Compare commits

...

3 Commits

Author SHA1 Message Date
bol-van
15751976e0 scripts: add quotes to paths 2024-08-25 18:04:11 +03:00
bol-van
6276d92ffb rm bad file 2024-08-25 17:50:50 +03:00
bol-van
983205e984 scripts: use ZAPRET_RW and ZAPRET_CONFIG vars 2024-08-25 17:49:15 +03:00
12 changed files with 88 additions and 40 deletions

View File

@ -2,11 +2,17 @@
EXEDIR="$(dirname "$0")" EXEDIR="$(dirname "$0")"
EXEDIR="$(cd "$EXEDIR"; pwd)" EXEDIR="$(cd "$EXEDIR"; pwd)"
ZAPRET_CONFIG="$EXEDIR/config" ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"}
ZAPRET_BASE="$EXEDIR" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
ZAPRET_CONFIG_DEFAULT="$ZAPRET_BASE/config.default"
[ -f "$ZAPRET_CONFIG" ] || { [ -f "$ZAPRET_CONFIG" ] || {
[ -f "${ZAPRET_CONFIG}.default" ] && cp "${ZAPRET_CONFIG}.default" "$ZAPRET_CONFIG" [ -f "$ZAPRET_CONFIG_DEFAULT" ] && {
ZAPRET_CONFIG_DIR="$(dirname "$ZAPRET_CONFIG")"
[ -d "$ZAPRET_CONFIG_DIR" ] || mkdir -p "$ZAPRET_CONFIG_DIR"
cp "$ZAPRET_CONFIG_DEFAULT" "$ZAPRET_CONFIG"
}
} }
[ -f "$ZAPRET_CONFIG" ] && . "$ZAPRET_CONFIG" [ -f "$ZAPRET_CONFIG" ] && . "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"

View File

@ -154,7 +154,7 @@ linux_get_subsys()
local INIT="$(sed 's/\x0/\n/g' /proc/1/cmdline | head -n 1)" local INIT="$(sed 's/\x0/\n/g' /proc/1/cmdline | head -n 1)"
[ -L "$INIT" ] && INIT=$(readlink "$INIT") [ -L "$INIT" ] && INIT=$(readlink "$INIT")
INIT=$(basename "$INIT") INIT="$(basename "$INIT")"
if [ -f "/etc/openwrt_release" ] && [ "$INIT" = "procd" ] ; then if [ -f "/etc/openwrt_release" ] && [ "$INIT" = "procd" ] ; then
SUBSYS=openwrt SUBSYS=openwrt
elif [ -x "/bin/ndm" ] ; then elif [ -x "/bin/ndm" ] ; then

View File

@ -89,7 +89,7 @@ check_system()
# do not use 'exe' because it requires root # do not use 'exe' because it requires root
local INIT="$(sed 's/\x0/\n/g' /proc/1/cmdline | head -n 1)" local INIT="$(sed 's/\x0/\n/g' /proc/1/cmdline | head -n 1)"
[ -L "$INIT" ] && INIT=$(readlink "$INIT") [ -L "$INIT" ] && INIT=$(readlink "$INIT")
INIT=$(basename "$INIT") INIT="$(basename "$INIT")"
# some distros include systemctl without systemd # some distros include systemctl without systemd
if [ -d "$SYSTEMD_DIR" ] && [ -x "$SYSTEMCTL" ] && [ "$INIT" = "systemd" ]; then if [ -d "$SYSTEMD_DIR" ] && [ -x "$SYSTEMCTL" ] && [ "$INIT" = "systemd" ]; then
SYSTEM=systemd SYSTEM=systemd

View File

@ -117,7 +117,7 @@ resolve_lower_devices()
{ {
local l lower lowers local l lower lowers
while read lower; do while read lower; do
lower=$(basename "$lower") lower="$(basename "$lower")"
l="${lower#lower_*}" l="${lower#lower_*}"
[ "$l" != "$lower" ] && append_separator_list lowers ' ' '' "$l" [ "$l" != "$lower" ] && append_separator_list lowers ' ' '' "$l"
done done

View File

@ -1,7 +1,9 @@
# init script functions library for macos # init script functions library for macos
[ -n "$ZAPRET_BASE" ] || ZAPRET_BASE=/opt/zapret ZAPRET_BASE=${ZAPRET_BASE:-/opt/zapret}
. "$ZAPRET_BASE/config" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
. "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
. "$ZAPRET_BASE/common/pf.sh" . "$ZAPRET_BASE/common/pf.sh"
. "$ZAPRET_BASE/common/list.sh" . "$ZAPRET_BASE/common/list.sh"

View File

@ -31,7 +31,9 @@ check_need_to_reload_tpws6()
else else
ZAPRET_BASE=/opt/zapret ZAPRET_BASE=/opt/zapret
fi fi
. "$ZAPRET_BASE/config" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
. "$ZAPRET_CONFIG"
check_need_to_reload_tpws6 check_need_to_reload_tpws6
[ -n "$RELOAD_TPWS6" ] && { [ -n "$RELOAD_TPWS6" ] && {

View File

@ -1,7 +1,9 @@
. /lib/functions/network.sh . /lib/functions/network.sh
[ -n "$ZAPRET_BASE" ] || ZAPRET_BASE=/opt/zapret ZAPRET_BASE=${ZAPRET_BASE:-/opt/zapret}
. "$ZAPRET_BASE/config" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
. "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
. "$ZAPRET_BASE/common/fwtype.sh" . "$ZAPRET_BASE/common/fwtype.sh"
. "$ZAPRET_BASE/common/queue.sh" . "$ZAPRET_BASE/common/queue.sh"

View File

@ -1,7 +1,9 @@
# init script functions library for desktop linux systems # init script functions library for desktop linux systems
[ -n "$ZAPRET_BASE" ] || ZAPRET_BASE=/opt/zapret ZAPRET_BASE=${ZAPRET_BASE:-/opt/zapret}
. "$ZAPRET_BASE/config" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
. "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
. "$ZAPRET_BASE/common/fwtype.sh" . "$ZAPRET_BASE/common/fwtype.sh"
. "$ZAPRET_BASE/common/queue.sh" . "$ZAPRET_BASE/common/queue.sh"

View File

@ -5,7 +5,7 @@ EXEDIR="$(cd "$EXEDIR"; pwd)"
BINS=binaries BINS=binaries
BINDIR="$EXEDIR/$BINS" BINDIR="$EXEDIR/$BINS"
ZAPRET_BASE="$EXEDIR" ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"}
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
check_dir() check_dir()
@ -41,11 +41,11 @@ check_dir()
# link or copy executables. uncomment either ln or cp, comment other # link or copy executables. uncomment either ln or cp, comment other
ccp() ccp()
{ {
local F=$(basename $1) local F="$(basename "$1")"
[ -d "$EXEDIR/$2" ] || mkdir "$EXEDIR/$2" [ -d "$ZAPRET_BASE/$2" ] || mkdir "$ZAPRET_BASE/$2"
[ -f "$EXEDIR/$2/$F" ] && rm -f "$EXEDIR/$2/$F" [ -f "$ZAPRET_BASE/$2/$F" ] && rm -f "$ZAPRET_BASE/$2/$F"
ln -fs "../$BINS/$1" "$EXEDIR/$2" && echo linking : "../$BINS/$1" =\> "$EXEDIR/$2" ln -fs "../$BINS/$1" "$ZAPRET_BASE/$2" && echo linking : "../$BINS/$1" =\> "$ZAPRET_BASE/$2"
#cp -f "$BINDIR/$1" "$EXEDIR/$2" && echo copying : "$BINDIR/$1" =\> "$EXEDIR/$2" #cp -f "../$BINS/$1" "$ZAPRET_BASE/$2" && echo copying : "../$BINS/$1" =\> "$ZAPRET_BASE/$2"
} }
UNAME=$(uname) UNAME=$(uname)

View File

@ -4,11 +4,17 @@
EXEDIR="$(dirname "$0")" EXEDIR="$(dirname "$0")"
EXEDIR="$(cd "$EXEDIR"; pwd)" EXEDIR="$(cd "$EXEDIR"; pwd)"
IPSET_DIR="$EXEDIR/ipset" ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"}
ZAPRET_CONFIG="$EXEDIR/config" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_BASE="$EXEDIR" ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
ZAPRET_CONFIG_DEFAULT="$ZAPRET_BASE/config.default"
IPSET_DIR="$ZAPRET_BASE/ipset"
[ -f "$ZAPRET_CONFIG" ] || cp "${ZAPRET_CONFIG}.default" "$ZAPRET_CONFIG" [ -f "$ZAPRET_CONFIG" ] || {
ZAPRET_CONFIG_DIR="$(dirname "$ZAPRET_CONFIG")"
[ -d "$ZAPRET_CONFIG_DIR" ] || mkdir -p "$ZAPRET_CONFIG_DIR"
cp "$ZAPRET_CONFIG_DEFAULT" "$ZAPRET_CONFIG"
}
. "$ZAPRET_CONFIG" . "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
. "$ZAPRET_BASE/common/elevate.sh" . "$ZAPRET_BASE/common/elevate.sh"
@ -19,7 +25,7 @@ ZAPRET_BASE="$EXEDIR"
. "$ZAPRET_BASE/common/virt.sh" . "$ZAPRET_BASE/common/virt.sh"
# install target # install target
ZAPRET_TARGET=/opt/zapret ZAPRET_TARGET=${ZAPRET_TARGET:-/opt/zapret}
GET_LIST="$IPSET_DIR/get_config.sh" GET_LIST="$IPSET_DIR/get_config.sh"
@ -378,12 +384,16 @@ select_mode_iface()
default_files() default_files()
{ {
[ -f "$1/ipset/$file/zapret-hosts-user-exclude.txt" ] || cp "$1/ipset/$file/zapret-hosts-user-exclude.txt.default" "$1/ipset/$file/zapret-hosts-user-exclude.txt" # $1 - ro location
[ -f "$1/ipset/$file/zapret-hosts-user.txt" ] || echo nonexistent.domain >> "$1/ipset/$file/zapret-hosts-user.txt" # $2 - rw location (can be equal to $1)
[ -f "$1/ipset/$file/zapret-hosts-user-ipban.txt" ] || touch "$1/ipset/$file/zapret-hosts-user-ipban.txt" [ -d "$2/ipset" ] || mkdir -p "$2/ipset"
[ -f "$2/ipset/zapret-hosts-user-exclude.txt" ] || cp "$1/ipset/zapret-hosts-user-exclude.txt.default" "$2/ipset/zapret-hosts-user-exclude.txt"
[ -f "$2/ipset/zapret-hosts-user.txt" ] || echo nonexistent.domain >> "$2/ipset/zapret-hosts-user.txt"
[ -f "$2/ipset/zapret-hosts-user-ipban.txt" ] || touch "$2/ipset/zapret-hosts-user-ipban.txt"
for dir in openwrt sysv macos; do for dir in openwrt sysv macos; do
[ -d "$1/init.d/$dir" ] && { [ -d "$1/init.d/$dir" ] && {
[ -f "$1/init.d/$dir/custom" ] || cp "$1/init.d/$dir/custom.default" "$1/init.d/$dir/custom" [ -d "$2/init.d/$dir" ] || mkdir -p "$2/init.d/$dir"
[ -f "$2/init.d/$dir/custom" ] || cp "$1/init.d/$dir/custom.default" "$2/init.d/$dir/custom"
} }
done done
} }
@ -420,7 +430,15 @@ fix_perms()
[ -d "$1" ] || return [ -d "$1" ] || return
find "$1" -type d -exec chmod 755 {} \; find "$1" -type d -exec chmod 755 {} \;
find "$1" -type f -exec chmod 644 {} \; find "$1" -type f -exec chmod 644 {} \;
chown -R root:root "$1" local chow
case "$UNAME" in
Linux)
chow=root:root
;;
*)
chow=root:wheel
esac
chown -R $chow "$1"
find "$1/binaries" '(' -name tpws -o -name dvtws -o -name nfqws -o -name ip2net -o -name mdig ')' -exec chmod 755 {} \; find "$1/binaries" '(' -name tpws -o -name dvtws -o -name nfqws -o -name ip2net -o -name mdig ')' -exec chmod 755 {} \;
for f in \ for f in \
install_bin.sh \ install_bin.sh \
@ -493,7 +511,7 @@ check_location()
# use inodes in case something is linked # use inodes in case something is linked
if [ -d "$ZAPRET_TARGET" ] && [ $(get_dir_inode "$EXEDIR") = $(get_dir_inode "$ZAPRET_TARGET") ]; then if [ -d "$ZAPRET_TARGET" ] && [ $(get_dir_inode "$EXEDIR") = $(get_dir_inode "$ZAPRET_TARGET") ]; then
default_files "$ZAPRET_TARGET" default_files "$ZAPRET_TARGET" "$ZAPRET_RW"
else else
echo echo
echo easy install is supported only from default location : $ZAPRET_TARGET echo easy install is supported only from default location : $ZAPRET_TARGET
@ -506,8 +524,10 @@ check_location()
echo directory needs to be replaced. config and custom scripts can be kept or replaced with clean version echo directory needs to be replaced. config and custom scripts can be kept or replaced with clean version
if ask_yes_no N "do you want to delete all files there and copy this version"; then if ask_yes_no N "do you want to delete all files there and copy this version"; then
echo echo
ask_yes_no Y "keep config, custom scripts and user lists" && keep=Y if [ $(get_dir_inode "$ZAPRET_BASE") = $(get_dir_inode "$ZAPRET_RW") ]; then
[ "$keep" = "Y" ] && backup_restore_settings 1 ask_yes_no Y "keep config, custom scripts and user lists" && keep=Y
[ "$keep" = "Y" ] && backup_restore_settings 1
fi
rm -r "$ZAPRET_TARGET" rm -r "$ZAPRET_TARGET"
else else
echo refused to overwrite $ZAPRET_TARGET. exiting echo refused to overwrite $ZAPRET_TARGET. exiting
@ -520,7 +540,7 @@ check_location()
fix_perms "$ZAPRET_TARGET" fix_perms "$ZAPRET_TARGET"
[ "$keep" = "Y" ] && backup_restore_settings 0 [ "$keep" = "Y" ] && backup_restore_settings 0
echo relaunching itself from $ZAPRET_TARGET echo relaunching itself from $ZAPRET_TARGET
exec $ZAPRET_TARGET/$(basename $0) exec "$ZAPRET_TARGET/$(basename "$0")"
else else
echo copying aborted. exiting echo copying aborted. exiting
exitp 3 exitp 3

View File

@ -4,10 +4,17 @@
EXEDIR="$(dirname "$0")" EXEDIR="$(dirname "$0")"
EXEDIR="$(cd "$EXEDIR"; pwd)" EXEDIR="$(cd "$EXEDIR"; pwd)"
ZAPRET_CONFIG="$EXEDIR/config" ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"}
ZAPRET_BASE="$EXEDIR" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
ZAPRET_CONFIG_DEFAULT="$ZAPRET_BASE/config.default"
[ -f "$ZAPRET_CONFIG" ] || {
ZAPRET_CONFIG_DIR="$(dirname "$ZAPRET_CONFIG")"
[ -d "$ZAPRET_CONFIG_DIR" ] || mkdir -p "$ZAPRET_CONFIG_DIR"
cp "$ZAPRET_CONFIG_DEFAULT" "$ZAPRET_CONFIG"
}
[ -f "$ZAPRET_CONFIG" ] || cp "${ZAPRET_CONFIG}.default" "$ZAPRET_CONFIG"
. "$ZAPRET_CONFIG" . "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
. "$ZAPRET_BASE/common/elevate.sh" . "$ZAPRET_BASE/common/elevate.sh"

View File

@ -4,11 +4,18 @@
EXEDIR="$(dirname "$0")" EXEDIR="$(dirname "$0")"
EXEDIR="$(cd "$EXEDIR"; pwd)" EXEDIR="$(cd "$EXEDIR"; pwd)"
IPSET_DIR="$EXEDIR/ipset" ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"}
ZAPRET_CONFIG="$EXEDIR/config" ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"}
ZAPRET_BASE="$EXEDIR" ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
ZAPRET_CONFIG_DEFAULT="$ZAPRET_BASE/config.default"
IPSET_DIR="$ZAPRET_BASE/ipset"
[ -f "$ZAPRET_CONFIG" ] || {
ZAPRET_CONFIG_DIR="$(dirname "$ZAPRET_CONFIG")"
[ -d "$ZAPRET_CONFIG_DIR" ] || mkdir -p "$ZAPRET_CONFIG_DIR"
cp "$ZAPRET_CONFIG_DEFAULT" "$ZAPRET_CONFIG"
}
[ -f "$ZAPRET_CONFIG" ] || cp "${ZAPRET_CONFIG}.default" "$ZAPRET_CONFIG"
. "$ZAPRET_CONFIG" . "$ZAPRET_CONFIG"
. "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/base.sh"
. "$ZAPRET_BASE/common/elevate.sh" . "$ZAPRET_BASE/common/elevate.sh"