
unset $(env | sed -n 's/=.*//p')
PATH=/bin:/usr/bin:/sbin/:/usr/sbin

declare -A FR_FLAGS
FR_FLAGS[EPEL5]=''

declare -A FR_SETTINGS 
FR_SETTINGS[resultdir]=""
FR_SETTINGS[verbose]="True"
FR_SETTINGS[no_report]=""
FR_SETTINGS[session_log]="/home/w0rm/.cache/fedora-review.log"
FR_SETTINGS[list_flags]=""
FR_SETTINGS[list_checks]=""
FR_SETTINGS[single]=""
FR_SETTINGS[rpm_spec]="True"
FR_SETTINGS[exclude]="CheckRpmlintInstalled,CheckApprovedLicense,CheckContainsLicenseText,CheckLicenseField,CheckLicenseUpstream,CheckReqPkgConfig,CheckBuildCompleted,CheckPackageInstalls,CheckNoNameConflict,CheckBuild,CheckBuildRequires"
FR_SETTINGS[configdir]=""
FR_SETTINGS[log_level]="10"
FR_SETTINGS[log]="<logging.RootLogger object at 0x7f97d5d64a90>"
FR_SETTINGS[init_done]="True"
FR_SETTINGS[cache]=""
FR_SETTINGS[mock_config]="fedora-rawhide-x86_64"
FR_SETTINGS[version]=""
FR_SETTINGS[uniqueext]=""
FR_SETTINGS[flags]=""
FR_SETTINGS[bz_url]="https://bugzilla.redhat.com"
FR_SETTINGS[mock_options]="--no-cleanup-after --no-clean"
FR_SETTINGS[other_bz]=""
FR_SETTINGS[repo]=""
FR_SETTINGS[use_colors]="True"
FR_SETTINGS[bug]=""
FR_SETTINGS[prebuilt]="True"
FR_SETTINGS[name]="hunspell-qu"
FR_SETTINGS[url]=""
FR_SETTINGS[checksum]="sha256"
FR_SETTINGS[nobuild]=""

export FR_REVIEWDIR='/data/temp/rhel-reviews/hunspell-qu-0.9-3.fc18/hunspell-qu'
export HOME=$FR_REVIEWDIR
cd $HOME

export FR_NAME='hunspell-qu'
export FR_VERSION='0.9'
export FR_RELEASE='3.fc18'
export FR_GROUP='Applications/Text'
export FR_LICENSE='AGPLv3'
export FR_URL='http://extensions.services.openoffice.org/project/KichwaSpellchecker'

export Source0="http://extensions.services.openoffice.org/e-files/2121/8/qu_EC-0.9.oxt"



export FR_PREP='cd '\''/data/temp/rhel-reviews/hunspell-qu-0.9-3.fc18/hunspell-qu/BUILD'\''
rm -rf '\''hunspell-qu-0.9'\''
/usr/bin/mkdir -p hunspell-qu-0.9
cd '\''hunspell-qu-0.9'\''
/usr/bin/tar -xf /data/temp/rhel-reviews/hunspell-qu-0.9-3.fc18/hunspell-qu/qu_EC-0.9.oxt
/usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .'
export FR_BUILD=
export FR_INSTALL='rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT//usr/share/myspell
cp -p qu_EC.aff qu_EC.dic $RPM_BUILD_ROOT//usr/share/myspell'

declare -A FR_FILES
FR_FILES[hunspell-qu]='%defattr(-,root,root,-)
%doc CURRENTVERSION.txt LICENSE.txt README.txt REVISION.txt
/usr/share/myspell/*'

declare -A FR_DESCRIPTION


export FR_FILES FR_DESCRIPTION

export FR_PASS=80
export FR_FAIL=81
export FR_PENDING=82
export FR_NOT_APPLICABLE=83


function get_used_rpms()
# returns (stdout) list of used rpms if found, else returns 1
{
    cd $FR_REVIEWDIR
    if test  "${FR_SETTINGS[prebuilt]}" = True
    then
        files=( $(ls ../*.rpm 2>/dev/null | grep -v .src.rpm) )                || files=( '@@' )
    else
        files=( $(ls results/*.rpm 2>/dev/null | grep -v .src.rpm) )                || files=( '@@' )
    fi
    test -e ${files[0]} || return 1
    echo "${files[@]}"
    cd $OLDPWD
}

function unpack_rpms()
# Unpack all non-src rpms in results into rpms-unpacked, one dir per rpm.
{
    [ -d rpms-unpacked ] && return 0
    rpms=( $( get_used_rpms ) ) || return 1
    mkdir rpms-unpacked
    cd rpms-unpacked
    retval=0
    for rpm_path in ${rpms[@]};  do
        rpm=$( basename $rpm_path)
        mkdir $rpm
        cd $rpm
        rpm2cpio ../../$rpm_path | cpio -id &>/dev/null
        cd ..
    done
    cd ..
}

function unpack_sources()
# Unpack sources in upstream into upstream-unpacked
# Ignores (reuses) already unpacked items.
{
    sources=( $(cd upstream; ls) ) || sources=(  )
    if [[ ${#sources[@]} -eq 0 || ! -e "upstream/${sources[0]}" ]]; then
       return $FR_NOT_APPLICABLE
    fi
    for source in "${sources[@]}"; do
        mkdir upstream-unpacked/$source 2>/dev/null || continue
        rpmdev-extract -qfC  upstream-unpacked/$source upstream/$source ||            cp upstream/$source upstream-unpacked/$source
    done
}

function attach()
# Usage: attach <sorting hint> <header>
# Reads attachment from stdin
{
    startdir=$(pwd)
    cd $FR_REVIEWDIR
    for (( i = 0; i < 10; i++ )); do
        test -e $FR_REVIEWDIR/.attachments/*$i || break
    done
    if [ $i -eq 10 ]; then
        echo "More than 10 attachments! Giving up" >&2
        exit 1
    fi
    sort_hint=$1
    shift
    title=${*//\/ }
    file="$sort_hint;${title/;/:};$i"
    cat > .attachments/"$file"
    cd $startdir
}

