#!/bin/bash set -e # quit script on error echo_header() { { echo -e "==============================================================================\n$1"; } 2>/dev/null } copy_apks_into_repo() { set +x for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert`; do name=$(basename $(dirname `dirname $f`)) apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"` test $f -nt repo/$apk && rm -f repo/$apk # delete existing if $f is newer if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then echo "$f --> repo/$apk" ln $f $1/repo/$apk || \ rsync -axv $f $1/repo/$apk # rsync if hard link is not possible fi done set -x } # keep this as an old version to test the automatic parsing of build-tools # verion numbers in `fdroid init` create_fake_android_home() { mkdir $1/tools mkdir $1/platform-tools mkdir $1/build-tools mkdir $1/build-tools/19.0.2 touch $1/build-tools/19.0.2/aapt } create_test_dir() { test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles mktemp -d $WORKSPACE/.testfiles/run-tests.XXXX } create_test_file() { test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles TMPDIR=$WORKSPACE/.testfiles mktemp } #------------------------------------------------------------------------------# # "main" if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then set +x echo "Usage: $0 '/path/to/folder/with/apks'" exit 1 fi if [ -z "$ANDROID_HOME" ]; then echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: " echo " export ANDROID_HOME=/opt/android-sdk" exit 1 fi if [ -d tests ]; then cd tests fi if [ -z "$1" ]; then APKDIR=`pwd` else APKDIR=$1 fi if [ -z $WORKSPACE ]; then WORKSPACE=`dirname $(pwd)` echo "Setting Workspace to $WORKSPACE" fi # allow the location of the script to be overridden if [ -z $fdroid ]; then fdroid="$WORKSPACE/fdroid" fi # allow the location of aapt to be overridden if [ -z $aapt ]; then aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1` fi # allow the location of python to be overridden if [ -z $python ]; then python=python3 fi set -x # show each command as it is executed #------------------------------------------------------------------------------# echo_header "run commit hooks" cd $WORKSPACE ./hooks/pre-commit #------------------------------------------------------------------------------# echo_header "test python getsig replacement" cd $WORKSPACE/tests/getsig ./make.sh cd $WORKSPACE/tests for testcase in $WORKSPACE/tests/*.TestCase; do $testcase done #------------------------------------------------------------------------------# echo_header "print fdroid version" $fdroid --version #------------------------------------------------------------------------------# echo_header "build the TeX manual" cd $WORKSPACE/docs # this is only ever generated officially on GNU/Linux if [ `uname -s` == "Linux" ]; then ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual" fi #------------------------------------------------------------------------------# echo_header "test UTF-8 metadata" REPOROOT=`create_test_dir` cd $REPOROOT $fdroid init sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py echo "mirrors = {'https://foo.bar/fdroid', 'http://secret.onion/fdroid'}" >> config.py mkdir metadata cp $WORKSPACE/tests/urzip.apk repo/ cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.txt metadata/ $fdroid readmeta $fdroid update #------------------------------------------------------------------------------# echo_header 'run `fdroid build` in fresh git checkout from import.TestCase' cd $WORKSPACE/tests/tmp/importer if [ -d $ANDROID_HOME/platforms/android-23 ]; then echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py echo "force_build_tools = True" >> config.py $fdroid build --verbose org.fdroid.ci.test.app:300 else echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!' fi #------------------------------------------------------------------------------# echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign" REPOROOT=`create_test_dir` GNUPGHOME=$REPOROOT/gnupghome cd $REPOROOT $fdroid init cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $REPOROOT/ cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME chmod 0700 $GNUPGHOME echo "accepted_formats = ['json', 'txt', 'xml', 'yml']" >> config.py echo "install_list = 'org.adaway'" >> config.py echo "uninstall_list = {'com.android.vending', 'com.facebook.orca',}" >> config.py echo "gpghome = '$GNUPGHOME'" >> config.py echo "gpgkey = 'CE71F7FB'" >> config.py $fdroid update --verbose test -e repo/index.xml test -e repo/index.jar grep -F '> metadata/fake.txt echo "Summary:Yup still fake" >> metadata/fake.txt echo "Categories:Internet" >> metadata/fake.txt echo "Description:" >> metadata/fake.txt echo "this is fake" >> metadata/fake.txt echo "." >> metadata/fake.txt # fake that no JDKs are available echo 'java_paths = {}' > config.py LOCAL_COPY_DIR=`create_test_dir`/fdroid mkdir -p $LOCAL_COPY_DIR/repo echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py $fdroid checkupdates $fdroid gpgsign $fdroid lint $fdroid readmeta $fdroid rewritemeta fake $fdroid server update $fdroid scanner # run these to get their output, but the are not setup, so don't fail $fdroid build || true $fdroid import || true $fdroid install || true #------------------------------------------------------------------------------# echo_header "create a source tarball and use that to build a repo" cd $WORKSPACE $python setup.py sdist REPOROOT=`create_test_dir` cd $REPOROOT tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1` cd $REPOROOT ./fdroidserver-*/fdroid init copy_apks_into_repo $REPOROOT ./fdroidserver-*/fdroid update --create-metadata --verbose #------------------------------------------------------------------------------# echo_header "test config checks of local_copy_dir" REPOROOT=`create_test_dir` cd $REPOROOT $fdroid init $fdroid update --create-metadata --verbose $fdroid readmeta $fdroid server update --local-copy-dir=/tmp/fdroid # now test the errors work set +e $fdroid server update --local-copy-dir=thisisnotanabsolutepath if [ $? -eq 0 ]; then echo "This should have failed because thisisnotanabsolutepath is not an absolute path!" exit 1 else echo "testing absolute path checker passed" fi $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf if [ $? -eq 0 ]; then echo "This should have failed because the path does not end with 'fdroid'!" exit 1 else echo "testing dirname exists checker passed" fi $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid if [ $? -eq 0 ]; then echo "This should have failed because the dirname path does not exist!" exit 1 else echo "testing dirname exists checker passed" fi set -e #------------------------------------------------------------------------------# echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync" REPOROOT=`create_test_dir` cd $REPOROOT $fdroid init copy_apks_into_repo $REPOROOT $fdroid update --create-metadata --verbose $fdroid readmeta grep -F '> config.py echo 'repo_keyalias = "foo"' >> config.py echo 'keystorepass = "foo"' >> config.py echo 'keypass = "foo"' >> config.py set +e $fdroid update --create-metadata --verbose if [ $? -eq 0 ]; then echo "This should have failed because this repo has a bad/fake keystore!" exit 1 else echo '`fdroid update` prompted to add keystore' fi set -e #------------------------------------------------------------------------------# echo_header "setup a new repo with keystore with APK, update, then without key" REPOROOT=`create_test_dir` KEYSTORE=$REPOROOT/keystore.jks cd $REPOROOT $fdroid init --keystore $KEYSTORE test -e $KEYSTORE cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/ $fdroid update --create-metadata --verbose $fdroid readmeta test -e repo/index.xml test -e repo/index.jar grep -F '