Files
Snowy-Fluffy 068f1bd126 some bug fix
2025-07-14 14:56:36 +03:00

133 lines
4.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
detect_init() {
GET_LIST_PREFIX=/ipset/get_
SYSTEMD_DIR=/lib/systemd
[ -d "$SYSTEMD_DIR" ] || SYSTEMD_DIR=/usr/lib/systemd
[ -d "$SYSTEMD_DIR" ] && SYSTEMD_SYSTEM_DIR="$SYSTEMD_DIR/system"
INIT_SCRIPT=/etc/init.d/zapret
if [ -d /run/systemd/system ]; then
INIT_SYSTEM="systemd"
elif [ $SYSTEM == openwrt ]; then
INIT_SYSTEM="procd"
elif command -v openrc >/dev/null 2>&1; then
INIT_SYSTEM="openrc"
elif command -v runit >/dev/null 2>&1; then
INIT_SYSTEM="runit"
[ -f /etc/os-release ] && . /etc/os-release
if [ $ID = artix ]; then
INIT_SYSTEM="runit-artix"
fi
elif [ -x /sbin/init ] && /sbin/init --version 2>&1 | grep -qi "sysv init"; then
INIT_SYSTEM="sysvinit"
else
error_exit "Не удалось определить init."
fi
}
check_zapret_exist() {
case "$INIT_SYSTEM" in
systemd)
if [ -f /etc/systemd/system/timers.target.wants/zapret-list-update.timer ]; then
service_exists=true
else
service_exists=false
fi
;;
procd)
if [ -f /etc/init.d/zapret ]; then
service_exists=true
else
service_exists=false
fi
;;
runit)
ls /var/service | grep -q "zapret" && service_exists=true || service_exists=false
;;
runit-artix)
ls /run/runit/service | grep -q "zapret" && service_exists=true || service_exists=false
;;
openrc)
rc-service -l | grep -q "zapret" && service_exists=true || service_exists=false
;;
sysvinit)
[ -f /etc/init.d/zapret ] && service_exists=true || service_exists=false
;;
*)
ZAPRET_EXIST=false
return
;;
esac
if [ -d /opt/zapret ]; then
dir_exists=true
[ -d /opt/zapret/binaries ] && binaries_exists=true || binaries_exists=false
else
dir_exists=false
binaries_exists=false
fi
if [ "$service_exists" = true ] && [ "$dir_exists" = true ] && [ "$binaries_exists" = true ]; then
ZAPRET_EXIST=true
else
ZAPRET_EXIST=false
fi
}
check_zapret_status() {
case "$INIT_SYSTEM" in
systemd)
ZAPRET_ACTIVE=$(systemctl show -p ActiveState zapret | cut -d= -f2 || true)
ZAPRET_ENABLED=$(systemctl is-enabled zapret 2>/dev/null || echo "false")
ZAPRET_SUBSTATE=$(systemctl show -p SubState zapret | cut -d= -f2)
if [[ "$ZAPRET_ACTIVE" == "active" && "$ZAPRET_SUBSTATE" == "running" ]]; then
ZAPRET_ACTIVE=true
else
ZAPRET_ACTIVE=false
fi
if [[ "$ZAPRET_ENABLED" == "enabled" ]]; then
ZAPRET_ENABLED=true
else
ZAPRET_ENABLED=false
fi
if [[ "$ZAPRET_ENABLED" == "not-found" ]]; then
ZAPRET_ENABLED=false
fi
;;
openrc)
rc-service zapret status >/dev/null 2>&1 && ZAPRET_ACTIVE=true || ZAPRET_ACTIVE=false
rc-update show | grep -q zapret && ZAPRET_ENABLED=true || ZAPRET_ENABLED=false
;;
procd)
if /etc/init.d/zapret status | grep -q "running"; then
ZAPRET_ACTIVE=true
else
ZAPRET_ACTIVE=false
fi
if ls /etc/rc.d/ | grep -q zapret >/dev/null 2>&1; then
ZAPRET_ENABLED=true
else
ZAPRET_ENABLED=false
fi
;;
runit)
sv status zapret | grep -q "run" && ZAPRET_ACTIVE=true || ZAPRET_ACTIVE=false
ls /var/service | grep -q "zapret" && ZAPRET_ENABLED=true || ZAPRET_ENABLED=false
;;
runit-artix)
sv status zapret | grep -q "run" && ZAPRET_ACTIVE=true || ZAPRET_ACTIVE=false
ls /run/runit/service | grep -q "zapret" && ZAPRET_ENABLED=true || ZAPRET_ENABLED=false
;;
sysvinit)
service zapret status >/dev/null 2>&1 && ZAPRET_ACTIVE=true || ZAPRET_ACTIVE=false
;;
esac
}