Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion module/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ install_apk() {
src="$1"
[ -s "$src" ] || return 1
stage="/data/local/tmp/betterflow-install-$$.apk"
error_log="$DATA_DIR/install-error.log"
rm -f "$stage"
cp -f "$src" "$stage" || return 1
chmod 0644 "$stage" 2>/dev/null || true
if pm install -r "$stage" >/dev/null 2>&1; then
restorecon "$stage" >/dev/null 2>&1 || true
output=$(pm install --user 0 -r "$stage" 2>&1)
result=$?
if [ "$result" -eq 0 ]; then
rm -f "$stage"
rm -f "$error_log"
return 0
fi
printf '%s\n' "$output" > "$error_log"
printf '%s\n' "$output" >&2
rm -f "$stage"
return 1
}
Expand Down
16 changes: 14 additions & 2 deletions module/scripts/hot-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ bb unzip -oq "$ZIP" -d "$TMP/unpack" || { say "betterFlow: unzip failed"; exit 1
APK="$TMP/unpack/app/betterflow.apk"
[ -s "$APK" ] || { say "betterFlow: release has no APK"; exit 1; }

# Refresh the updater itself before installing the APK. This deliberately
# happens after SHA-256 verification and lets a corrected installer recover on
# the next Action run even if this APK installation fails.
if [ -d "$TMP/unpack/module-runtime/scripts" ]; then
for script in common.sh hot-update.sh; do
[ -s "$TMP/unpack/module-runtime/scripts/$script" ] || continue
cp -f "$TMP/unpack/module-runtime/scripts/$script" "$MODDIR/scripts/$script.new" || continue
chmod 0755 "$MODDIR/scripts/$script.new"
mv -f "$MODDIR/scripts/$script.new" "$MODDIR/scripts/$script"
done
fi

OLD_APK="$DATA_DIR/backups/betterflow-prev.apk"
if [ -s "$DATA_DIR/current.apk" ]; then cp -f "$DATA_DIR/current.apk" "$OLD_APK"; fi
cp -f "$APK" "$DATA_DIR/current.apk.new"
Expand All @@ -63,9 +75,9 @@ if ! install_apk "$DATA_DIR/current.apk.new"; then
fi
mv -f "$DATA_DIR/current.apk.new" "$DATA_DIR/current.apk"

# Script payloads are intentionally replaced only after the APK has installed.
# Refresh the remaining runtime scripts after the APK has installed.
if [ -d "$TMP/unpack/module-runtime/scripts" ]; then
for script in common.sh watchdog.sh status.sh control.sh; do
for script in watchdog.sh status.sh control.sh; do
[ -s "$TMP/unpack/module-runtime/scripts/$script" ] || continue
cp -f "$TMP/unpack/module-runtime/scripts/$script" "$MODDIR/scripts/$script.new" || continue
chmod 0755 "$MODDIR/scripts/$script.new"
Expand Down
2 changes: 1 addition & 1 deletion tools/package-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cp -a webui/dist/. "$OUT/module/webroot/"
cp "$APK" "$OUT/module/payload/betterflow.apk"
cp "$APK" "$OUT/runtime/app/betterflow.apk"

for script in common.sh watchdog.sh status.sh control.sh; do
for script in common.sh hot-update.sh watchdog.sh status.sh control.sh; do
cp "module/scripts/$script" "$OUT/runtime/module-runtime/scripts/$script"
done
cp -a webui/dist/. "$OUT/runtime/module-runtime/webroot/"
Expand Down
Loading