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
echo "This script will erase everything under \$PREFIX. All files under that directory will be lost, that includes packages, configuration files, databases, etc."
echo
2020-06-07 19:40:53 +02:00
echo "Termux home directory as well as data on 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
echo "Leaving intact the contents of \$PREFIX."
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"
# In case if copying am.apk failed.
if [ ! -e "@TERMUX_CACHE_DIR@/termux-am/am.apk" ]; then
HAS_TERMUX_AM=false
fi
fi
fi
echo "Erasing '@TERMUX_PREFIX@'..."
/system/bin/rm -rf "@TERMUX_PREFIX@"
echo "Done. You need to close Termux application now."
if ! $HAS_TERMUX_AM && [ -x "/system/bin/killall" ]; then
echo "Terminating all sessions..."
/system/bin/killall -9 "$SHELL"
else
export CLASSPATH="@TERMUX_CACHE_DIR@/termux-am/am.apk"
/system/bin/app_process / com.example.termuxam.Am stopservice com.termux/.app.TermuxService
fi
fi