generalize easy script for any systemd system

This commit is contained in:
bolvan 2019-05-04 14:51:47 +03:00
parent fbc4e6d6f4
commit 2e9a6cf502
3 changed files with 51 additions and 38 deletions

View File

@ -1,11 +1,15 @@
#!/bin/sh
# automated script for easy installing zapret on debian or ubuntu based system
# system must use apt as package manager and systemd
# automated script for easy installing zapret on systemd based system
# all required tools must be already present or system must use apt as package manager
# if its not apt based system then manually install ipset, curl, lsb-core
[ $(id -u) -ne "0" ] && {
echo root is required
exec sudo $0
which sudo >/dev/null && exec sudo $0
which su >/dev/null && exec su -c $0
echo su or sudo not found
exit 2
}
SCRIPT=$(readlink -f $0)
@ -19,27 +23,34 @@ GET_IPLIST_PREFIX=$EXEDIR/ipset/get_
echo \* checking system ...
APTGET=$(which apt-get)
SYSTEMCTL=$(which systemctl)
[ ! -x "$APTGET" ] || [ ! -x "$SYSTEMCTL" ] && {
echo not debian-like system
[ ! -x "$SYSTEMCTL" ] && {
echo not systemd based system
exit 5
}
echo \* checking prerequisites ...
echo \* installing prerequisites ...
"$APTGET" update
"$APTGET" install -y --no-install-recommends ipset curl lsb-core dnsutils || {
echo could not install prerequisites
exit 6
}
[ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] && {
echo lsb install scripts not found
exit 7
}
if [ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] || ! which ipset >/dev/null || ! which curl >/dev/null ; then
echo \* installing prerequisites ...
APTGET=$(which apt-get)
[ ! -x "$APTGET" ] && {
echo not apt based system
exit 5
}
"$APTGET" update
"$APTGET" install -y --no-install-recommends ipset curl lsb-core dnsutils || {
echo could not install prerequisites
exit 6
}
[ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] && {
echo lsb install scripts not found
exit 7
}
else
echo everything is present
fi
echo \* installing binaries ...
@ -56,16 +67,15 @@ script_mode=Y
cmp -s $INIT_SCRIPT $INIT_SCRIPT_SRC ||
{
echo $INIT_SCRIPT already exists and differs from $INIT_SCRIPT_SRC
echo Y = overwrite with new version
echo N = exit
echo L = leave current version and continue
echo Y = overwrite with new version
echo N = exit
echo L = leave current version and continue
read script_mode
case "${script_mode}" in
Y|y|L|l)
;;
*)
echo aborted
exit 1
;;
esac
}

View File

@ -323,17 +323,26 @@ status, output messages : systemctl status zapret
# apt-get install git
# cd /opt
# git clone https://github.com/bol-van/zapret
# zapret/install_debian_easy.sh
# zapret/install_easy.sh
Надоело ?
# su
# /opt/zapret/uninstall_debian_easy.sh
# /opt/zapret/uninstall_easy.sh
# rm -r /opt/zapret
Скрипты простой установки могут быть удобны и для нечайников для первоначальной установки,
после которой можно поправить настройки вручную. Так устанавливать быстрее.
Эти скрипты будут работать и на других системах на базе systemd при условии, что
уже есть следующие программы :
/usr/lib/lsb/install_initd
/usr/lib/lsb/remove_initd
ipset
curl
Их можно установить вручную при помощи менеджера пакетов вашей ОС.
Другие linux системы
--------------------

View File

@ -1,11 +1,13 @@
#!/bin/sh
# automated script for easy installing zapret on debian or ubuntu based system
# system must use apt as package manager and systemd
# automated script for easy uninstalling zapret on systemd based system
[ $(id -u) -ne "0" ] && {
echo root is required
exec sudo $0
which sudo >/dev/null && exec sudo $0
which su >/dev/null && exec su -c $0
echo su or sudo not found
exit 2
}
SCRIPT=$(readlink -f $0)
@ -18,17 +20,14 @@ GET_IPLIST_PREFIX=$EXEDIR/ipset/get_
echo \* checking system ...
APTGET=$(which apt-get)
SYSTEMCTL=$(which systemctl)
[ ! -x "$APTGET" ] || [ ! -x "$SYSTEMCTL" ] && {
echo not debian-like system
[ ! -x "$SYSTEMCTL" ] && {
echo not systemd based system
exit 5
}
echo \* stopping service and unregistering init script with LSB ...
"$SYSTEMCTL" disable zapret
"$SYSTEMCTL" stop zapret
[ -f "$INIT_SCRIPT" ] && "$LSB_REMOVE" $INIT_SCRIPT
@ -49,7 +48,6 @@ script_mode=Y
fi
}
echo \* removing crontab entry ...
CRONTMP=/tmp/cron.tmp
@ -63,8 +61,4 @@ if grep -q "$GET_IPLIST_PREFIX" $CRONTMP; then
fi
rm -f $CRONTMP
echo \* systemd cleanup ...
"$SYSTEMCTL" daemon-reload
exit 0