env/
fdroidserver.egg-info/
pylint.parseable
+/.testfiles/
def test_sdk_exists(c):
if c['sdk_path'] == None:
# c['sdk_path'] is set to the value of ANDROID_HOME by default
- logging.critical("Neither ANDROID_HOME nor sdk_path is set, no Android SDK found!")
- logging.info('Set ANDROID_HOME to the path to your SDK, i.e.:')
+ logging.critical('No Android SDK found! ANDROID_HOME is not set and sdk_path is not in config.py!')
+ logging.info('You can use ANDROID_HOME to set the path to your SDK, i.e.:')
logging.info('\texport ANDROID_HOME=/opt/android-sdk')
return False
if not os.path.exists(c['sdk_path']):
if not os.path.isdir(c['sdk_path']):
logging.critical('Android SDK path "' + c['sdk_path'] + '" is not a directory!')
return False
+ if not os.path.isdir(os.path.join(c['sdk_path'], 'build-tools')):
+ logging.critical('Android SDK path "' + c['sdk_path'] + '" does not contain "build-tools/"!')
+ return False
return True
def write_password_file(pwtype, password=None):
help="Path to the keystore for the repo signing key")
parser.add_option("--repo-keyalias", default=None,
help="Alias of the repo signing key in the keystore")
+ parser.add_option("--android-home", default=None,
+ help="Path to the Android SDK (sometimes set in ANDROID_HOME)")
(options, args) = parser.parse_args()
- common.test_sdk_exists(common.get_default_config())
-
# find root install prefix
tmp = os.path.dirname(sys.argv[0])
if os.path.basename(tmp) == 'bin':
examplesdir = prefix + '/examples'
fdroiddir = os.getcwd()
+ test_config = common.get_default_config()
+
+ # track down where the Android SDK is, the default is to use the path set
+ # in ANDROID_HOME if that exists, otherwise None
+ if options.android_home != None:
+ test_config['sdk_path'] = options.android_home
+ elif not common.test_sdk_exists(test_config):
+ # if neither --android-home nor the default sdk_path exist, prompt the user
+ default_sdk_path = '/opt/android-sdk'
+ while True:
+ s = raw_input('Enter the path to the Android SDK (' + default_sdk_path + ') here:\n> ')
+ if re.match('^\s*$', s) != None:
+ test_config['sdk_path'] = default_sdk_path
+ else:
+ test_config['sdk_path'] = s
+ if common.test_sdk_exists(test_config):
+ break
+ if not common.test_sdk_exists(test_config):
+ sys.exit(3)
if not os.path.exists('config.py'):
# 'metadata' and 'tmp' are created in fdroid
shutil.copy(os.path.join(examplesdir, 'fdroid-icon.png'), fdroiddir)
shutil.copyfile(os.path.join(examplesdir, 'config.py'), 'config.py')
os.chmod('config.py', 0o0600)
+ write_to_config('sdk_path', test_config['sdk_path'])
else:
logging.warn('Looks like this is already an F-Droid repo, cowardly refusing to overwrite it...')
logging.info('Try running `fdroid init` in an empty directory.')
# now that we have a local config.py, read configuration...
config = common.read_config(options)
- # track down where the Android SDK is
- if os.path.isdir(config['sdk_path']):
- logging.info('Using "' + config['sdk_path'] + '" for the Android SDK')
- sdk_path = config['sdk_path']
- elif 'ANDROID_HOME' in os.environ.keys():
- sdk_path = os.environ['ANDROID_HOME']
- else:
- default_sdk_path = '/opt/android-sdk'
- while True:
- s = raw_input('Enter the path to the Android SDK (' + default_sdk_path + '): ')
- if re.match('^\s*$', s) != None:
- sdk_path = default_sdk_path
- else:
- sdk_path = s
- if os.path.isdir(os.path.join(sdk_path, 'build-tools')):
- break
- else:
- logging.info('"' + s + '" does not contain the Android SDK! Try again...')
- if os.path.isdir(sdk_path):
- write_to_config('sdk_path', sdk_path)
-
# try to find a working aapt, in all the recent possible paths
- build_tools = os.path.join(sdk_path, 'build-tools')
+ build_tools = os.path.join(config['sdk_path'], 'build-tools')
aaptdirs = []
aaptdirs.append(os.path.join(build_tools, config['build_tools']))
aaptdirs.append(build_tools)
logging.info('Built repo based in "' + fdroiddir + '"')
logging.info('with this config:')
- logging.info(' Android SDK:\t\t\t' + sdk_path)
+ logging.info(' Android SDK:\t\t\t' + config['sdk_path'])
logging.info(' Android SDK Build Tools:\t' + os.path.dirname(aapt))
logging.info(' Android NDK (optional):\t' + ndk_path)
logging.info(' Keystore for signing key:\t' + keystore)
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
#------------------------------------------------------------------------------#
-# setup a new repo from scratch
+echo "setup a new repo from scratch using ANDROID_HOME"
-REPOROOT=`mktemp --directory --tmpdir=$WORKSPACE`
+REPOROOT=`create_test_dir`
cd $REPOROOT
$fdroid init
copy_apks_into_repo $REPOROOT
#------------------------------------------------------------------------------#
-# setup a new repo from scratch and generate a keystore
+# 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 "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 "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
+test -e $KEYSTORE
+copy_apks_into_repo $REPOROOT
+$fdroid update -c
+$fdroid update
+test -e repo/index.xml
+test -e repo/index.jar
+export ANDROID_HOME=$STORED_ANDROID_HOME
+
+
+#------------------------------------------------------------------------------#
+echo "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
-REPOROOT=`mktemp --directory --tmpdir=$WORKSPACE`
+REPOROOT=`create_test_dir`
+cd $REPOROOT
+mkdir repo
+copy_apks_into_repo $REPOROOT
+$fdroid init
+$fdroid update -c
+$fdroid update
+
+
+#------------------------------------------------------------------------------#
+echo "setup a new repo from scratch and generate a keystore"
+
+REPOROOT=`create_test_dir`
KEYSTORE=$REPOROOT/keystore.jks
cd $REPOROOT
$fdroid init --keystore $KEYSTORE
#------------------------------------------------------------------------------#
-# setup a new repo from scratch with a HSM/smartcard
+echo "setup a new repo from scratch with a HSM/smartcard"
-REPOROOT=`mktemp --directory --tmpdir=$WORKSPACE`
+REPOROOT=`create_test_dir`
cd $REPOROOT
$fdroid init --keystore NONE
test -e opensc-fdroid.cfg
test ! -e NONE
+
+
+echo SUCCESS