-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·163 lines (141 loc) · 3.86 KB
/
install.sh
File metadata and controls
executable file
·163 lines (141 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
set -e
# Define color codes and output functions
RED='\033[1;31m'
GREEN='\033[1;32m'
RESET='\033[0m'
msg_red() { printf "${RED}%b${RESET}\n" "$*"; }
msg_green() { printf "${GREEN}%b${RESET}\n" "$*"; }
msg_green "\nInstall luci-app-openlist2"
msg_green "LuCI support for OpenList (Alist Variant)\n"
# Parse gh_proxy from $1 if provided, e.g. gh_proxy="https://gh-proxy.com/"
gh_proxy=""
if [ -n "$1" ]; then
case "$1" in
gh_proxy=*)
gh_proxy="${1#gh_proxy=}"
# ensure gh_proxy ends with /
[ -n "$gh_proxy" ] && case "$gh_proxy" in
*/) : ;;
*) gh_proxy="$gh_proxy/" ;;
esac
;;
esac
fi
# Check if running on OpenWrt
if [ ! -f /etc/openwrt_release ]; then
msg_red "Unknown OpenWrt Version."
exit 1
fi
# Read architecture information
. /etc/openwrt_release
DISTRIB_ARCH="${DISTRIB_ARCH:-unknown}"
# Detect package manager and set SDK version
if [ -x "/usr/bin/apk" ]; then
PKG_MANAGER="apk"
PKG_OPT="add --allow-untrusted"
SDK="SNAPSHOT"
elif command -v opkg >/dev/null 2>&1; then
PKG_MANAGER="opkg"
PKG_OPT="install --force-downgrade"
SDK="openwrt-24.10"
else
msg_red "No supported package manager found."
exit 1
fi
# Check LuCI version compatibility
if [ ! -d "/usr/share/luci/menu.d" ]; then
msg_red "The current OpenWrt LuCI version is not supported or \`luci-base\` is not installed."
msg_red "The minimum required OpenWrt version is openwrt-21.02 or higher (i.e., LuCI2)."
exit 1
fi
# Check available root partition space (at least 20MiB required)
ROOT_SPACE=$(df -m /usr | awk 'END{print $4}')
if [ "$ROOT_SPACE" -lt 20 ]; then
msg_red "Error: The system storage space is less than 20MiB."
exit 1
fi
# Create temporary directory and set up cleanup on exit
TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT
# Check if the current platform is supported
msg_green "Checking platform..."
SUPPORTED_PLATFORMS="
aarch64_cortex-a53
aarch64_cortex-a72
aarch64_cortex-a76
aarch64_generic
arm_arm1176jzf-s_vfp
arm_arm926ej-s
arm_cortex-a15_neon-vfpv4
arm_cortex-a5_vfpv4
arm_cortex-a7
arm_cortex-a7_neon-vfpv4
arm_cortex-a7_vfpv4
arm_cortex-a8_vfpv3
arm_cortex-a9
arm_cortex-a9_neon
arm_cortex-a9_vfpv3-d16
arm_fa526
arm_xscale
i386_pentium-mmx
i386_pentium4
loongarch64_generic
mips64_mips64r2
mips64_octeonplus
mips64el_mips64r2
mips_24kc
mips_4kec
mips_mips32
mipsel_24kc
mipsel_24kc_24kf
mipsel_74kc
mipsel_mips32
riscv64_riscv64
x86_64
"
FOUND=0
for arch in $SUPPORTED_PLATFORMS; do
if [ "$DISTRIB_ARCH" = "$arch" ]; then
FOUND=1
break
fi
done
if [ "$FOUND" -ne 1 ]; then
msg_red "Error! The current \"$DISTRIB_ARCH\" platform is not supported."
exit 1
fi
# Download the corresponding package archive
PKG_FILE="$SDK-$DISTRIB_ARCH.tar.gz"
BASE_URL="https://github.com/sbwml/luci-app-openlist2/releases/latest/download/$PKG_FILE"
if [ -n "$gh_proxy" ]; then
PKG_URL="${gh_proxy}${BASE_URL}"
else
PKG_URL="$BASE_URL"
fi
msg_green "Downloading $PKG_URL ..."
if ! curl --connect-timeout 5 -m 300 -kLo "$TEMP_DIR/$PKG_FILE" "$PKG_URL"; then
msg_red "Download $PKG_FILE failed."
exit 1
fi
# Stop openlist service
if [ -x "/etc/init.d/openlist" ]; then
/etc/init.d/openlist stop || true
elif [ -x "/etc/init.d/openlist2" ]; then
/etc/init.d/openlist2 stop || true
fi
# Extract and install packages
msg_green "\nInstalling Packages ..."
tar -zxf "$TEMP_DIR/$PKG_FILE" -C "$TEMP_DIR/"
for pkg in "$TEMP_DIR"/packages_ci/openlist2*.* \
"$TEMP_DIR"/packages_ci/luci-app-openlist2*.* \
"$TEMP_DIR"/packages_ci/luci-i18n-openlist2-zh-cn*.*; do
[ -f "$pkg" ] && $PKG_MANAGER $PKG_OPT $pkg
done
# Clean up temporary files and finish
rm -rf /tmp/luci-*
# Start openlist service
if [ -x "/etc/init.d/openlist2" ]; then
/etc/init.d/openlist2 start || true
fi
msg_green "Done!"