-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
79 lines (68 loc) 路 1.69 KB
/
Copy pathinstall.sh
File metadata and controls
79 lines (68 loc) 路 1.69 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
#!/usr/bin/env sh
API_URL="https://api.github.com/repos/vernette/beszel-agent-openwrt/releases/latest"
require_openwrt_release() {
if [ ! -r /etc/openwrt_release ]; then
echo "Error: /etc/openwrt_release not found."
exit 1
fi
. /etc/openwrt_release
}
detect_arch() {
ARCH="${DISTRIB_ARCH:-}"
if [ -z "$ARCH" ]; then
echo "Error: DISTRIB_ARCH not found in /etc/openwrt_release."
exit 1
fi
}
detect_pkg_manager() {
if command -v apk >/dev/null 2>&1; then
PKG_EXT="apk"
PKG_MANAGER="apk"
elif command -v opkg >/dev/null 2>&1; then
PKG_EXT="ipk"
PKG_MANAGER="opkg"
else
echo "Error: neither apk nor opkg found on this system."
exit 1
fi
}
resolve_asset_url() {
MATCH_PATTERN="_${ARCH}.${PKG_EXT}"
PKG_URL="$(wget -qO- "$API_URL" | grep -o 'https://[^"]*'"${MATCH_PATTERN}" | head -n 1)"
if [ -z "$PKG_URL" ]; then
echo "Error: failed to find asset URL for ${ARCH} (${PKG_EXT})."
exit 1
fi
PKG_NAME="${PKG_URL##*/}"
PKG_PATH="/tmp/${PKG_NAME}"
}
download_package() {
printf "%s: %s\n%s: %s\n\n%s: %s\n" \
"Architecture" "${ARCH}" \
"Package manager" "${PKG_MANAGER}" \
"Downloading" "${PKG_URL}"
if ! wget -qO "$PKG_PATH" "$PKG_URL"; then
echo "Error: failed to download ${PKG_URL}."
rm -f "$PKG_PATH"
exit 1
fi
}
install_package() {
echo "Installing $PKG_PATH"
if [ "$PKG_MANAGER" = "opkg" ]; then
opkg install "$PKG_PATH"
else
apk add --allow-untrusted "$PKG_PATH"
fi
rm -f "$PKG_PATH"
}
main() {
require_openwrt_release
detect_arch
detect_pkg_manager
resolve_asset_url
download_package
install_package
printf "\n%s\n" "Done. Edit config in /etc/config/beszel-agent"
}
main "$@"