chore: Added apk package manager support for install script

This commit is contained in:
SaltyMonkey
2025-10-08 21:42:19 +03:00
parent 3d63a82815
commit b89fe33296

View File

@@ -4,6 +4,10 @@ REPO="https://api.github.com/repos/itdoginfo/podkop/releases/latest"
DOWNLOAD_DIR="/tmp/podkop" DOWNLOAD_DIR="/tmp/podkop"
COUNT=3 COUNT=3
# Cached flag to switch between ipk or apk package managers
PKG_IS_APK=0
command -v apk >/dev/null 2>&1 && PKG_IS_APK=1
rm -rf "$DOWNLOAD_DIR" rm -rf "$DOWNLOAD_DIR"
mkdir -p "$DOWNLOAD_DIR" mkdir -p "$DOWNLOAD_DIR"
@@ -11,13 +15,58 @@ msg() {
printf "\033[32;1m%s\033[0m\n" "$1" printf "\033[32;1m%s\033[0m\n" "$1"
} }
pkg_is_installed () {
local pkg_name="$1"
if [ "$PKG_IS_APK" -eq 1 ]; then
# grep -q should work without change based on example from documentation
# apk list --installed --providers dnsmasq
# <dnsmasq> dnsmasq-full-2.90-r3 x86_64 {feeds/base/package/network/services/dnsmasq} (GPL-2.0) [installed]
apk list --installed | grep -q "$pkg_name"
else
opkg list-installed | grep -q "$pkg_name"
fi
}
pkg_remove() {
local pkg_name="$1"
if [ "$PKG_IS_APK" -eq 1 ]; then
# TODO: check --force-depends flag
# Nothing here: https://openwrt.org/docs/guide-user/additional-software/opkg-to-apk-cheatsheet
apk del "$pkg_name"
else
opkg remove --force-depends "$pkg_name"
fi
}
pkg_list_update() {
if [ "$PKG_IS_APK" -eq 1 ]; then
apk update
else
opkg update
fi
}
pkg_install() {
local pkg_file="$1"
if [ "$PKG_IS_APK" -eq 1 ]; then
# Can't install without flag based on info from documentation
# If you're installing a non-standard (self-built) package, use the --allow-untrusted option:
apk add --allow-untrusted "$pkg_file"
else
opkg install "$pkg_file"
fi
}
main() { main() {
check_system check_system
sing_box sing_box
/usr/sbin/ntpd -q -p 194.190.168.1 -p 216.239.35.0 -p 216.239.35.4 -p 162.159.200.1 -p 162.159.200.123 /usr/sbin/ntpd -q -p 194.190.168.1 -p 216.239.35.0 -p 216.239.35.4 -p 162.159.200.1 -p 162.159.200.123
opkg update || { echo "opkg update failed"; exit 1; } pkg_list_update || { echo "Packages list update failed"; exit 1; }
if [ -f "/etc/init.d/podkop" ]; then if [ -f "/etc/init.d/podkop" ]; then
msg "Podkop is already installed. Upgraded..." msg "Podkop is already installed. Upgraded..."
@@ -34,6 +83,13 @@ main() {
fi fi
fi fi
local grep_url_pattern
if [ "$PKG_IS_APK" -eq 1 ]; then
grep_url_pattern='https://[^"[:space:]]*\.ipk'
else
grep_url_pattern='https://[^"[:space:]]*\.apk'
fi
download_success=0 download_success=0
while read -r url; do while read -r url; do
filename=$(basename "$url") filename=$(basename "$url")
@@ -57,7 +113,7 @@ main() {
if [ $attempt -eq $COUNT ]; then if [ $attempt -eq $COUNT ]; then
msg "Failed to download $filename after $COUNT attempts" msg "Failed to download $filename after $COUNT attempts"
fi fi
done < <(wget -qO- "$REPO" | grep -o 'https://[^"[:space:]]*\.ipk') done < <(wget -qO- "$REPO" | grep -o "$grep_url_pattern")
if [ $download_success -eq 0 ]; then if [ $download_success -eq 0 ]; then
msg "No packages were downloaded successfully" msg "No packages were downloaded successfully"
@@ -68,25 +124,25 @@ main() {
file=$(ls "$DOWNLOAD_DIR" | grep "^$pkg" | head -n 1) file=$(ls "$DOWNLOAD_DIR" | grep "^$pkg" | head -n 1)
if [ -n "$file" ]; then if [ -n "$file" ]; then
msg "Installing $file" msg "Installing $file"
opkg install "$DOWNLOAD_DIR/$file" pkg_install "$DOWNLOAD_DIR/$file"
sleep 3 sleep 3
fi fi
done done
ru=$(ls "$DOWNLOAD_DIR" | grep "luci-i18n-podkop-ru" | head -n 1) ru=$(ls "$DOWNLOAD_DIR" | grep "luci-i18n-podkop-ru" | head -n 1)
if [ -n "$ru" ]; then if [ -n "$ru" ]; then
if opkg list-installed | grep -q luci-i18n-podkop-ru; then if pkg_is_installed luci-i18n-podkop-ru; then
msg "Upgraded ru translation..." msg "Upgraded ru translation..."
opkg remove luci-i18n-podkop* pkg_remove remove luci-i18n-podkop*
opkg install "$DOWNLOAD_DIR/$ru" pkg_install install "$DOWNLOAD_DIR/$ru"
else else
msg "Русский язык интерфейса ставим? y/n (Need a Russian translation?)" msg "Русский язык интерфейса ставим? y/n (Need a Russian translation?)"
while true; do while true; do
read -r -p '' RUS read -r -p '' RUS
case $RUS in case $RUS in
y) y)
opkg remove luci-i18n-podkop* pkg_remove luci-i18n-podkop*
opkg install "$DOWNLOAD_DIR/$ru" pkg_install "$DOWNLOAD_DIR/$ru"
break break
;; ;;
n) n)
@@ -133,15 +189,17 @@ check_system() {
exit 1 exit 1
fi fi
if opkg list-installed | grep -q https-dns-proxy; then if pkg_is_installed https-dns-proxy; then
msg "Сonflicting package detected: https-dns-proxy. Remove?" msg "Сonflicting package detected: https-dns-proxy. Remove?"
while true; do while true; do
read -r -p '' DNSPROXY read -r -p '' DNSPROXY
case $DNSPROXY in case $DNSPROXY in
yes|y|Y|yes) yes|y|Y)
opkg remove --force-depends luci-app-https-dns-proxy https-dns-proxy luci-i18n-https-dns-proxy* pkg_remove luci-app-https-dns-proxy
pkg_remove https-dns-proxy
pkg_remove luci-i18n-https-dns-proxy*
break break
;; ;;
*) *)
@@ -154,7 +212,7 @@ check_system() {
} }
sing_box() { sing_box() {
if ! opkg list-installed | grep -q "^sing-box"; then if ! pkg_is_installed "^sing-box"; then
return return
fi fi
@@ -165,7 +223,7 @@ sing_box() {
msg "sing-box version $sing_box_version is older than required $required_version" msg "sing-box version $sing_box_version is older than required $required_version"
msg "Removing old version..." msg "Removing old version..."
service podkop stop service podkop stop
opkg remove sing-box --force-depends pkg_remove sing-box
fi fi
} }