diff --git a/blockcheck.sh b/blockcheck.sh index f798244..a7b2d9b 100755 --- a/blockcheck.sh +++ b/blockcheck.sh @@ -2,11 +2,17 @@ EXEDIR="$(dirname "$0")" EXEDIR="$(cd "$EXEDIR"; pwd)" -ZAPRET_CONFIG="$EXEDIR/config" -ZAPRET_BASE="$EXEDIR" +ZAPRET_BASE=${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}.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" . "$ZAPRET_BASE/common/base.sh" diff --git a/init.d/macos/functions b/init.d/macos/functions index fbafd1a..45f678e 100644 --- a/init.d/macos/functions +++ b/init.d/macos/functions @@ -1,7 +1,9 @@ # init script functions library for macos -[ -n "$ZAPRET_BASE" ] || ZAPRET_BASE=/opt/zapret -. "$ZAPRET_BASE/config" +ZAPRET_BASE=${ZAPRET_BASE:-/opt/zapret} +ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} +ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"} +. "$ZAPRET_CONFIG" . "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/pf.sh" . "$ZAPRET_BASE/common/list.sh" diff --git a/init.d/openwrt/90-zapret b/init.d/openwrt/90-zapret index a7fee78..8cb05f5 100644 --- a/init.d/openwrt/90-zapret +++ b/init.d/openwrt/90-zapret @@ -31,7 +31,9 @@ check_need_to_reload_tpws6() else ZAPRET_BASE=/opt/zapret fi - . "$ZAPRET_BASE/config" + ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} + ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"} + . "$ZAPRET_CONFIG" check_need_to_reload_tpws6 [ -n "$RELOAD_TPWS6" ] && { diff --git a/init.d/openwrt/functions b/init.d/openwrt/functions index bd91881..c46d866 100644 --- a/init.d/openwrt/functions +++ b/init.d/openwrt/functions @@ -1,7 +1,9 @@ . /lib/functions/network.sh -[ -n "$ZAPRET_BASE" ] || ZAPRET_BASE=/opt/zapret -. "$ZAPRET_BASE/config" +ZAPRET_BASE=${ZAPRET_BASE:-/opt/zapret} +ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} +ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"} +. "$ZAPRET_CONFIG" . "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/fwtype.sh" . "$ZAPRET_BASE/common/queue.sh" diff --git a/init.d/sysv/custom b/init.d/sysv/custom new file mode 100755 index 0000000..666d2d4 --- /dev/null +++ b/init.d/sysv/custom @@ -0,0 +1,34 @@ +# this script contain your special code to launch daemons and configure firewall +# use helpers from "functions" file +# in case of upgrade keep this file only, do not modify others + +zapret_custom_daemons() +{ + # $1 - 1 - run, 0 - stop + + # PLACEHOLDER + echo !!! NEED ATTENTION !!! + echo Start daemon\(s\) + echo Study how other sections work + + do_daemon $1 1 /bin/sleep 20 +} +zapret_custom_firewall() +{ + # $1 - 1 - run, 0 - stop + + # PLACEHOLDER + echo !!! NEED ATTENTION !!! + echo Configure iptables for required actions + echo Study how other sections work +} + +zapret_custom_firewall_nft() +{ + # stop logic is not required + + # PLACEHOLDER + echo !!! NEED ATTENTION !!! + echo Configure nftables for required actions + echo Study how other sections work +} diff --git a/init.d/sysv/functions b/init.d/sysv/functions index d3586aa..b4ba081 100644 --- a/init.d/sysv/functions +++ b/init.d/sysv/functions @@ -1,7 +1,9 @@ # init script functions library for desktop linux systems -[ -n "$ZAPRET_BASE" ] || ZAPRET_BASE=/opt/zapret -. "$ZAPRET_BASE/config" +ZAPRET_BASE=${ZAPRET_BASE:-/opt/zapret} +ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} +ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"} +. "$ZAPRET_CONFIG" . "$ZAPRET_BASE/common/base.sh" . "$ZAPRET_BASE/common/fwtype.sh" . "$ZAPRET_BASE/common/queue.sh" diff --git a/install_bin.sh b/install_bin.sh index 3f2e361..7f117fe 100755 --- a/install_bin.sh +++ b/install_bin.sh @@ -5,7 +5,7 @@ EXEDIR="$(cd "$EXEDIR"; pwd)" BINS=binaries BINDIR="$EXEDIR/$BINS" -ZAPRET_BASE="$EXEDIR" +ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"} . "$ZAPRET_BASE/common/base.sh" check_dir() @@ -42,10 +42,10 @@ check_dir() ccp() { local F=$(basename $1) - [ -d "$EXEDIR/$2" ] || mkdir "$EXEDIR/$2" - [ -f "$EXEDIR/$2/$F" ] && rm -f "$EXEDIR/$2/$F" - ln -fs "../$BINS/$1" "$EXEDIR/$2" && echo linking : "../$BINS/$1" =\> "$EXEDIR/$2" - #cp -f "$BINDIR/$1" "$EXEDIR/$2" && echo copying : "$BINDIR/$1" =\> "$EXEDIR/$2" + [ -d "$ZAPRET_BASE/$2" ] || mkdir "$ZAPRET_BASE/$2" + [ -f "$ZAPRET_BASE/$2/$F" ] && rm -f "$ZAPRET_BASE/$2/$F" + ln -fs "../$BINS/$1" "$ZAPRET_BASE/$2" && echo linking : "../$BINS/$1" =\> "$ZAPRET_BASE/$2" + #cp -f "../$BINS/$1" "$ZAPRET_BASE/$2" && echo copying : "../$BINS/$1" =\> "$ZAPRET_BASE/$2" } UNAME=$(uname) diff --git a/install_easy.sh b/install_easy.sh index 23bd371..081674d 100755 --- a/install_easy.sh +++ b/install_easy.sh @@ -4,11 +4,17 @@ EXEDIR="$(dirname "$0")" EXEDIR="$(cd "$EXEDIR"; pwd)" -IPSET_DIR="$EXEDIR/ipset" -ZAPRET_CONFIG="$EXEDIR/config" -ZAPRET_BASE="$EXEDIR" +ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"} +ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} +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_BASE/common/base.sh" . "$ZAPRET_BASE/common/elevate.sh" @@ -19,7 +25,7 @@ ZAPRET_BASE="$EXEDIR" . "$ZAPRET_BASE/common/virt.sh" # install target -ZAPRET_TARGET=/opt/zapret +ZAPRET_TARGET=${ZAPRET_TARGET:-/opt/zapret} GET_LIST="$IPSET_DIR/get_config.sh" @@ -378,12 +384,16 @@ select_mode_iface() 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" - [ -f "$1/ipset/$file/zapret-hosts-user.txt" ] || echo nonexistent.domain >> "$1/ipset/$file/zapret-hosts-user.txt" - [ -f "$1/ipset/$file/zapret-hosts-user-ipban.txt" ] || touch "$1/ipset/$file/zapret-hosts-user-ipban.txt" + # $1 - ro location + # $2 - rw location (can be equal to $1) + [ -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 [ -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 } @@ -420,7 +430,15 @@ fix_perms() [ -d "$1" ] || return find "$1" -type d -exec chmod 755 {} \; 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 {} \; for f in \ install_bin.sh \ @@ -493,7 +511,7 @@ check_location() # use inodes in case something is linked 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 echo 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 if ask_yes_no N "do you want to delete all files there and copy this version"; then echo - ask_yes_no Y "keep config, custom scripts and user lists" && keep=Y - [ "$keep" = "Y" ] && backup_restore_settings 1 + if [ $(get_dir_inode "$ZAPRET_BASE") = $(get_dir_inode "$ZAPRET_RW") ]; then + ask_yes_no Y "keep config, custom scripts and user lists" && keep=Y + [ "$keep" = "Y" ] && backup_restore_settings 1 + fi rm -r "$ZAPRET_TARGET" else echo refused to overwrite $ZAPRET_TARGET. exiting @@ -520,7 +540,7 @@ check_location() fix_perms "$ZAPRET_TARGET" [ "$keep" = "Y" ] && backup_restore_settings 0 echo relaunching itself from $ZAPRET_TARGET - exec $ZAPRET_TARGET/$(basename $0) + exec "$ZAPRET_TARGET/$(basename $0)" else echo copying aborted. exiting exitp 3 diff --git a/install_prereq.sh b/install_prereq.sh index df03a56..be938cc 100755 --- a/install_prereq.sh +++ b/install_prereq.sh @@ -4,10 +4,17 @@ EXEDIR="$(dirname "$0")" EXEDIR="$(cd "$EXEDIR"; pwd)" -ZAPRET_CONFIG="$EXEDIR/config" -ZAPRET_BASE="$EXEDIR" +ZAPRET_BASE=${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_BASE/common/base.sh" . "$ZAPRET_BASE/common/elevate.sh" diff --git a/uninstall_easy.sh b/uninstall_easy.sh index 38bcaa0..781c8d5 100755 --- a/uninstall_easy.sh +++ b/uninstall_easy.sh @@ -4,11 +4,18 @@ EXEDIR="$(dirname "$0")" EXEDIR="$(cd "$EXEDIR"; pwd)" -IPSET_DIR="$EXEDIR/ipset" -ZAPRET_CONFIG="$EXEDIR/config" -ZAPRET_BASE="$EXEDIR" +ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"} +ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} +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_BASE/common/base.sh" . "$ZAPRET_BASE/common/elevate.sh"