mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-27 12:50:35 +03:00
updater: Add support install packages on clean OpenWrt
Example: ./update-pkg.sh -u 1 Example: ./update-pkg.sh -u 2
This commit is contained in:
@@ -3,10 +3,6 @@
|
|||||||
|
|
||||||
EXE_DIR=$(cd "$(dirname "$0")" 2>/dev/null || exit 1; pwd)
|
EXE_DIR=$(cd "$(dirname "$0")" 2>/dev/null || exit 1; pwd)
|
||||||
|
|
||||||
. $EXE_DIR/comfunc.sh
|
|
||||||
. /usr/share/libubox/jshn.sh
|
|
||||||
. /etc/openwrt_release
|
|
||||||
|
|
||||||
opt_check=
|
opt_check=
|
||||||
opt_prerelease=
|
opt_prerelease=
|
||||||
opt_update=
|
opt_update=
|
||||||
@@ -16,13 +12,33 @@ opt_test=
|
|||||||
while getopts "cu:pft:" opt; do
|
while getopts "cu:pft:" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
c) opt_check=true;;
|
c) opt_check=true;;
|
||||||
p) opt_prerelease=true;;
|
p) opt_prerelease="true";;
|
||||||
u) opt_update="$OPTARG";;
|
u) opt_update="$OPTARG";;
|
||||||
f) opt_forced=true;;
|
f) opt_forced="true";;
|
||||||
t) opt_test="$OPTARG";;
|
t) opt_test="$OPTARG";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$EXE_DIR" = "/tmp" ]; then
|
||||||
|
ZAPRET_CFG_NAME="zapret"
|
||||||
|
if [ "$opt_update" = "1" ]; then
|
||||||
|
ZAPRET_CFG_NAME="zapret"
|
||||||
|
opt_update="@"
|
||||||
|
opt_forced="true"
|
||||||
|
fi
|
||||||
|
if [ "$opt_update" = "2" ]; then
|
||||||
|
ZAPRET_CFG_NAME="zapret2"
|
||||||
|
opt_update="@"
|
||||||
|
opt_forced="true"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
[ -f "$EXE_DIR/comfunc.sh" ] || { echo "ERROR: file $EXE_DIR/comfunc.sh not founded!"; exit 1; }
|
||||||
|
. $EXE_DIR/comfunc.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
. /etc/openwrt_release
|
||||||
|
|
||||||
ZAP_PKG_DIR=/tmp/$ZAPRET_CFG_NAME-pkg
|
ZAP_PKG_DIR=/tmp/$ZAPRET_CFG_NAME-pkg
|
||||||
|
|
||||||
if [ "$opt_test" != "" ]; then
|
if [ "$opt_test" != "" ]; then
|
||||||
@@ -35,7 +51,7 @@ if [ "$opt_test" != "" ]; then
|
|||||||
return "$opt_test"
|
return "$opt_test"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ZAP_CPU_ARCH=$(get_cpu_arch)
|
ZAP_CPU_ARCH="$DISTRIB_ARCH"
|
||||||
|
|
||||||
if [ $ZAPRET_CFG_NAME = "zapret" ]; then
|
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"
|
ZAP_REL_URL="https://raw.githubusercontent.com/remittor/zapret-openwrt/gh-pages/releases/releases_zap1_$ZAP_CPU_ARCH.json"
|
||||||
@@ -69,11 +85,73 @@ fi
|
|||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function download_json
|
function get_distrib_param
|
||||||
{
|
{
|
||||||
local url="$1"
|
local parname=$1
|
||||||
curl -s -L --max-time $CURL_TIMEOUT -H "$CURL_HEADER1" -H "$CURL_HEADER2" "$url" 2>/dev/null
|
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 pkg_mgr_update
|
||||||
|
{
|
||||||
|
local forced=$1
|
||||||
|
if [ "$PKG_MGR" = "opkg" ]; then
|
||||||
|
PKG_TOTAL=$( opkg list | wc -l )
|
||||||
|
PKG_INSTALLED=$( opkg list-installed | wc -l )
|
||||||
|
if [ "$PKG_TOTAL" = "$PKG_INSTALLED" ]; then
|
||||||
|
echo ">>> OPKG update..."
|
||||||
|
opkg update
|
||||||
return $?
|
return $?
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
PKG_AVAIL=$( apk list --available 2>/dev/null | wc -l )
|
||||||
|
if [ "$PKG_AVAIL" -lt 100 ]; then
|
||||||
|
echo ">>> APK update..."
|
||||||
|
apk update
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function curl_install
|
||||||
|
{
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
pkg_mgr_update || { echo "ERROR: cannot update packages list"; return 1; }
|
||||||
|
echo ">>> Package curl not found, installing..."
|
||||||
|
if [ "$PKG_MGR" = "opkg" ]; then
|
||||||
|
opkg install curl
|
||||||
|
else
|
||||||
|
apk add curl
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function unzip_install
|
||||||
|
{
|
||||||
|
if command -v unzip >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
pkg_mgr_update || { echo "ERROR: cannot update packages list"; return 1; }
|
||||||
|
echo ">>> Package unzip not found, installing..."
|
||||||
|
if [ "$PKG_MGR" = "opkg" ]; then
|
||||||
|
opkg install unzip
|
||||||
|
else
|
||||||
|
apk add unzip
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_pkg_version
|
function get_pkg_version
|
||||||
@@ -279,7 +357,12 @@ echo "DISTRIB_DESCRIPTION:" $(get_distrib_param DISTRIB_DESCRIPTION)
|
|||||||
echo "DISTRIB_ARCH:" $( get_distrib_param DISTRIB_ARCH )
|
echo "DISTRIB_ARCH:" $( get_distrib_param DISTRIB_ARCH )
|
||||||
|
|
||||||
if ! command -v curl >/dev/null 2>&1; then
|
if ! command -v curl >/dev/null 2>&1; then
|
||||||
echo "ERROR: package \"curl\" not installed!"
|
if [ "$opt_forced" = true ]; then
|
||||||
|
curl_install
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if ! command -v curl >/dev/null 2>&1; then
|
||||||
|
echo "ERROR: Required package \"curl\" not installed!"
|
||||||
return 10
|
return 10
|
||||||
fi
|
fi
|
||||||
CURL_INFO=$( curl -V )
|
CURL_INFO=$( curl -V )
|
||||||
@@ -301,6 +384,11 @@ if [ "$opt_check" = "true" ]; then
|
|||||||
fi
|
fi
|
||||||
get_actual_release
|
get_actual_release
|
||||||
ZAP_ERR=$?
|
ZAP_ERR=$?
|
||||||
|
if [ $ZAP_ERR = 150 ] && [ "$opt_prerelease" != true ] && [ "$opt_forced" = true ]; then
|
||||||
|
opt_prerelease="true"
|
||||||
|
get_actual_release
|
||||||
|
ZAP_ERR=$?
|
||||||
|
fi
|
||||||
if [ $ZAP_ERR -ne 0 ]; then
|
if [ $ZAP_ERR -ne 0 ]; then
|
||||||
echo "ERROR: Func get_actual_release return error code: $ZAP_ERR"
|
echo "ERROR: Func get_actual_release return error code: $ZAP_ERR"
|
||||||
return $ZAP_ERR
|
return $ZAP_ERR
|
||||||
@@ -393,6 +481,11 @@ if [ "$opt_update" != "" ]; then
|
|||||||
echo "ERROR: downloaded package is incorrect! (size = $ZAP_PKG_SZ)"
|
echo "ERROR: downloaded package is incorrect! (size = $ZAP_PKG_SZ)"
|
||||||
return 216
|
return 216
|
||||||
fi
|
fi
|
||||||
|
if ! command -v unzip >/dev/null 2>&1; then
|
||||||
|
if [ "$opt_forced" = true ]; then
|
||||||
|
unzip_install
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if ! command -v unzip >/dev/null 2>&1; then
|
if ! command -v unzip >/dev/null 2>&1; then
|
||||||
echo "ERROR: package \"upzip\" not installed!"
|
echo "ERROR: package \"upzip\" not installed!"
|
||||||
return 218
|
return 218
|
||||||
@@ -429,6 +522,9 @@ if [ "$opt_update" != "" ]; then
|
|||||||
return 232
|
return 232
|
||||||
fi
|
fi
|
||||||
echo "ZAP_PKG_LUCI_FN = $ZAP_PKG_LUCI_FN"
|
echo "ZAP_PKG_LUCI_FN = $ZAP_PKG_LUCI_FN"
|
||||||
|
if [ "$opt_forced" = true ]; then
|
||||||
|
pkg_mgr_update
|
||||||
|
fi
|
||||||
echo "Install downloaded packages..."
|
echo "Install downloaded packages..."
|
||||||
if [ "$PKG_MGR" != "apk" ]; then
|
if [ "$PKG_MGR" != "apk" ]; then
|
||||||
opkg install --force-reinstall "$ZAP_PKG_BASE_FN"
|
opkg install --force-reinstall "$ZAP_PKG_BASE_FN"
|
||||||
|
|||||||
Reference in New Issue
Block a user