termux-tools: add script for resetting Termux installation (#5377)

This commit is contained in:
Leonid Pliushch 2020-06-07 20:05:11 +03:00 committed by GitHub
parent 5551bfb8b4
commit b9a86e7836
2 changed files with 56 additions and 6 deletions

View File

@ -1,8 +1,7 @@
TERMUX_PKG_HOMEPAGE=https://termux.com/
TERMUX_PKG_DESCRIPTION="Basic system tools for Termux"
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_VERSION=0.80
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION=0.81
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_ESSENTIAL=true
@ -34,11 +33,13 @@ termux_step_make_install() {
done
for script in chsh dalvikvm login pkg su termux-fix-shebang termux-info \
termux-open termux-open-url termux-reload-settings termux-setup-storage \
termux-wake-lock termux-wake-unlock termux-change-repo; do
termux-open termux-open-url termux-reload-settings termux-reset \
termux-setup-storage termux-wake-lock termux-wake-unlock termux-change-repo; do
install -Dm700 $TERMUX_PKG_BUILDER_DIR/$script $TERMUX_PREFIX/bin/$script
perl -p -i -e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $TERMUX_PREFIX/bin/$script
perl -p -i -e "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" $TERMUX_PREFIX/bin/$script
sed -i -e "s|@TERMUX_PREFIX@|${TERMUX_PREFIX}|g" \
-e "s|@TERMUX_HOME@|${TERMUX_ANDROID_HOME}|g" \
-e "s|@TERMUX_CACHE_DIR@|$(realpath ${TERMUX_PREFIX}/../../cache)|g" \
$TERMUX_PREFIX/bin/$script
done
install -Dm600 $TERMUX_PKG_BUILDER_DIR/motd $TERMUX_PREFIX/etc/motd

View File

@ -0,0 +1,49 @@
#!/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
echo "Termux home directory as well as data on your shared or external storage will not be removed and leaved as-is."
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