#!/bin/bash set -e # quit script on error set -x # show each command as it is executed echo_header() { echo "==============================================================================" echo $1 } copy_apks_into_repo() { set +x for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned`; 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 } 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 } #------------------------------------------------------------------------------# # "main" if [ $# -ne 1 ]; then echo "Usage: $0 '/path/to/folder/with/apks'" exit 1 fi APKDIR=$1 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 --create-metadata grep -F '