Skip to content

Commit

Permalink
scripts(termux-reset): make am.apk read only before running and pas…
Browse files Browse the repository at this point in the history
…s the `-Xnoimage-dex2oat` flag and use variables for `am.apk` path

- termux/TermuxAm@521ccb3
- termux/TermuxAm@598a9c0
  • Loading branch information
agnostic-apollo committed Aug 13, 2024
1 parent 001d6bc commit 5db4ffc
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scripts/termux-reset.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

unset LD_PRELOAD LD_LIBRARY_PATH

AM_APK_PATH="@TERMUX_PREFIX@/libexec/termux-am/am.apk"
AM_APK_TMP_PATH="@TERMUX_CACHE_DIR@/termux-am/am.apk"

echo
echo "You are going to reset your Termux installation."
echo
Expand All @@ -18,18 +21,18 @@ if ! [[ $CHOICE =~ (Y|y) ]]; then
else
HAS_TERMUX_AM=false

if [ -f "@TERMUX_PREFIX@/libexec/termux-am/am.apk" ]; then
if [ -f "$AM_APK_PATH" ]; then
HAS_TERMUX_AM=true

echo "Preserving package 'termux-am' for later use..."

if [ -d "@TERMUX_CACHE_DIR@" ]; then
/system/bin/rm -rf "@TERMUX_CACHE_DIR@/termux-am"
/system/bin/mkdir -p "@TERMUX_CACHE_DIR@/termux-am"
/system/bin/cp "@TERMUX_PREFIX@/libexec/termux-am/am.apk" "@TERMUX_CACHE_DIR@/termux-am/am.apk"
/system/bin/cp "$AM_APK_PATH" "$AM_APK_TMP_PATH"

# In case copying am.apk failed.
if [ ! -e "@TERMUX_CACHE_DIR@/termux-am/am.apk" ]; then
if [ ! -e "$AM_APK_TMP_PATH" ]; then
HAS_TERMUX_AM=false
fi
fi
Expand All @@ -44,7 +47,12 @@ else
echo "Terminating all sessions..."
/system/bin/killall -9 "$SHELL"
else
export CLASSPATH="@TERMUX_CACHE_DIR@/termux-am/am.apk"
/system/bin/app_process / "com.termux.termuxam.Am" stopservice "@TERMUX_APP_PACKAGE@/@TERMUX_APP_PACKAGE@.app.TermuxService"
# - https://github.com/termux/TermuxAm/commit/598a9c06
if [ -w "$AM_APK_TMP_PATH" ]; then
chmod 0400 "$AM_APK_TMP_PATH"
fi

export CLASSPATH="$AM_APK_TMP_PATH"
/system/bin/app_process -Xnoimage-dex2oat / "com.termux.termuxam.Am" stopservice "@TERMUX_APP_PACKAGE@/@TERMUX_APP_PACKAGE@.app.TermuxService"
fi
fi

0 comments on commit 5db4ffc

Please sign in to comment.