mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-31 21:59:06 +03:00
updater: Replace wget to curl and other fixes
This commit is contained in:
@@ -32,11 +32,13 @@ return baseclass.extend({
|
|||||||
setStage: function(stage, btn_flag = true) {
|
setStage: function(stage, btn_flag = true) {
|
||||||
if (stage == 0) {
|
if (stage == 0) {
|
||||||
this.btn_action.textContent = _('Check for updates');
|
this.btn_action.textContent = _('Check for updates');
|
||||||
|
this.btn_action.classList.remove('hidden');
|
||||||
} else
|
} else
|
||||||
if (stage == 1) {
|
if (stage == 1) {
|
||||||
this.btn_action.textContent = _('Update packages');
|
this.btn_action.textContent = _('Update packages');
|
||||||
|
this.btn_action.classList.remove('hidden');
|
||||||
} else {
|
} else {
|
||||||
this.btn_action.textContent = _('');
|
this.btn_action.classList.add('hidden');
|
||||||
}
|
}
|
||||||
if (stage > 1 && typeof(this.btn_action) == 'object') {
|
if (stage > 1 && typeof(this.btn_action) == 'object') {
|
||||||
this.setBtnMode(1);
|
this.setBtnMode(1);
|
||||||
@@ -102,10 +104,12 @@ return baseclass.extend({
|
|||||||
}
|
}
|
||||||
let rpc_opt = { timeout: 5*1000 }
|
let rpc_opt = { timeout: 5*1000 }
|
||||||
//rpc_opt.uid = 0; // run under root
|
//rpc_opt.uid = 0; // run under root
|
||||||
const logFile = '/tmp/zapret_pkg_install.log';
|
const x_filename = 'zapret_pkg_install';
|
||||||
const pidFile = '/tmp/zapret_pkg_install.pid';
|
const pidFile = '/tmp/' + x_filename + '.pid';
|
||||||
|
const logFile = '/tmp/' + x_filename + '.log';
|
||||||
|
const errFile = '/tmp/' + x_filename + '.err';
|
||||||
try {
|
try {
|
||||||
await fs.exec('/bin/busybox', [ 'rm', '-f', '/tmp/zapret_pkg_install.*' ], null, rpc_opt);
|
await fs.exec('/bin/busybox', [ 'rm', '-f', '/tmp/' + x_filename + '.*' ], null, rpc_opt);
|
||||||
this.appendLog('Install log cleared.');
|
this.appendLog('Install log cleared.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.appendLog('ERROR: Failed to clear log file');
|
this.appendLog('ERROR: Failed to clear log file');
|
||||||
@@ -114,7 +118,7 @@ return baseclass.extend({
|
|||||||
}
|
}
|
||||||
//console.log(`Start ${fn_update_pkg_sh}...`);
|
//console.log(`Start ${fn_update_pkg_sh}...`);
|
||||||
try {
|
try {
|
||||||
let opt = [ logFile, pidFile, fn_update_pkg_sh ];
|
let opt = [ x_filename, fn_update_pkg_sh ];
|
||||||
//opt.push('-t'); // only for testing
|
//opt.push('-t'); // only for testing
|
||||||
opt.push(...opt_list);
|
opt.push(...opt_list);
|
||||||
await fs.exec('/opt/zapret/script-exec.sh', opt, null, rpc_opt);
|
await fs.exec('/opt/zapret/script-exec.sh', opt, null, rpc_opt);
|
||||||
@@ -157,21 +161,28 @@ return baseclass.extend({
|
|||||||
if (pid > 0 && !alive) {
|
if (pid > 0 && !alive) {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
this.appendLog('\nProcess finished.');
|
this.appendLog('\nProcess finished.');
|
||||||
|
let err_code = -1;
|
||||||
|
try {
|
||||||
|
let err_data = await fs.exec('/bin/cat', [ errFile ], null, rpc_opt);
|
||||||
|
err_code = parseInt(err_data.stdout.trim(), 10);
|
||||||
|
} catch (e) {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
let log = res.stdout;
|
let log = res.stdout;
|
||||||
let code = log.match(/^RESULT:\s*\(([^)]+)\)\s+.+$/m);
|
let code = log.match(/^RESULT:\s*\(([^)]+)\)\s+.+$/m);
|
||||||
if (code && code[1] == '+') {
|
if (code && code[1] == '+') {
|
||||||
this.setStage(999);
|
this.stage = 999;
|
||||||
this.btn_action.textContent = _('OK');
|
this.btn_action.textContent = _('OK');
|
||||||
this.btn_action.disabled = false;
|
this.btn_action.disabled = false;
|
||||||
this.btn_cancel.disabled = true;
|
this.btn_cancel.disabled = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
this.appendLog('ERROR: Install updates failed!');
|
this.appendLog('ERROR: Install updates failed with error ' + err_code);
|
||||||
this.setStage(999);
|
this.setStage(999);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
this.appendLog('ERROR: reading log: ' + e.message);
|
this.appendLog('ERROR: installUpdates: ' + e.message);
|
||||||
this.setStage(999);
|
this.setStage(999);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|||||||
@@ -90,14 +90,28 @@ function get_run_on_boot_option
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_distrib_param
|
||||||
|
{
|
||||||
|
local parname=$1
|
||||||
|
local value="__unknown__"
|
||||||
|
if [ -f /etc/openwrt_release ]; then
|
||||||
|
while IFS='=' read -r key val; do
|
||||||
|
val="${val#\'}"
|
||||||
|
val="${val%\'}"
|
||||||
|
val="${val#\"}"
|
||||||
|
val="${val%\"}"
|
||||||
|
if [ "$key" = "$parname" ]; then
|
||||||
|
value="$val"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done < /etc/openwrt_release
|
||||||
|
fi
|
||||||
|
printf '%s' "$value"
|
||||||
|
}
|
||||||
|
|
||||||
function get_cpu_arch
|
function get_cpu_arch
|
||||||
{
|
{
|
||||||
if [ -f /etc/openwrt_release ]; then
|
get_distrib_param DISTRIB_ARCH
|
||||||
. /etc/openwrt_release
|
|
||||||
printf '%s' "$DISTRIB_ARCH"
|
|
||||||
else
|
|
||||||
printf 'unknown'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore_ipset_txt
|
function restore_ipset_txt
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2024 remittor
|
# Copyright (c) 2024 remittor
|
||||||
LOG_FILE=$1
|
PID_FILE=/tmp/$1.pid
|
||||||
PID_FILE=$2
|
LOG_FILE=/tmp/$1.log
|
||||||
shift 2
|
ERR_FILE=/tmp/$1.err
|
||||||
|
shift 1
|
||||||
: > $LOG_FILE
|
: > $LOG_FILE
|
||||||
|
: > $ERR_FILE
|
||||||
(
|
(
|
||||||
exec </dev/null >/dev/null 2>&1
|
exec </dev/null >/dev/null 2>&1
|
||||||
"$@" >> $LOG_FILE 2>&1
|
"$@" >> $LOG_FILE 2>&1
|
||||||
|
echo $? > "$ERR_FILE"
|
||||||
|
sleep 1
|
||||||
) &
|
) &
|
||||||
echo $! > $PID_FILE
|
echo $! > $PID_FILE
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
. /opt/zapret/comfunc.sh
|
. /opt/zapret/comfunc.sh
|
||||||
. /usr/share/libubox/jshn.sh
|
. /usr/share/libubox/jshn.sh
|
||||||
|
. /etc/openwrt_release
|
||||||
|
|
||||||
opt_check=
|
opt_check=
|
||||||
opt_prerelease=
|
opt_prerelease=
|
||||||
@@ -35,9 +36,9 @@ 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"
|
ZAP_REL_URL="https://raw.githubusercontent.com/remittor/zapret-openwrt/gh-pages/releases/releases_zap1_$ZAP_CPU_ARCH.json"
|
||||||
|
|
||||||
WGET_TIMEOUT=5
|
CURL_TIMEOUT=5
|
||||||
WGET_HEADER1="Accept: application/json"
|
CURL_HEADER1="Accept: application/json"
|
||||||
WGET_HEADER2="Cache-Control: no-cache"
|
CURL_HEADER2="Cache-Control: no-cache"
|
||||||
|
|
||||||
REL_JSON=
|
REL_JSON=
|
||||||
REL_ACTUAL_TAG=
|
REL_ACTUAL_TAG=
|
||||||
@@ -48,13 +49,6 @@ ZAP_OUT=
|
|||||||
ZAP_ERR=
|
ZAP_ERR=
|
||||||
ZAP_PKG_URL=
|
ZAP_PKG_URL=
|
||||||
|
|
||||||
function download_json
|
|
||||||
{
|
|
||||||
local url="$1"
|
|
||||||
wget -q -T "$WGET_TIMEOUT" --header="$WGET_HEADER1" --header="$WGET_HEADER2" -O - "$url"
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
if command -v apk >/dev/null; then
|
if command -v apk >/dev/null; then
|
||||||
PKG_MGR=apk
|
PKG_MGR=apk
|
||||||
ZAP_PKG_EXT=apk
|
ZAP_PKG_EXT=apk
|
||||||
@@ -68,6 +62,13 @@ fi
|
|||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function download_json
|
||||||
|
{
|
||||||
|
local url="$1"
|
||||||
|
curl -s -L --max-time $CURL_TIMEOUT -H "$CURL_HEADER1" -H "$CURL_HEADER2" "$url" 2>/dev/null
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
function get_pkg_version
|
function get_pkg_version
|
||||||
{
|
{
|
||||||
local pkg_name="$1"
|
local pkg_name="$1"
|
||||||
@@ -148,7 +149,6 @@ function download_releases_info
|
|||||||
{
|
{
|
||||||
local txt txtlen txtlines generated_at
|
local txt txtlen txtlines generated_at
|
||||||
REL_JSON=
|
REL_JSON=
|
||||||
echo "CPU arch: $ZAP_CPU_ARCH"
|
|
||||||
echo "Download releases info..."
|
echo "Download releases info..."
|
||||||
txt=$(download_json $ZAP_REL_URL)
|
txt=$(download_json $ZAP_REL_URL)
|
||||||
txtlen=${#txt}
|
txtlen=${#txt}
|
||||||
@@ -229,13 +229,32 @@ function get_actual_release
|
|||||||
|
|
||||||
if [ "$opt_check" != "true" -a "$opt_update" = "" ]; then
|
if [ "$opt_check" != "true" -a "$opt_update" = "" ]; then
|
||||||
echo 'ERROR: Incorrect arguments'
|
echo 'ERROR: Incorrect arguments'
|
||||||
return 1
|
return 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$opt_update" = "@" ]; then
|
if [ "$opt_update" = "@" ]; then
|
||||||
opt_check="true"
|
opt_check="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#echo "DISTRIB_ID: $DISTRIB_ID"
|
||||||
|
echo "DISTRIB_RELEASE: $DISTRIB_RELEASE"
|
||||||
|
echo "DISTRIB_DESCRIPTION:" $(get_distrib_param DISTRIB_DESCRIPTION)
|
||||||
|
echo "DISTRIB_ARCH:" $(get_distrib_param DISTRIB_ARCH)
|
||||||
|
|
||||||
|
if ! command -v curl >/dev/null 2>&1; then
|
||||||
|
echo "ERROR: package \"curl\" not installed!"
|
||||||
|
return 10
|
||||||
|
fi
|
||||||
|
CURL_INFO=$( curl -V )
|
||||||
|
if ! echo "$CURL_INFO" | grep -q 'https'; then
|
||||||
|
echo "------- package curl"
|
||||||
|
echo "$CURL_INFO"
|
||||||
|
echo "-------"
|
||||||
|
echo "ERROR: package \"curl\" not supported HTTPS protocol!"
|
||||||
|
echo "NOTE: Please install package \"curl-ssl\""
|
||||||
|
return 11
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$opt_check" = "true" ]; then
|
if [ "$opt_check" = "true" ]; then
|
||||||
download_releases_info
|
download_releases_info
|
||||||
ZAP_ERR=$?
|
ZAP_ERR=$?
|
||||||
@@ -317,7 +336,8 @@ if [ "$opt_update" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
ZAP_PKG_DIR=/tmp/zapret_pkg
|
ZAP_PKG_DIR=/tmp/zapret_pkg
|
||||||
rm -rf $ZAP_PKG_DIR
|
rm -rf $ZAP_PKG_DIR
|
||||||
ZAP_PKG_SIZE=$( wget --spider -T $WGET_TIMEOUT --header="$WGET_HEADER2" -S "$ZAP_PKG_URL" 2>&1 | grep -i 'Content-Length:' | tail -n1 | awk '{print $2}' | tr -d '\r' )
|
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' )
|
||||||
echo "Downloded ZIP-file size = $ZAP_PKG_SIZE bytes"
|
echo "Downloded ZIP-file size = $ZAP_PKG_SIZE bytes"
|
||||||
[ "$ZAP_PKG_SIZE" = "" ] || [[ $ZAP_PKG_SIZE -lt 256 ]] && {
|
[ "$ZAP_PKG_SIZE" = "" ] || [[ $ZAP_PKG_SIZE -lt 256 ]] && {
|
||||||
echo "ERROR: incorrect package size!"
|
echo "ERROR: incorrect package size!"
|
||||||
@@ -326,14 +346,14 @@ if [ "$opt_update" != "" ]; then
|
|||||||
mkdir $ZAP_PKG_DIR
|
mkdir $ZAP_PKG_DIR
|
||||||
ZAP_PKG_FN="$ZAP_PKG_DIR/${ZAP_PKG_URL##*/}"
|
ZAP_PKG_FN="$ZAP_PKG_DIR/${ZAP_PKG_URL##*/}"
|
||||||
echo "Download ZIP-file..."
|
echo "Download ZIP-file..."
|
||||||
wget -q -T 15 --header="$WGET_HEADER2" -O "$ZAP_PKG_FN" "$ZAP_PKG_URL"
|
curl -s -L --max-time 15 -H "$CURL_HEADER2" "$ZAP_PKG_URL" -o "$ZAP_PKG_FN"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ERROR: cannot download package!"
|
echo "ERROR: cannot download package!"
|
||||||
return 215
|
return 215
|
||||||
fi
|
fi
|
||||||
ZAP_PKG_SZ=$( wc -c < "$ZAP_PKG_FN" )
|
ZAP_PKG_SZ=$( wc -c < "$ZAP_PKG_FN" )
|
||||||
if [ "$ZAP_PKG_SZ" != "$ZAP_PKG_SIZE" ]; then
|
if [ "$ZAP_PKG_SZ" != "$ZAP_PKG_SIZE" ]; then
|
||||||
echo "ERROR: downloaded package is incorrect!"
|
echo "ERROR: downloaded package is incorrect! (size = $ZAP_PKG_SZ)"
|
||||||
return 216
|
return 216
|
||||||
fi
|
fi
|
||||||
unzip -q "$ZAP_PKG_FN" -d $ZAP_PKG_DIR
|
unzip -q "$ZAP_PKG_FN" -d $ZAP_PKG_DIR
|
||||||
@@ -384,5 +404,4 @@ if [ "$opt_update" != "" ]; then
|
|||||||
return 247
|
return 247
|
||||||
fi
|
fi
|
||||||
echo "RESULT: (+) Packages from $ZAP_PKG_ZIP_NAME successfully installed!"
|
echo "RESULT: (+) Packages from $ZAP_PKG_ZIP_NAME successfully installed!"
|
||||||
sleep 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user