Skip to content

Commit

Permalink
chore: refine
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Nov 20, 2024
1 parent e75180c commit 9b9f351
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions luci-app-openclash/luasrc/controller/openclash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ local function coremodel()
if fs.access("/bin/opkg") then
return luci.sys.exec("rm -f /var/lock/opkg.lock && opkg status libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null")
elseif fs.access("/usr/bin/apk") then
return luci.sys.exec("apk list libc |awk '{print $2}'")
return luci.sys.exec("apk list libc 2>/dev/null |awk '{print $2}'")
end
end
end
Expand Down Expand Up @@ -255,7 +255,7 @@ local function opcv()
if fs.access("/bin/opkg") then
return luci.sys.exec("rm -f /var/lock/opkg.lock && opkg status luci-app-openclash 2>/dev/null |grep 'Version' |awk -F 'Version: ' '{print \"v\"$2}'")
elseif fs.access("/usr/bin/apk") then
return "v" .. luci.sys.exec("apk list luci-app-openclash |grep 'installed' | grep -oE '\\d+(\\.\\d+)*' | head -1")
return "v" .. luci.sys.exec("apk list luci-app-openclash 2>/dev/null |grep 'installed' | grep -oE '\\d+(\\.\\d+)*' | head -1")
end
end
end
Expand Down
26 changes: 15 additions & 11 deletions luci-app-openclash/root/usr/share/openclash/openclash_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ del_lock() {
rm -rf "/tmp/lock/openclash_debug.lock"
}

ipk_v()
{
if [ -x "/bin/opkg" ]; then
echo $(opkg status "$1" 2>/dev/null |grep 'Version' |awk -F ': ' '{print $2}' 2>/dev/null)
elif [ -x "/usr/bin/apk" ]; then
echo $(apk list "$1" 2>/dev/null |grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1)
fi
}

DEBUG_LOG="/tmp/openclash_debug.log"
LOGTIME=$(echo $(date "+%Y-%m-%d %H:%M:%S"))
set_lock
Expand All @@ -31,11 +40,15 @@ en_mode=$(uci -q get openclash.config.en_mode)
RAW_CONFIG_FILE=$(uci -q get openclash.config.config_path)
CONFIG_FILE="/etc/openclash/$(uci -q get openclash.config.config_path |awk -F '/' '{print $5}' 2>/dev/null)"
core_model=$(uci -q get openclash.config.core_version)
cpu_model=$(ipk_v libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null)
if [ -x "/bin/opkg" ]; then
cpu_model=$(opkg status libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null)
elif [ -x "/usr/bin/apk" ]; then
cpu_model=$(apk list libc 2>/dev/null|awk '{print $2}')
fi
core_meta_version=$(/etc/openclash/core/clash_meta -v 2>/dev/null |awk -F ' ' '{print $3}' |head -1 2>/dev/null)
servers_update=$(uci -q get openclash.config.servers_update)
mix_proxies=$(uci -q get openclash.config.mix_proxies)
op_version=$(ipk_v luci-app-openclash 2>/dev/null |grep 'Version' |awk -F 'Version: ' '{print "v"$2}')
op_version=$(ipk_v "luci-app-openclash")
china_ip_route=$(uci -q get openclash.config.china_ip_route)
common_ports=$(uci -q get openclash.config.common_ports)
router_self_proxy=$(uci -q get openclash.config.router_self_proxy)
Expand Down Expand Up @@ -80,15 +93,6 @@ ts_re()
fi
}

ipk_v()
{
if [ -x "/bin/opkg" ]; then
echo $(opkg status "$1" 2>/dev/null |grep 'Version' |awk -F ': ' '{print $2}' 2>/dev/null)
elif [ -x "/usr/bin/apk" ]; then
echo $(apk list "$1" |grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1)
fi
}

dns_re()
{
if [ "$1" = "1" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LAST_VER=$(sed -n 1p "$LAST_OPVER" 2>/dev/null |sed "s/^v//g" |tr -d "\n")
if [ -x "/bin/opkg" ]; then
OP_CV=$(rm -f /var/lock/opkg.lock && opkg status luci-app-openclash 2>/dev/null |grep 'Version' |awk -F 'Version: ' '{print $2}' |awk -F '.' '{print $2$3}' 2>/dev/null)
elif [ -x "/usr/bin/apk" ]; then
OP_CV=$(apk list luci-app-openclash |grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1)
OP_CV=$(apk list luci-app-openclash 2>/dev/null |grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1apk list luci-app-openclash 2>/dev/null|grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1 |awk -F '.' '{print $2$3}' 2>/dev/null)
fi
OP_LV=$(sed -n 1p "$LAST_OPVER" 2>/dev/null |awk -F 'v' '{print $2}' |awk -F '.' '{print $2$3}' 2>/dev/null)
RELEASE_BRANCH=$(uci -q get openclash.config.release_branch || echo "master")
Expand Down Expand Up @@ -156,10 +156,10 @@ if [ -x "/bin/opkg" ]; then
SLOG_CLEAN
fi
elif [ -x "/usr/bin/apk" ]; then
if [ "$?" != "0" ] || [ -z "$(apk list luci-app-openclash |grep 'installed')" ]; then
if [ "$?" != "0" ] || [ -z "$(apk list luci-app-openclash 2>/dev/null |grep 'installed')" ]; then
apk add --allow-untrusted /tmp/openclash.apk
fi
if [ "$?" != "0" ] || [ -z "$(apk list luci-app-openclash |grep 'installed')" ]; then
if [ "$?" != "0" ] || [ -z "$(apk list luci-app-openclash 2>/dev/null |grep 'installed')" ]; then
rm -rf /tmp/openclash.apk >/dev/null 2>&1
LOG_OUT "OpenClash Update Successful, About To Restart!"
uci -q set openclash.config.enable=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RELEASE_BRANCH=$(uci -q get openclash.config.release_branch || echo "master")
if [ -x "/bin/opkg" ]; then
OP_CV=$(rm -f /var/lock/opkg.lock && opkg status luci-app-openclash 2>/dev/null |grep 'Version' |awk -F 'Version: ' '{print $2}' |awk -F '.' '{print $2$3}' 2>/dev/null)
elif [ -x "/usr/bin/apk" ]; then
OP_CV=$(apk list luci-app-openclash |grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1)
OP_CV=$(apk list luci-app-openclash 2>/dev/null|grep 'installed' | grep -oE '\d+(\.\d+)*' | head -1 |awk -F '.' '{print $2$3}' 2>/dev/null)
fi
OP_LV=$(sed -n 1p $LAST_OPVER 2>/dev/null |awk -F 'v' '{print $2}' |awk -F '.' '{print $2$3}' 2>/dev/null)
github_address_mod=$(uci -q get openclash.config.github_address_mod || echo 0)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9b9f351

Please sign in to comment.