2020-06-07 19:05:11 +02:00
#!/bin/bash
unset LD_PRELOAD LD_LIBRARY_PATH
echo
echo "You are going to reset your Termux installation."
echo
2020-06-07 19:55:26 +02:00
echo "This script will erase everything under \$PREFIX. All files in that directory will be lost, that includes packages, configuration files, databases, etc."
2020-06-07 19:05:11 +02:00
echo
2020-06-07 19:55:26 +02:00
echo "Termux home directory as well as data in your shared or external storage will not be removed and left as-is."
2020-06-07 19:05:11 +02:00
echo
read -re -p "Do you want to continue ? (y/n) " CHOICE
if ! [[ $CHOICE =~ (Y|y) ]]; then
2020-06-07 19:55:26 +02:00
echo "Leaving \$PREFIX intact."
2020-06-07 19:05:11 +02:00
exit 1
else
HAS_TERMUX_AM=false
if [ -f "@TERMUX_PREFIX@/libexec/termux-am/am.apk" ]; 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"
2020-06-07 19:55:26 +02:00
# In case copying am.apk failed.
2020-06-07 19:05:11 +02:00
if [ ! -e "@TERMUX_CACHE_DIR@/termux-am/am.apk" ]; then
HAS_TERMUX_AM=false
fi
fi
fi
echo "Erasing '@TERMUX_PREFIX@'..."
2020-07-21 15:01:45 +02:00
/system/bin/chmod -R 700 "@TERMUX_PREFIX@" >/dev/null 2>&1
2020-06-07 19:05:11 +02:00
/system/bin/rm -rf "@TERMUX_PREFIX@"
echo "Done. You need to close Termux application now."
2020-06-07 20:01:12 +02:00
if ! $HAS_TERMUX_AM; then
2020-06-07 19:05:11 +02:00
echo "Terminating all sessions..."
/system/bin/killall -9 "$SHELL"
else
export CLASSPATH="@TERMUX_CACHE_DIR@/termux-am/am.apk"
2021-02-10 14:28:29 +01:00
/system/bin/app_process / com.termux.termuxam.Am stopservice com.termux/.app.TermuxService
2020-06-07 19:05:11 +02:00
fi
fi