support for centos 7+, fedora

This commit is contained in:
bolvan 2019-05-05 12:00:44 +03:00
parent c0f1473f5f
commit 14d1bc91e4
4 changed files with 88 additions and 27 deletions

View File

@ -72,7 +72,7 @@ prepare_tpws()
# $TPWS_USER is required to prevent redirection of the traffic originating from TPWS itself # $TPWS_USER is required to prevent redirection of the traffic originating from TPWS itself
# otherwise infinite loop will occur # otherwise infinite loop will occur
# also its good idea not to run tpws as root # 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 # 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 # 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 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 true
} }
exists()
{
which $1 >/dev/null 2>/dev/null
}
run_daemon() run_daemon()
{ {
# $1 - daemon string id or number. can use 1,2,3,... # $1 - daemon string id or number. can use 1,2,3,...
@ -141,9 +145,22 @@ run_daemon()
# $3 - daemon args # $3 - daemon args
# use $PIDDIR/$DAEMONBASE$1.pid as pidfile # use $PIDDIR/$DAEMONBASE$1.pid as pidfile
local DAEMONBASE=$(basename $2) local DAEMONBASE=$(basename $2)
local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid
echo "Starting daemon $1: $2 $3" echo "Starting daemon $1: $2 $3"
start-stop-daemon --start --quiet --pidfile $PIDDIR/$DAEMONBASE$1.pid --background --make-pidfile \ if exists start-stop-daemon ; then
--exec $2 -- $3 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() stop_daemon()
{ {
@ -151,9 +168,20 @@ stop_daemon()
# $2 - daemon # $2 - daemon
# use $PIDDIR/$DAEMONBASE$1.pid as pidfile # use $PIDDIR/$DAEMONBASE$1.pid as pidfile
local DAEMONBASE=$(basename $2) local DAEMONBASE=$(basename $2)
local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid
echo "Stopping daemon $1: $2" echo "Stopping daemon $1: $2"
start-stop-daemon --oknodo --stop --quiet --pidfile $PIDDIR/$DAEMONBASE$1.pid \ if exists start-stop-daemon ; then
--exec $2 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
} }

View File

@ -2,12 +2,21 @@
# automated script for easy installing zapret on systemd based system # 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 # 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" ] && { [ $(id -u) -ne "0" ] && {
echo root is required echo root is required
which sudo >/dev/null && exec sudo $0 exists sudo && exec sudo $0
which su >/dev/null && exec su -c $0 exists su && exec su -c $0
echo su or sudo not found echo su or sudo not found
exit 2 exit 2
} }
@ -22,7 +31,6 @@ INIT_SCRIPT=/etc/init.d/zapret
GET_IPLIST=$EXEDIR/ipset/get_antizapret.sh GET_IPLIST=$EXEDIR/ipset/get_antizapret.sh
GET_IPLIST_PREFIX=$EXEDIR/ipset/get_ GET_IPLIST_PREFIX=$EXEDIR/ipset/get_
exitp() exitp()
{ {
echo echo
@ -34,7 +42,7 @@ exitp()
echo \* checking system ... echo \* checking system ...
SYSTEMCTL=$(which systemctl) SYSTEMCTL=$(whichq systemctl)
[ ! -x "$SYSTEMCTL" ] && { [ ! -x "$SYSTEMCTL" ] && {
echo not systemd based system echo not systemd based system
exitp 5 exitp 5
@ -73,25 +81,33 @@ echo running from $EXEDIR
echo \* checking prerequisites ... 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 ... echo \* installing prerequisites ...
APTGET=$(which apt-get) APTGET=$(whichq apt-get)
[ ! -x "$APTGET" ] && { YUM=$(whichq yum)
echo not apt based system 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 exitp 5
} fi
"$APTGET" update
"$APTGET" install -y --no-install-recommends ipset curl lsb-core dnsutils || {
echo could not install prerequisites
exitp 6
}
[ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] && { [ ! -x "$LSB_INSTALL" ] || [ ! -x "$LSB_REMOVE" ] && {
echo lsb install scripts not found echo lsb install scripts not found
exitp 7 exitp 7
} }
else
echo everything is present
fi fi
echo \* installing binaries ... echo \* installing binaries ...

View File

@ -310,11 +310,23 @@ stop : systemctl stop zapret
status, output messages : systemctl status zapret status, output messages : systemctl status zapret
После изменения /etc/init.d/zapret : systemctl daemon-reload После изменения /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 # su

View File

@ -2,10 +2,15 @@
# automated script for easy uninstalling zapret on systemd based system # automated script for easy uninstalling zapret on systemd based system
exists()
{
which $1 >/dev/null 2>/dev/null
}
[ $(id -u) -ne "0" ] && { [ $(id -u) -ne "0" ] && {
echo root is required echo root is required
which sudo >/dev/null && exec sudo $0 exists sudo && exec sudo $0
which su >/dev/null && exec su -c $0 exists su && exec su -c $0
echo su or sudo not found echo su or sudo not found
exit 2 exit 2
} }