Skip to content

Commit 62a86c0

Browse files
committed
fix(fdroid): allow native library patching without resigning
1 parent 0be0ce7 commit 62a86c0

1 file changed

Lines changed: 49 additions & 24 deletions

File tree

scripts/release/verify-fdroid-native-libs.sh

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
66
APK_DIR="${APK_DIR:-$REPO_ROOT/build/app/outputs/flutter-apk}"
77
APP_NAME="${APP_NAME:-ServerBox}"
88
KEY_PROPERTIES="${KEY_PROPERTIES:-$REPO_ROOT/android/key.properties}"
9+
RESIGN_APKS="${RESIGN_APKS:-true}"
910

1011
require_cmd() {
1112
local name="$1"
@@ -187,13 +188,26 @@ READELF="${READELF:-}"
187188
APKSIGNER="${APKSIGNER:-}"
188189
ZIPALIGN="${ZIPALIGN:-}"
189190

191+
case "$RESIGN_APKS" in
192+
true | 1 | yes)
193+
RESIGN_APKS=true
194+
;;
195+
false | 0 | no)
196+
RESIGN_APKS=false
197+
;;
198+
*)
199+
echo "RESIGN_APKS must be true or false, got: $RESIGN_APKS" >&2
200+
exit 1
201+
;;
202+
esac
203+
190204
if [[ -z "$OBJCOPY" ]]; then
191205
OBJCOPY="$(find_llvm_objcopy || true)"
192206
fi
193207
if [[ -z "$READELF" ]]; then
194208
READELF="$(find_readelf || true)"
195209
fi
196-
if [[ -z "$APKSIGNER" ]]; then
210+
if [[ "$RESIGN_APKS" == true && -z "$APKSIGNER" ]]; then
197211
APKSIGNER="$(find_latest_android_tool apksigner || true)"
198212
fi
199213
if [[ -z "$ZIPALIGN" ]]; then
@@ -210,7 +224,7 @@ if [[ -z "$READELF" || ! -x "$READELF" ]]; then
210224
exit 1
211225
fi
212226

213-
if [[ -z "$APKSIGNER" || ! -x "$APKSIGNER" ]]; then
227+
if [[ "$RESIGN_APKS" == true && ( -z "$APKSIGNER" || ! -x "$APKSIGNER" ) ]]; then
214228
echo 'Android build-tools apksigner is required to re-sign patched APKs' >&2
215229
exit 1
216230
fi
@@ -220,28 +234,35 @@ if [[ -z "$ZIPALIGN" || ! -x "$ZIPALIGN" ]]; then
220234
exit 1
221235
fi
222236

223-
if [[ ! -f "$KEY_PROPERTIES" ]]; then
237+
if [[ "$RESIGN_APKS" == true && ! -f "$KEY_PROPERTIES" ]]; then
224238
echo "key.properties not found: $KEY_PROPERTIES" >&2
225239
exit 1
226240
fi
227241

228-
store_file="$(property_value storeFile)"
229-
store_password="$(property_value storePassword)"
230-
key_alias="$(property_value keyAlias)"
231-
key_password="$(property_value keyPassword)"
242+
store_file=''
243+
store_password=''
244+
key_alias=''
245+
key_password=''
232246

233-
if [[ -z "$store_file" || -z "$store_password" || -z "$key_alias" || -z "$key_password" ]]; then
234-
echo "storeFile, storePassword, keyAlias, and keyPassword are required in $KEY_PROPERTIES" >&2
235-
exit 1
236-
fi
247+
if [[ "$RESIGN_APKS" == true ]]; then
248+
store_file="$(property_value storeFile)"
249+
store_password="$(property_value storePassword)"
250+
key_alias="$(property_value keyAlias)"
251+
key_password="$(property_value keyPassword)"
237252

238-
if [[ "$store_file" != /* ]]; then
239-
store_file="$REPO_ROOT/android/app/$store_file"
240-
fi
253+
if [[ -z "$store_file" || -z "$store_password" || -z "$key_alias" || -z "$key_password" ]]; then
254+
echo "storeFile, storePassword, keyAlias, and keyPassword are required in $KEY_PROPERTIES" >&2
255+
exit 1
256+
fi
241257

242-
if [[ ! -f "$store_file" ]]; then
243-
echo "signing store file not found: $store_file" >&2
244-
exit 1
258+
if [[ "$store_file" != /* ]]; then
259+
store_file="$REPO_ROOT/android/app/$store_file"
260+
fi
261+
262+
if [[ ! -f "$store_file" ]]; then
263+
echo "signing store file not found: $store_file" >&2
264+
exit 1
265+
fi
245266
fi
246267

247268
shopt -s nullglob
@@ -307,12 +328,14 @@ for apk in "${apks[@]}"; do
307328
"$ZIPALIGN" -f -p 4 "$apk" "$aligned_apk"
308329
mv "$aligned_apk" "$apk"
309330

310-
"$APKSIGNER" sign \
311-
--ks "$store_file" \
312-
--ks-key-alias "$key_alias" \
313-
--ks-pass "pass:$store_password" \
314-
--key-pass "pass:$key_password" \
315-
"$apk"
331+
if [[ "$RESIGN_APKS" == true ]]; then
332+
"$APKSIGNER" sign \
333+
--ks "$store_file" \
334+
--ks-key-alias "$key_alias" \
335+
--ks-pass "pass:$store_password" \
336+
--key-pass "pass:$key_password" \
337+
"$apk"
338+
fi
316339
done
317340

318341
for apk in "${apks[@]}"; do
@@ -329,7 +352,9 @@ for apk in "${apks[@]}"; do
329352
fi
330353
done < <(find "$verify_dir" -type f -name '*.so' | sort)
331354

332-
"$APKSIGNER" verify "$apk"
355+
if [[ "$RESIGN_APKS" == true ]]; then
356+
"$APKSIGNER" verify "$apk"
357+
fi
333358
done
334359

335360
echo 'F-Droid native library verification passed.'

0 commit comments

Comments
 (0)