mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-30 22:30:36 +03:00
zapret: Global use of dynamic variables
This commit is contained in:
@@ -7,13 +7,16 @@ ZAPRET_BASE=/opt/zapret
|
|||||||
ZAPRET_INITD=/etc/init.d/zapret
|
ZAPRET_INITD=/etc/init.d/zapret
|
||||||
ZAPRET_ORIG_INITD="$ZAPRET_BASE/init.d/openwrt/zapret"
|
ZAPRET_ORIG_INITD="$ZAPRET_BASE/init.d/openwrt/zapret"
|
||||||
|
|
||||||
|
ZAP_LOG_TAG=ZAPRET
|
||||||
|
|
||||||
ZAPRET_CONFIG="$ZAPRET_BASE/config"
|
ZAPRET_CONFIG="$ZAPRET_BASE/config"
|
||||||
ZAPRET_CONFIG_NEW="$ZAPRET_BASE/config.new"
|
ZAPRET_CONFIG_NEW="$ZAPRET_BASE/config.new"
|
||||||
ZAPRET_CONFIG_DEF="$ZAPRET_BASE/config.default"
|
ZAPRET_CONFIG_DEF="$ZAPRET_BASE/config.default"
|
||||||
|
|
||||||
ZAPRET_CFG=/etc/config/zapret
|
ZAPRET_CFG=/etc/config/zapret
|
||||||
ZAPRET_CFG_NAME=zapret
|
ZAPRET_CFG_NAME=zapret
|
||||||
ZAPRET_CFG_SEC_NAME="$( uci -q get $ZAPRET_CFG_NAME.config )"
|
ZAPRET_CFG_SEC=$ZAPRET_CFG_NAME.config
|
||||||
|
ZAPRET_CFG_SEC_NAME="$( uci -q get $ZAPRET_CFG_SEC )"
|
||||||
|
|
||||||
. $ZAPRET_BASE/def-cfg.sh
|
. $ZAPRET_BASE/def-cfg.sh
|
||||||
|
|
||||||
@@ -148,7 +151,7 @@ function merge_cfg_with_def_values
|
|||||||
local cfgname=${1:-$ZAPRET_CFG_NAME}
|
local cfgname=${1:-$ZAPRET_CFG_NAME}
|
||||||
local force=$2
|
local force=$2
|
||||||
local cfgfile=/etc/config/$cfgname
|
local cfgfile=/etc/config/$cfgname
|
||||||
local NEWCFGNAME="zapret-default"
|
local NEWCFGNAME="$ZAPRET_CFG_NAME-default"
|
||||||
local NEWCFGFILE="/etc/config/$NEWCFGNAME"
|
local NEWCFGFILE="/etc/config/$NEWCFGNAME"
|
||||||
|
|
||||||
local cfg_sec_name="$( uci -q get $ZAPRET_CFG_NAME.config )"
|
local cfg_sec_name="$( uci -q get $ZAPRET_CFG_NAME.config )"
|
||||||
@@ -168,7 +171,7 @@ function merge_cfg_with_def_values
|
|||||||
function remove_cron_task_logs
|
function remove_cron_task_logs
|
||||||
{
|
{
|
||||||
if [ -f "$CRONTAB_FILE" ]; then
|
if [ -f "$CRONTAB_FILE" ]; then
|
||||||
sed -i "/-name 'zapret+\*.log' -size +/d" "$CRONTAB_FILE"
|
sed -i "/-name '$ZAPRET_CFG_NAME+\*.log' -size +/d" "$CRONTAB_FILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +179,8 @@ function insert_cron_task_logs
|
|||||||
{
|
{
|
||||||
[ ! -f "$CRONTAB_FILE" ] && touch "$CRONTAB_FILE"
|
[ ! -f "$CRONTAB_FILE" ] && touch "$CRONTAB_FILE"
|
||||||
[ ! -f "$CRONTAB_FILE" ] && return 1
|
[ ! -f "$CRONTAB_FILE" ] && return 1
|
||||||
if ! grep -q -e "-name 'zapret\*\.log' -size \+" "$CRONTAB_FILE"; then
|
if ! grep -q -e "-name '$ZAPRET_CFG_NAME\*\.log' -size \+" "$CRONTAB_FILE"; then
|
||||||
echo "*/2 * * * * /usr/bin/find /tmp -maxdepth 1 -type f -name 'zapret+*.log' -size +2600k -exec rm -f {} \;" >> "$CRONTAB_FILE"
|
echo "*/2 * * * * /usr/bin/find /tmp -maxdepth 1 -type f -name '$ZAPRET_CFG_NAME+*.log' -size +2600k -exec rm -f {} \;" >> "$CRONTAB_FILE"
|
||||||
/etc/init.d/cron restart 2> /dev/null
|
/etc/init.d/cron restart 2> /dev/null
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
@@ -190,7 +193,7 @@ function init_before_start
|
|||||||
[ ! -f "$HOSTLIST_FN" ] && touch "$HOSTLIST_FN"
|
[ ! -f "$HOSTLIST_FN" ] && touch "$HOSTLIST_FN"
|
||||||
chmod 644 $ZAPRET_BASE/ipset/*.txt
|
chmod 644 $ZAPRET_BASE/ipset/*.txt
|
||||||
chmod 666 $ZAPRET_BASE/ipset/*.log
|
chmod 666 $ZAPRET_BASE/ipset/*.log
|
||||||
rm -f /tmp/zapret+*.log
|
rm -f /tmp/$ZAPRET_CFG_NAME+*.log
|
||||||
#*/
|
#*/
|
||||||
if [ "$DAEMON_LOG_ENABLE" = "1" ]; then
|
if [ "$DAEMON_LOG_ENABLE" = "1" ]; then
|
||||||
insert_cron_task_logs
|
insert_cron_task_logs
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ SCRIPT_FILENAME=$1
|
|||||||
. /opt/zapret/comfunc.sh
|
. /opt/zapret/comfunc.sh
|
||||||
|
|
||||||
if ! is_valid_config ; then
|
if ! is_valid_config ; then
|
||||||
logger -p err -t ZAPRET "Wrong main config: $ZAPRET_CONFIG"
|
logger -p err -t $ZAP_LOG_TAG "Wrong main config: $ZAPRET_CONFIG"
|
||||||
exit 91
|
exit 91
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. $ZAPRET_ORIG_INITD
|
. $ZAPRET_ORIG_INITD
|
||||||
|
|
||||||
EXEDIR=/opt/zapret
|
EXEDIR=/opt/$ZAPRET_CFG_NAME
|
||||||
ZAPRET_BASE=/opt/zapret
|
ZAPRET_BASE=/opt/$ZAPRET_CFG_NAME
|
||||||
|
|
||||||
is_run_on_boot && IS_RUN_ON_BOOT=1 || IS_RUN_ON_BOOT=0
|
is_run_on_boot && IS_RUN_ON_BOOT=1 || IS_RUN_ON_BOOT=0
|
||||||
|
|
||||||
@@ -30,13 +30,13 @@ function enable
|
|||||||
if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then
|
if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then
|
||||||
run_on_boot=$( get_run_on_boot_option )
|
run_on_boot=$( get_run_on_boot_option )
|
||||||
if [ $run_on_boot != 1 ]; then
|
if [ $run_on_boot != 1 ]; then
|
||||||
logger -p notice -t ZAPRET "Attempt to enable service, but service blocked!"
|
logger -p notice -t $ZAP_LOG_TAG "Attempt to enable service, but service blocked!"
|
||||||
return 61
|
return 61
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then
|
if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then
|
||||||
uci set $ZAPRET_CFG_NAME.config.run_on_boot=1
|
uci set $ZAPRET_CFG_SEC.run_on_boot=1
|
||||||
uci commit
|
uci commit
|
||||||
fi
|
fi
|
||||||
/bin/sh /etc/rc.common $ZAPRET_ORIG_INITD enable
|
/bin/sh /etc/rc.common $ZAPRET_ORIG_INITD enable
|
||||||
@@ -49,7 +49,7 @@ function enabled
|
|||||||
run_on_boot=$( get_run_on_boot_option )
|
run_on_boot=$( get_run_on_boot_option )
|
||||||
if [ $run_on_boot != 1 ]; then
|
if [ $run_on_boot != 1 ]; then
|
||||||
if [ "$IS_RUN_ON_BOOT" = "1" ]; then
|
if [ "$IS_RUN_ON_BOOT" = "1" ]; then
|
||||||
logger -p notice -t ZAPRET "Service is blocked!"
|
logger -p notice -t $ZAP_LOG_TAG "Service is blocked!"
|
||||||
fi
|
fi
|
||||||
return 61
|
return 61
|
||||||
fi
|
fi
|
||||||
@@ -65,7 +65,7 @@ function boot
|
|||||||
if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then
|
if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then
|
||||||
run_on_boot=$( get_run_on_boot_option )
|
run_on_boot=$( get_run_on_boot_option )
|
||||||
if [ $run_on_boot != 1 ]; then
|
if [ $run_on_boot != 1 ]; then
|
||||||
logger -p notice -t ZAPRET "Attempt to run service on boot! Service is blocked!"
|
logger -p notice -t $ZAP_LOG_TAG "Attempt to run service on boot! Service is blocked!"
|
||||||
return 61
|
return 61
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2024 remittor
|
# Copyright (c) 2024 remittor
|
||||||
|
|
||||||
. /opt/zapret/comfunc.sh
|
EXE_DIR=$(cd "$(dirname "$0")" 2>/dev/null || exit 1; pwd)
|
||||||
|
|
||||||
|
. $EXE_DIR/comfunc.sh
|
||||||
|
|
||||||
merge_cfg_with_def_values
|
merge_cfg_with_def_values
|
||||||
|
|
||||||
@@ -12,5 +14,5 @@ CONFIGS_SYNC=0
|
|||||||
|
|
||||||
if [ "$CONFIGS_SYNC" = "1" ]; then
|
if [ "$CONFIGS_SYNC" = "1" ]; then
|
||||||
# renew main config
|
# renew main config
|
||||||
/opt/zapret/sync_config.sh
|
$ZAPRET_BASE/sync_config.sh
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2024 remittor
|
# Copyright (c) 2024 remittor
|
||||||
|
|
||||||
. /opt/zapret/comfunc.sh
|
EXE_DIR=$(cd "$(dirname "$0")" 2>/dev/null || exit 1; pwd)
|
||||||
|
|
||||||
cfg_run_on_boot="$( uci -q get zapret.config.run_on_boot )"
|
. $EXE_DIR/comfunc.sh
|
||||||
|
|
||||||
|
cfg_run_on_boot="$( uci -q get $ZAPRET_CFG_SEC.run_on_boot )"
|
||||||
|
|
||||||
opt_flags=${1:--}
|
opt_flags=${1:--}
|
||||||
opt_strat=$2
|
opt_strat=$2
|
||||||
@@ -15,7 +17,7 @@ fi
|
|||||||
create_default_cfg "$opt_flags" "$opt_strat"
|
create_default_cfg "$opt_flags" "$opt_strat"
|
||||||
|
|
||||||
if [ "$cfg_run_on_boot" = "1" ]; then
|
if [ "$cfg_run_on_boot" = "1" ]; then
|
||||||
uci set zapret.config.run_on_boot=1
|
uci set $ZAPRET_CFG_SEC.run_on_boot=1
|
||||||
uci commit
|
uci commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -29,5 +31,5 @@ fi
|
|||||||
|
|
||||||
if [ "$ZAPRET_SYNC_CONFIG" = "1" ]; then
|
if [ "$ZAPRET_SYNC_CONFIG" = "1" ]; then
|
||||||
# renew main config
|
# renew main config
|
||||||
/opt/zapret/sync_config.sh
|
$ZAPRET_BASE/sync_config.sh
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2024 remittor
|
# Copyright (c) 2024 remittor
|
||||||
|
|
||||||
. /opt/zapret/comfunc.sh
|
EXE_DIR=$(cd "$(dirname "$0")" 2>/dev/null || exit 1; pwd)
|
||||||
|
|
||||||
|
. $EXE_DIR/comfunc.sh
|
||||||
|
|
||||||
function uncomment_param
|
function uncomment_param
|
||||||
{
|
{
|
||||||
@@ -41,7 +43,7 @@ function sync_param
|
|||||||
{
|
{
|
||||||
local param=$1
|
local param=$1
|
||||||
local vtype=$2
|
local vtype=$2
|
||||||
local value="$( uci -q get zapret.config.$param )"
|
local value="$( uci -q get $ZAPRET_CFG_SEC.$param )"
|
||||||
uncomment_param $param
|
uncomment_param $param
|
||||||
append_param $param
|
append_param $param
|
||||||
local TAB="$( echo -n -e '\t' )"
|
local TAB="$( echo -n -e '\t' )"
|
||||||
@@ -51,9 +53,15 @@ function sync_param
|
|||||||
if [ "$param" = "NFQWS_PORTS_TCP_KEEPALIVE" -o "$param" = "NFQWS_PORTS_UDP_KEEPALIVE" ]; then
|
if [ "$param" = "NFQWS_PORTS_TCP_KEEPALIVE" -o "$param" = "NFQWS_PORTS_UDP_KEEPALIVE" ]; then
|
||||||
[ "$value" = "0" ] && value=""
|
[ "$value" = "0" ] && value=""
|
||||||
fi
|
fi
|
||||||
|
if [ "$param" = "NFQWS2_PORTS_TCP_KEEPALIVE" -o "$param" = "NFQWS2_PORTS_UDP_KEEPALIVE" ]; then
|
||||||
|
[ "$value" = "0" ] && value=""
|
||||||
|
fi
|
||||||
if [ "$param" = "NFQWS_OPT" -a "$value" != "" ]; then
|
if [ "$param" = "NFQWS_OPT" -a "$value" != "" ]; then
|
||||||
value=$( echo -n "$value" | sed '/^#/d' )
|
value=$( echo -n "$value" | sed '/^#/d' )
|
||||||
fi
|
fi
|
||||||
|
if [ "$param" = "NFQWS2_OPT" -a "$value" != "" ]; then
|
||||||
|
value=$( echo -n "$value" | sed '/^#/d' )
|
||||||
|
fi
|
||||||
if [ "$vtype" = "str" ]; then
|
if [ "$vtype" = "str" ]; then
|
||||||
set_param_value_str $param "$value"
|
set_param_value_str $param "$value"
|
||||||
else
|
else
|
||||||
@@ -90,21 +98,42 @@ sync_param DAEMON_LOG_FILE str
|
|||||||
sync_param AUTOHOSTLIST_RETRANS_THRESHOLD
|
sync_param AUTOHOSTLIST_RETRANS_THRESHOLD
|
||||||
sync_param AUTOHOSTLIST_FAIL_THRESHOLD
|
sync_param AUTOHOSTLIST_FAIL_THRESHOLD
|
||||||
sync_param AUTOHOSTLIST_FAIL_TIME
|
sync_param AUTOHOSTLIST_FAIL_TIME
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret2" ]; then
|
||||||
|
sync_param AUTOHOSTLIST_INCOMING_MAXSEQ
|
||||||
|
sync_param AUTOHOSTLIST_RETRANS_MAXSEQ
|
||||||
|
sync_param AUTOHOSTLIST_UDP_IN
|
||||||
|
sync_param AUTOHOSTLIST_UDP_OUT
|
||||||
|
fi
|
||||||
sync_param AUTOHOSTLIST_DEBUGLOG
|
sync_param AUTOHOSTLIST_DEBUGLOG
|
||||||
|
|
||||||
sync_param NFQWS_ENABLE
|
|
||||||
sync_param DESYNC_MARK
|
sync_param DESYNC_MARK
|
||||||
sync_param DESYNC_MARK_POSTNAT
|
sync_param DESYNC_MARK_POSTNAT
|
||||||
sync_param FILTER_MARK str
|
sync_param FILTER_MARK str
|
||||||
sync_param NFQWS_PORTS_TCP str
|
|
||||||
sync_param NFQWS_PORTS_UDP str
|
if [ $ZAPRET_CFG_NAME = "zapret" ]; then
|
||||||
sync_param NFQWS_TCP_PKT_OUT str
|
sync_param NFQWS_ENABLE
|
||||||
sync_param NFQWS_TCP_PKT_IN str
|
sync_param NFQWS_PORTS_TCP str
|
||||||
sync_param NFQWS_UDP_PKT_OUT str
|
sync_param NFQWS_PORTS_UDP str
|
||||||
sync_param NFQWS_UDP_PKT_IN str
|
sync_param NFQWS_TCP_PKT_OUT str
|
||||||
sync_param NFQWS_PORTS_TCP_KEEPALIVE str
|
sync_param NFQWS_TCP_PKT_IN str
|
||||||
sync_param NFQWS_PORTS_UDP_KEEPALIVE str
|
sync_param NFQWS_UDP_PKT_OUT str
|
||||||
sync_param NFQWS_OPT str
|
sync_param NFQWS_UDP_PKT_IN str
|
||||||
|
sync_param NFQWS_PORTS_TCP_KEEPALIVE str
|
||||||
|
sync_param NFQWS_PORTS_UDP_KEEPALIVE str
|
||||||
|
sync_param NFQWS_OPT str
|
||||||
|
fi
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret2" ]; then
|
||||||
|
sync_param NFQWS2_ENABLE
|
||||||
|
sync_param NFQWS2_PORTS_TCP str
|
||||||
|
sync_param NFQWS2_PORTS_UDP str
|
||||||
|
sync_param NFQWS2_TCP_PKT_OUT str
|
||||||
|
sync_param NFQWS2_TCP_PKT_IN str
|
||||||
|
sync_param NFQWS2_UDP_PKT_OUT str
|
||||||
|
sync_param NFQWS2_UDP_PKT_IN str
|
||||||
|
sync_param NFQWS2_PORTS_TCP_KEEPALIVE str
|
||||||
|
sync_param NFQWS2_PORTS_UDP_KEEPALIVE str
|
||||||
|
sync_param NFQWS2_OPT str
|
||||||
|
fi
|
||||||
|
|
||||||
ZAPRET_CONFIG="$ZAPRET_CONFIG__SAVED"
|
ZAPRET_CONFIG="$ZAPRET_CONFIG__SAVED"
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@
|
|||||||
. /opt/zapret/comfunc.sh
|
. /opt/zapret/comfunc.sh
|
||||||
|
|
||||||
# create empty txt files into ipset directory
|
# create empty txt files into ipset directory
|
||||||
[ ! -f "/opt/zapret/ipset/zapret-hosts-google.txt" ] && touch "/opt/zapret/ipset/zapret-hosts-google.txt"
|
[ ! -f "$ZAPRET_BASE/ipset/zapret-hosts-google.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-hosts-google.txt"
|
||||||
#[ ! -f "/opt/zapret/ipset/zapret-hosts-auto.txt" ] && touch "/opt/zapret/ipset/zapret-hosts-auto.txt"
|
#[ ! -f "$ZAPRET_BASE/ipset/zapret-hosts-auto.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-hosts-auto.txt"
|
||||||
[ ! -f "/opt/zapret/ipset/zapret-hosts-user.txt" ] && touch "/opt/zapret/ipset/zapret-hosts-user.txt"
|
[ ! -f "$ZAPRET_BASE/ipset/zapret-hosts-user.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-hosts-user.txt"
|
||||||
[ ! -f "/opt/zapret/ipset/zapret-hosts-user-ipban.txt" ] && touch "/opt/zapret/ipset/zapret-hosts-user-ipban.txt"
|
[ ! -f "$ZAPRET_BASE/ipset/zapret-hosts-user-ipban.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-hosts-user-ipban.txt"
|
||||||
#[ ! -f "/opt/zapret/ipset/zapret-ip.txt" ] && touch "/opt/zapret/ipset/zapret-ip.txt"
|
#[ ! -f "$ZAPRET_BASE/ipset/zapret-ip.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-ip.txt"
|
||||||
[ ! -f "/opt/zapret/ipset/zapret-ip-user.txt" ] && touch "/opt/zapret/ipset/zapret-ip-user.txt"
|
[ ! -f "$ZAPRET_BASE/ipset/zapret-ip-user.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-ip-user.txt"
|
||||||
[ ! -f "/opt/zapret/ipset/zapret-ip-user-exclude.txt" ] && touch "/opt/zapret/ipset/zapret-ip-user-exclude.txt"
|
[ ! -f "$ZAPRET_BASE/ipset/zapret-ip-user-exclude.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-ip-user-exclude.txt"
|
||||||
[ ! -f "/opt/zapret/ipset/zapret-ip-user-ipban.txt" ] && touch "/opt/zapret/ipset/zapret-ip-user-ipban.txt"
|
[ ! -f "$ZAPRET_BASE/ipset/zapret-ip-user-ipban.txt" ] && touch "$ZAPRET_BASE/ipset/zapret-ip-user-ipban.txt"
|
||||||
|
|
||||||
# create or merge uci-config
|
# create or merge uci-config
|
||||||
$ZAPRET_BASE/renew-cfg.sh
|
$ZAPRET_BASE/renew-cfg.sh
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2025 remittor
|
# Copyright (c) 2025 remittor
|
||||||
|
|
||||||
. /opt/zapret/comfunc.sh
|
EXE_DIR=$(cd "$(dirname "$0")" 2>/dev/null || exit 1; pwd)
|
||||||
|
|
||||||
|
. $EXE_DIR/comfunc.sh
|
||||||
. /usr/share/libubox/jshn.sh
|
. /usr/share/libubox/jshn.sh
|
||||||
. /etc/openwrt_release
|
. /etc/openwrt_release
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ while getopts "cu:pft:" opt; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
ZAP_PKG_DIR=/tmp/zapret_pkg
|
ZAP_PKG_DIR=/tmp/$ZAPRET_CFG_NAME-pkg
|
||||||
|
|
||||||
if [ "$opt_test" != "" ]; then
|
if [ "$opt_test" != "" ]; then
|
||||||
echo 1; sleep 2;
|
echo 1; sleep 2;
|
||||||
@@ -34,8 +36,13 @@ if [ "$opt_test" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
ZAP_CPU_ARCH=$(get_cpu_arch)
|
ZAP_CPU_ARCH=$(get_cpu_arch)
|
||||||
ZAP_REL_URL="https://raw.githubusercontent.com/remittor/zapret-openwrt/gh-pages/releases/releases_zap1_$ZAP_CPU_ARCH.json"
|
|
||||||
|
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret" ]; then
|
||||||
|
ZAP_REL_URL="https://raw.githubusercontent.com/remittor/zapret-openwrt/gh-pages/releases/releases_zap1_$ZAP_CPU_ARCH.json"
|
||||||
|
fi
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret2" ]; then
|
||||||
|
ZAP_REL_URL="https://raw.githubusercontent.com/remittor/zapret-openwrt/gh-pages/releases/releases_zap2_$ZAP_CPU_ARCH.json"
|
||||||
|
fi
|
||||||
CURL_TIMEOUT=5
|
CURL_TIMEOUT=5
|
||||||
CURL_HEADER1="Accept: application/json"
|
CURL_HEADER1="Accept: application/json"
|
||||||
CURL_HEADER2="Cache-Control: no-cache"
|
CURL_HEADER2="Cache-Control: no-cache"
|
||||||
@@ -104,7 +111,8 @@ function normalize_version
|
|||||||
{
|
{
|
||||||
local ver="$1"
|
local ver="$1"
|
||||||
local base
|
local base
|
||||||
local major minor rel
|
local major minor build rel
|
||||||
|
local old_ifs
|
||||||
case "$ver" in
|
case "$ver" in
|
||||||
*-r[0-9]*)
|
*-r[0-9]*)
|
||||||
rel="${ver##*-r}"
|
rel="${ver##*-r}"
|
||||||
@@ -115,11 +123,17 @@ function normalize_version
|
|||||||
base="$ver"
|
base="$ver"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
major="${base%%.*}"
|
old_ifs="$IFS" ; IFS='.' ; set -- $base ; IFS="$old_ifs"
|
||||||
minor="${base#*.}"
|
rel=${rel:-1}
|
||||||
[ -z "$minor" ] && minor=0
|
major=${1:-0}
|
||||||
[ -z "$rel" ] && rel=1
|
minor=${2:-0}
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret" ]; then
|
||||||
echo "$major.$minor.$rel"
|
echo "$major.$minor.$rel"
|
||||||
|
fi
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret2" ]; then
|
||||||
|
build=${3:-0}
|
||||||
|
echo "$major.$minor.$build.$rel"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function pkg_version_cmp
|
function pkg_version_cmp
|
||||||
@@ -137,11 +151,24 @@ function pkg_version_cmp
|
|||||||
x2=$( echo "$ver2" | cut -d. -f2 )
|
x2=$( echo "$ver2" | cut -d. -f2 )
|
||||||
[ "$x1" -gt "$x2" ] && { echo -n "G"; return 0; }
|
[ "$x1" -gt "$x2" ] && { echo -n "G"; return 0; }
|
||||||
[ "$x1" -lt "$x2" ] && { echo -n "L"; return 0; }
|
[ "$x1" -lt "$x2" ] && { echo -n "L"; return 0; }
|
||||||
# release
|
if [ $ZAPRET_CFG_NAME = "zapret2" ]; then
|
||||||
|
# build
|
||||||
x1=$( echo "$ver1" | cut -d. -f3 )
|
x1=$( echo "$ver1" | cut -d. -f3 )
|
||||||
x2=$( echo "$ver2" | cut -d. -f3 )
|
x2=$( echo "$ver2" | cut -d. -f3 )
|
||||||
[ "$x1" -gt "$x2" ] && { echo -n "G"; return 0; }
|
[ "$x1" -gt "$x2" ] && { echo -n "G"; return 0; }
|
||||||
[ "$x1" -lt "$x2" ] && { echo -n "L"; return 0; }
|
[ "$x1" -lt "$x2" ] && { echo -n "L"; return 0; }
|
||||||
|
fi
|
||||||
|
# release
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret" ]; then
|
||||||
|
x1=$( echo "$ver1" | cut -d. -f3 )
|
||||||
|
x2=$( echo "$ver2" | cut -d. -f3 )
|
||||||
|
fi
|
||||||
|
if [ $ZAPRET_CFG_NAME = "zapret2" ]; then
|
||||||
|
x1=$( echo "$ver1" | cut -d. -f4 )
|
||||||
|
x2=$( echo "$ver2" | cut -d. -f4 )
|
||||||
|
fi
|
||||||
|
[ "$x1" -gt "$x2" ] && { echo -n "G"; return 0; }
|
||||||
|
[ "$x1" -lt "$x2" ] && { echo -n "L"; return 0; }
|
||||||
echo -n "E"
|
echo -n "E"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +316,7 @@ ZAP_PKG_FN=
|
|||||||
ZAP_PKG_BASE_FN=
|
ZAP_PKG_BASE_FN=
|
||||||
ZAP_PKG_LUCI_FN=
|
ZAP_PKG_LUCI_FN=
|
||||||
|
|
||||||
ZAP_CUR_PKG_VER=$( get_pkg_version zapret )
|
ZAP_CUR_PKG_VER=$( get_pkg_version $ZAPRET_CFG_NAME )
|
||||||
echo "Current installed version: $ZAP_CUR_PKG_VER"
|
echo "Current installed version: $ZAP_CUR_PKG_VER"
|
||||||
|
|
||||||
if [ "$opt_update" = "" ]; then
|
if [ "$opt_update" = "" ]; then
|
||||||
@@ -344,7 +371,7 @@ if [ "$opt_update" != "" ]; then
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
ZAP_PKG_DIR=/tmp/zapret_pkg
|
ZAP_PKG_DIR=/tmp/$ZAPRET_CFG_NAME-pkg
|
||||||
rm -rf $ZAP_PKG_DIR 2>/dev/null
|
rm -rf $ZAP_PKG_DIR 2>/dev/null
|
||||||
ZAP_PKG_HDRS=$( curl -s -I -L --max-time $CURL_TIMEOUT -H "$CURL_HEADER2" "$ZAP_PKG_URL" )
|
ZAP_PKG_HDRS=$( curl -s -I -L --max-time $CURL_TIMEOUT -H "$CURL_HEADER2" "$ZAP_PKG_URL" )
|
||||||
ZAP_PKG_SIZE=$( echo "$ZAP_PKG_HDRS" | grep -i 'content-length: ' | tail -n1 | awk '{print $2}' | tr -d '\r' )
|
ZAP_PKG_SIZE=$( echo "$ZAP_PKG_HDRS" | grep -i 'content-length: ' | tail -n1 | awk '{print $2}' | tr -d '\r' )
|
||||||
@@ -387,18 +414,18 @@ if [ "$opt_update" != "" ]; then
|
|||||||
echo "$ZAP_PKG_LIST"
|
echo "$ZAP_PKG_LIST"
|
||||||
echo "------"
|
echo "------"
|
||||||
if [ "$PKG_MGR" != "apk" ]; then
|
if [ "$PKG_MGR" != "apk" ]; then
|
||||||
ZAP_PKG_BASE_FN=$( find "$ZAP_PKG_DIR" -maxdepth 1 -type f -name "zapret_*.${ZAP_PKG_EXT}" | head -n 1 )
|
ZAP_PKG_BASE_FN=$( find "$ZAP_PKG_DIR" -maxdepth 1 -type f -name "${ZAPRET_CFG_NAME}_*.${ZAP_PKG_EXT}" | head -n 1 )
|
||||||
else
|
else
|
||||||
ZAP_PKG_BASE_FN=$( find "$ZAP_PKG_DIR" -maxdepth 1 -type f -name "zapret-[0-9]*.?*.${ZAP_PKG_EXT}" | head -n 1 )
|
ZAP_PKG_BASE_FN=$( find "$ZAP_PKG_DIR" -maxdepth 1 -type f -name "${ZAPRET_CFG_NAME}-[0-9]*.?*.${ZAP_PKG_EXT}" | head -n 1 )
|
||||||
fi
|
fi
|
||||||
ZAP_PKG_LUCI_FN=$( find "$ZAP_PKG_DIR" -maxdepth 1 -type f -name "luci-app-zapret*.${ZAP_PKG_EXT}" | head -n 1 )
|
ZAP_PKG_LUCI_FN=$( find "$ZAP_PKG_DIR" -maxdepth 1 -type f -name "luci-app-${ZAPRET_CFG_NAME}*.${ZAP_PKG_EXT}" | head -n 1 )
|
||||||
if [ ! -f "$ZAP_PKG_BASE_FN" ]; then
|
if [ ! -f "$ZAP_PKG_BASE_FN" ]; then
|
||||||
echo "ERROR: File \"zapret*.${ZAP_PKG_EXT}\" not found!"
|
echo "ERROR: File \"${ZAPRET_CFG_NAME}*.${ZAP_PKG_EXT}\" not found!"
|
||||||
return 231
|
return 231
|
||||||
fi
|
fi
|
||||||
echo "ZAP_PKG_BASE_FN = $ZAP_PKG_BASE_FN"
|
echo "ZAP_PKG_BASE_FN = $ZAP_PKG_BASE_FN"
|
||||||
if [ ! -f "$ZAP_PKG_LUCI_FN" ]; then
|
if [ ! -f "$ZAP_PKG_LUCI_FN" ]; then
|
||||||
echo "ERROR: File \"luci-app-zapret*.${ZAP_PKG_EXT}\" not found!"
|
echo "ERROR: File \"luci-app-${ZAPRET_CFG_NAME}*.${ZAP_PKG_EXT}\" not found!"
|
||||||
return 232
|
return 232
|
||||||
fi
|
fi
|
||||||
echo "ZAP_PKG_LUCI_FN = $ZAP_PKG_LUCI_FN"
|
echo "ZAP_PKG_LUCI_FN = $ZAP_PKG_LUCI_FN"
|
||||||
|
|||||||
Reference in New Issue
Block a user