summaryrefslogtreecommitdiffstats
path: root/.vars.rc.do
blob: f9ccc805f58e9324834749a87aedaa82136bb496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
set -e

unset ANDROID_SDK ANDROID_VER BUILD_TOOLS BUILD_TOOLS_VER JAVAC KEYSTORE KEYSTORE_ARGS KEYSTORE_PASS KOTLIN KOTLINC PLATFORM verbose

ANDROID_VER=android-33-ext5
BUILD_TOOLS_VER=33.0.2
APKSIGNER_SIGN_ARGS=()

if [ -e config.rc ]; then
	redo-ifchange config.rc
	. ./config.rc
else
	redo-ifcreate config.rc
fi

if [[ ! ( $BUILD_TOOLS || $PLATFORM ) && ! $ANDROID_SDK ]]; then
	cat <<-"EOF" >&2
	$BUILD_TOOLS or $PLATFORM unset without setting $ANDROID_SDK.
	Either set both $BUILD_TOOLS and $PLATFORM or set $ANDROID_SDK.
	EOF
	exit 1
fi

BUILD_TOOLS=${BUILD_TOOLS-$ANDROID_SDK/build-tools/$BUILD_TOOLS_VER}
PLATFORM=${PLATFORM-$ANDROID_SDK/platforms/$ANDROID_VER}
KOTLIN=${KOTLIN-/usr/share/kotlin}

KEYSTORE=${KEYSTORE-$HOME/.android/debug.keystore}
KEYSTORE_PASS=${KEYSTORE_PASS-pass:android}

check() {
	what=$1
	shift
	for p do
		if command -v "$p" >/dev/null 2>&1; then
			command -v "$p"
			return
		fi
	done
	echo "$what not set or found" >&2
	return 1
}

JAVAC=$(check '$JAVAC or javac' "$JAVAC" javac) || exit
KOTLINC=$(check '$KOTLINC or kotlinc' "$KOTLINC" kotlinc) || exit

{
	printf "# generated by %s\n" "$0"
	declare -p APKSIGNER_SIGN_ARGS BUILD_TOOLS JAVAC KEYSTORE KEYSTORE_PASS KOTLIN KOTLINC PLATFORM
} >"$3"

if [[ $verbose ]]; then
	echo "# Configuration regenerated:" >&2
	cat "$3" >&2
fi
# vim:ft=bash