From 14d1bc91e4d17c70002df5dd6778c7bab1cc92d2 Mon Sep 17 00:00:00 2001 From: bolvan Date: Sun, 5 May 2019 12:00:44 +0300 Subject: [PATCH] support for centos 7+, fedora --- init.d/debian/zapret | 38 ++++++++++++++++++++++++++++----- install_easy.sh | 50 +++++++++++++++++++++++++++++--------------- readme.txt | 18 +++++++++++++--- uninstall_easy.sh | 9 ++++++-- 4 files changed, 88 insertions(+), 27 deletions(-) diff --git a/init.d/debian/zapret b/init.d/debian/zapret index 2a9491f..ba60c37 100755 --- a/init.d/debian/zapret +++ b/init.d/debian/zapret @@ -72,7 +72,7 @@ prepare_tpws() # $TPWS_USER is required to prevent redirection of the traffic originating from TPWS itself # otherwise infinite loop will occur # also its good idea not to run tpws as root - adduser --disabled-login --no-create-home --system --quiet $TPWS_USER + id -u $TPWS_USER >/dev/null 2>/dev/null || adduser --no-create-home --system --shell /bin/false $TPWS_USER # otherwise linux kernel will treat 127.0.0.1 as "martian" ip and refuse routing to it # NOTE : kernels <3.6 do not have this feature. consider upgrading or change DNAT to REDIRECT and do not bind to 127.0.0.1 for iface in /proc/sys/net/ipv4/conf/*; do sysctl -qw net.ipv4.conf.$(basename $iface).route_localnet=1; done @@ -134,6 +134,10 @@ fw_nfqws_del_post() true } +exists() +{ + which $1 >/dev/null 2>/dev/null +} run_daemon() { # $1 - daemon string id or number. can use 1,2,3,... @@ -141,9 +145,22 @@ run_daemon() # $3 - daemon args # use $PIDDIR/$DAEMONBASE$1.pid as pidfile local DAEMONBASE=$(basename $2) + local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid echo "Starting daemon $1: $2 $3" - start-stop-daemon --start --quiet --pidfile $PIDDIR/$DAEMONBASE$1.pid --background --make-pidfile \ - --exec $2 -- $3 + if exists start-stop-daemon ; then + start-stop-daemon --start --quiet --pidfile "$PIDFILE" --background --make-pidfile \ + --exec "$2" -- $3 + elif exists daemonize ; then + daemonize -p "$PIDFILE" "$2" $3 + else + nohup "$2" $3 >/dev/null 2>/dev/null & + PID=$(jobs -p %1) + if [ -n "$PID" ]; then + echo $PID >$PIDFILE + else + echo could not start daemon $1 : $2 $3 + fi + fi } stop_daemon() { @@ -151,9 +168,20 @@ stop_daemon() # $2 - daemon # use $PIDDIR/$DAEMONBASE$1.pid as pidfile local DAEMONBASE=$(basename $2) + local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid echo "Stopping daemon $1: $2" - start-stop-daemon --oknodo --stop --quiet --pidfile $PIDDIR/$DAEMONBASE$1.pid \ - --exec $2 + if exists start-stop-daemon ; then + start-stop-daemon --oknodo --stop --quiet --pidfile "$PIDFILE" \ + --exec "$2" + else + if [ -f "$PIDFILE" ]; then + read PID <"$PIDFILE" + kill $PID + else + echo no pidfile : $PIDFILE + false + fi + fi } diff --git a/install_easy.sh b/install_easy.sh index 44448a2..2e0e870 100755 --- a/install_easy.sh +++ b/install_easy.sh @@ -2,12 +2,21 @@ # 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 +# if its not apt or yum based system then manually install ipset, curl, lsb-core + +exists() +{ + which $1 >/dev/null 2>/dev/null +} +whichq() +{ + which $1 2>/dev/null +} [ $(id -u) -ne "0" ] && { echo root is required - which sudo >/dev/null && exec sudo $0 - which su >/dev/null && exec su -c $0 + exists sudo && exec sudo $0 + exists su && exec su -c $0 echo su or sudo not found exit 2 } @@ -22,7 +31,6 @@ INIT_SCRIPT=/etc/init.d/zapret GET_IPLIST=$EXEDIR/ipset/get_antizapret.sh GET_IPLIST_PREFIX=$EXEDIR/ipset/get_ - exitp() { echo @@ -34,7 +42,7 @@ exitp() echo \* checking system ... -SYSTEMCTL=$(which systemctl) +SYSTEMCTL=$(whichq systemctl) [ ! -x "$SYSTEMCTL" ] && { echo not systemd based system exitp 5 @@ -73,25 +81,33 @@ echo running from $EXEDIR echo \* checking prerequisites ... -if [ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] || ! which ipset >/dev/null || ! which curl >/dev/null ; then +if [ -x "$LSB_INSTALL" ] && [ -x "$LSB_REMOVE" ] && exists ipset && exists curl ; then + echo everything is present +else echo \* installing prerequisites ... - APTGET=$(which apt-get) - [ ! -x "$APTGET" ] && { - echo not apt based system + APTGET=$(whichq apt-get) + YUM=$(whichq yum) + if [ -x "$APTGET" ] ; then + "$APTGET" update + "$APTGET" install -y --no-install-recommends ipset curl lsb-core dnsutils || { + echo could not install prerequisites + exitp 6 + } + elif [ -x "$YUM" ] ; then + "$YUM" -y install curl ipset redhat-lsb-core daemonize || { + echo could not install prerequisites + exitp 6 + } + else + echo supported package manager not found + echo you must manually install : ipset curl lsb-core exitp 5 - } - "$APTGET" update - "$APTGET" install -y --no-install-recommends ipset curl lsb-core dnsutils || { - echo could not install prerequisites - exitp 6 - } + fi [ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] && { echo lsb install scripts not found exitp 7 } -else - echo everything is present fi echo \* installing binaries ... diff --git a/readme.txt b/readme.txt index b7e660c..fc87e1b 100644 --- a/readme.txt +++ b/readme.txt @@ -310,11 +310,23 @@ stop : systemctl stop zapret status, output messages : systemctl status zapret После изменения /etc/init.d/zapret : systemctl daemon-reload -Пример установки на debian-подобную систему для чайников --------------------------------------------------------- +Centos 7+, Fedora +----------------- + +Centos с 7 версии и более-менее новые федоры построены на systemd. +В качестве пакетного менеджера используется yum. + +Установить пакеты : + yum install -y curl ipset redhat-lsb-core daemonize + +Далее все аналогично debian. +Инит скрипт init.d/debian/zapret адаптирован под условия новых centos и fedora. + +Пример установки на debian-подобную систему, centos 7+, fedora для чайников +--------------------------------------------------------------------------- Ты простой юзер ? Не хочешь ни во что вникать, а хочешь нажать и чтобы сразу заработало ? -Пользуешься ubuntu или debian ? Тогда этот вариант для тебя. +Пользуешься ubuntu 16+, debian 8+, centos 7+, fedora ? Тогда этот вариант для тебя. Есть шансы, что оно заработает с минимумом усилий. Запусти терминал и в нем вбивай команды : # su diff --git a/uninstall_easy.sh b/uninstall_easy.sh index b6d9236..f975b43 100755 --- a/uninstall_easy.sh +++ b/uninstall_easy.sh @@ -2,10 +2,15 @@ # automated script for easy uninstalling zapret on systemd based system +exists() +{ + which $1 >/dev/null 2>/dev/null +} + [ $(id -u) -ne "0" ] && { echo root is required - which sudo >/dev/null && exec sudo $0 - which su >/dev/null && exec su -c $0 + exists sudo && exec sudo $0 + exists su && exec su -c $0 echo su or sudo not found exit 2 }