mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 14:30:30 +03:00 
			
		
		
		
	Yes, this includes a binary file, but it is only for the tests, and it is free software since I wrote it. The source is here: https://github.com/eighthave/urzip
		
			
				
	
	
		
			205 lines
		
	
	
	
		
			5.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			205 lines
		
	
	
	
		
			5.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/bin/bash
 | 
						|
 | 
						|
set -e
 | 
						|
set -x
 | 
						|
 | 
						|
echo_header() {
 | 
						|
    echo "=============================================================================="
 | 
						|
    echo $1
 | 
						|
}
 | 
						|
 | 
						|
copy_apks_into_repo() {
 | 
						|
    for f in `ls -1 ../../*/bin/*.apk`; do
 | 
						|
        name=$(basename $(dirname `dirname $f`))
 | 
						|
        echo "name $name"
 | 
						|
        apk=`aapt d badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
 | 
						|
        echo "apk $apk"
 | 
						|
        cp -f $f $1/repo/$apk
 | 
						|
    done
 | 
						|
}
 | 
						|
 | 
						|
create_fake_android_home() {
 | 
						|
    mkdir $1/build-tools
 | 
						|
    mkdir $1/build-tools/19.0.1
 | 
						|
    touch $1/build-tools/19.0.1/aapt
 | 
						|
}
 | 
						|
 | 
						|
create_test_dir() {
 | 
						|
    test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
 | 
						|
    mktemp --directory --tmpdir=$WORKSPACE/.testfiles
 | 
						|
}
 | 
						|
 | 
						|
create_test_file() {
 | 
						|
    test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
 | 
						|
    mktemp --tmpdir=$WORKSPACE/.testfiles
 | 
						|
}
 | 
						|
 | 
						|
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
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "setup a new repo from scratch using ANDROID_HOME"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init
 | 
						|
copy_apks_into_repo $REPOROOT
 | 
						|
$fdroid update --createmeta
 | 
						|
grep -F '<application id=' repo/index.xml
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
# check that --android-home fails when dir does not exist or is not a dir
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
cd $REPOROOT
 | 
						|
set +e
 | 
						|
$fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
 | 
						|
if [ $? -eq 0 ]; then
 | 
						|
    echo "This should have failed because /opt/fakeandroidhome does not exist!"
 | 
						|
    exit 1
 | 
						|
else
 | 
						|
    echo "testing android-home path checker passed"
 | 
						|
fi
 | 
						|
TESTFILE=`create_test_file`
 | 
						|
$fdroid init --keystore $KEYSTORE --android-home $TESTFILE
 | 
						|
if [ $? -eq 0 ]; then
 | 
						|
    echo "This should have failed because $TESTFILE is a file not a dir!"
 | 
						|
    exit 1
 | 
						|
else
 | 
						|
    echo "testing android-home not-dir checker passed"
 | 
						|
fi
 | 
						|
set -e
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "check that fake android home passes `fdroid init`"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
FAKE_ANDROID_HOME=`create_test_dir`
 | 
						|
create_fake_android_home $FAKE_ANDROID_HOME
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "check that 'fdroid init' fails when build-tools cannot be found"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
FAKE_ANDROID_HOME=`create_test_dir`
 | 
						|
create_fake_android_home $FAKE_ANDROID_HOME
 | 
						|
rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
cd $REPOROOT
 | 
						|
set +e
 | 
						|
$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
 | 
						|
[ $? -eq 0 ] && exit 1
 | 
						|
set -e
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "check that --android-home overrides ANDROID_HOME"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
FAKE_ANDROID_HOME=`create_test_dir`
 | 
						|
create_fake_android_home $FAKE_ANDROID_HOME
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
 | 
						|
set +e
 | 
						|
grep $FAKE_ANDROID_HOME $REPOROOT/config.py
 | 
						|
if [ $? -ne 0 ]; then
 | 
						|
    echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
set -e
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
FAKE_ANDROID_HOME=`create_test_dir`
 | 
						|
create_fake_android_home $FAKE_ANDROID_HOME
 | 
						|
STORED_ANDROID_HOME=$ANDROID_HOME
 | 
						|
unset ANDROID_HOME
 | 
						|
echo "ANDROID_HOME: $ANDROID_HOME"
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME --no-prompt
 | 
						|
test -e $KEYSTORE
 | 
						|
copy_apks_into_repo $REPOROOT
 | 
						|
$fdroid update --createmeta
 | 
						|
grep -F '<application id=' repo/index.xml
 | 
						|
test -e repo/index.xml
 | 
						|
test -e repo/index.jar
 | 
						|
export ANDROID_HOME=$STORED_ANDROID_HOME
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
cd $REPOROOT
 | 
						|
mkdir repo
 | 
						|
copy_apks_into_repo $REPOROOT
 | 
						|
$fdroid init
 | 
						|
$fdroid update --createmeta
 | 
						|
grep -F '<application id=' repo/index.xml
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "setup a new repo from scratch and generate a keystore"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init --keystore $KEYSTORE
 | 
						|
test -e $KEYSTORE
 | 
						|
copy_apks_into_repo $REPOROOT
 | 
						|
$fdroid update --createmeta
 | 
						|
test -e repo/index.xml
 | 
						|
test -e repo/index.jar
 | 
						|
grep -F '<application id=' repo/index.xml
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
KEYSTORE=$REPOROOT/keystore.jks
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init --keystore $KEYSTORE
 | 
						|
test -e $KEYSTORE
 | 
						|
copy_apks_into_repo $REPOROOT
 | 
						|
$fdroid update --createmeta
 | 
						|
test -e repo/index.xml
 | 
						|
test -e repo/index.jar
 | 
						|
grep -F '<application id=' repo/index.xml
 | 
						|
cp $WORKSPACE/tests/urzip.apk $REPOROOT/
 | 
						|
$fdroid update --createmeta
 | 
						|
test -e repo/index.xml
 | 
						|
test -e repo/index.jar
 | 
						|
grep -F '<application id=' repo/index.xml
 | 
						|
 | 
						|
 | 
						|
#------------------------------------------------------------------------------#
 | 
						|
echo_header "setup a new repo from scratch with a HSM/smartcard"
 | 
						|
 | 
						|
REPOROOT=`create_test_dir`
 | 
						|
cd $REPOROOT
 | 
						|
$fdroid init --keystore NONE
 | 
						|
test -e opensc-fdroid.cfg
 | 
						|
test ! -e NONE
 | 
						|
 | 
						|
 | 
						|
echo SUCCESS
 |