From 4b19e6f409e003d5780649402c230bd45f85e830 Mon Sep 17 00:00:00 2001 From: bolvan Date: Sat, 4 May 2019 18:22:47 +0300 Subject: [PATCH] install_easy : copy itself to /opt/zapret --- install_easy.sh | 34 ++++++++++++++++++++++++++++++++++ uninstall_easy.sh | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/install_easy.sh b/install_easy.sh index 177b9fa..a7b28d8 100755 --- a/install_easy.sh +++ b/install_easy.sh @@ -14,6 +14,7 @@ SCRIPT=$(readlink -f $0) EXEDIR=$(dirname $SCRIPT) +ZAPRET_BASE=/opt/zapret LSB_INSTALL=/usr/lib/lsb/install_initd LSB_REMOVE=/usr/lib/lsb/remove_initd INIT_SCRIPT_SRC=$EXEDIR/init.d/debian/zapret @@ -21,6 +22,7 @@ INIT_SCRIPT=/etc/init.d/zapret GET_IPLIST=$EXEDIR/ipset/get_antizapret.sh GET_IPLIST_PREFIX=$EXEDIR/ipset/get_ + echo \* checking system ... SYSTEMCTL=$(which systemctl) @@ -29,6 +31,37 @@ SYSTEMCTL=$(which systemctl) exit 5 } + +echo \* checking location ... + +[ "$EXEDIR" != "$ZAPRET_BASE" ] && { + echo easy install is supported only from default location : $ZAPRET_BASE + echo currenlty its run from $EXEDIR + echo -n "do you want the installer to copy it for you (Y/N) ? " + read A + if [ "$A" = "Y" ] || [ "$A" = "y" ]; then + if [ -d "$ZAPRET_BASE" ]; then + echo installer found existing $ZAPRET_BASE + echo -n "do you want to delete all files there and copy this version (Y/N) ? " + read A + if [ "$A" = "Y" ] || [ "$A" = "y" ]; then + rm -r "$ZAPRET_BASE" + else + echo refused to overwrite $ZAPRET_BASE. exiting + exit 3 + fi + fi + cp -R $EXEDIR $ZAPRET_BASE + echo relaunching itself from $ZAPRET_BASE + exec $ZAPRET_BASE/$(basename $0) + else + echo copying aborted. exiting + exit 3 + fi +} +echo running from $EXEDIR + + echo \* checking prerequisites ... if [ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] || ! which ipset >/dev/null || ! which curl >/dev/null ; then @@ -76,6 +109,7 @@ script_mode=Y ;; *) echo aborted + exit 3 ;; esac } diff --git a/uninstall_easy.sh b/uninstall_easy.sh index a5cd821..a4d7990 100755 --- a/uninstall_easy.sh +++ b/uninstall_easy.sh @@ -28,6 +28,7 @@ SYSTEMCTL=$(which systemctl) echo \* stopping service and unregistering init script with LSB ... +"$SYSTEMCTL" disable zapret "$SYSTEMCTL" stop zapret [ -f "$INIT_SCRIPT" ] && "$LSB_REMOVE" $INIT_SCRIPT @@ -48,6 +49,10 @@ script_mode=Y fi } +echo \* systemd cleanup ... + +"$SYSTEMCTL" daemon-reload + echo \* removing crontab entry ... CRONTMP=/tmp/cron.tmp