From ad8fa679cb7ac7bddc5b9f3f488a79606427c26d Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Mon, 1 Jun 2020 20:23:30 +0300 Subject: [PATCH] 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. --- packages/termux-tools/build.sh | 3 ++- packages/termux-tools/termux-setup-storage | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/termux-tools/build.sh b/packages/termux-tools/build.sh index 23c6827a2..ad44ab515 100644 --- a/packages/termux-tools/build.sh +++ b/packages/termux-tools/build.sh @@ -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 diff --git a/packages/termux-tools/termux-setup-storage b/packages/termux-tools/termux-setup-storage index 3fc8c50bd..0a7d6324a 100755 --- a/packages/termux-tools/termux-setup-storage +++ b/packages/termux-tools/termux-setup-storage @@ -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