termux-tools: ask user for confirmation before recreating ~/storage directory

Notify user about potential data loss if files were placed to
the root of ~/storage directory during execution of termux-setup-storage.
This commit is contained in:
Leonid Pliushch 2020-06-01 20:23:30 +03:00
parent 6c5c0b6c92
commit ad8fa679cb
2 changed files with 14 additions and 2 deletions

View File

@ -1,7 +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.79
TERMUX_PKG_VERSION=0.80
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_ESSENTIAL=true
@ -37,6 +37,7 @@ termux_step_make_install() {
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
done
install -Dm600 $TERMUX_PKG_BUILDER_DIR/motd $TERMUX_PREFIX/etc/motd

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
if [ "$#" != "0" ]; then
echo 'usage: termux-setup-storage'
@ -7,6 +7,17 @@ if [ "$#" != "0" ]; then
exit
fi
if [ -d "@TERMUX_HOME@/storage" ]; then
echo
echo "Directory '~/storage' is going to be wiped. No storage contents will be touched."
read -re -p "Do you want to continue ? (y/n) " CHOICE
if ! [[ "${CHOICE}" =~ (Y|y) ]]; then
echo "Leaving intact the contents of '~/storage' directory."
exit 1
fi
fi
am broadcast --user 0 \
--es com.termux.app.reload_style storage \
-a com.termux.app.reload_style com.termux > /dev/null