-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathonekey-install.sh
More file actions
executable file
·153 lines (130 loc) · 5.54 KB
/
onekey-install.sh
File metadata and controls
executable file
·153 lines (130 loc) · 5.54 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
#!/bin/bash
#========================================================================================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the luci-app-amlogic plugin
# https://github.com/ophub/luci-app-amlogic
#
# Description: Install luci-app-amlogic plugin for OpenWrt
# Copyright (C) 2021- https://github.com/unifreq/openwrt_packit
# Copyright (C) 2021- https://github.com/ophub/luci-app-amlogic
#
# Command: curl -fsSL git.io/luci-app-amlogic | bash
#
#==================================== Functions list ====================================
#
# process_msg : Output process message
# query_version : Query the latest version
# download_plugin : Download plug-in
# install_plugin : Install plug-in
#
#============================ Set make environment variables ============================
#
# Set the plugin download directory
tmp_dir="/root"
#
#========================================================================================
process_msg() {
echo -e "${1}"
[[ -n "${2}" && "${2}" -eq "1" ]] && exit 1
}
query_version() {
process_msg "01. Start querying plugin version..."
# Get the latest version
latest_version="$(
curl -fsSL -m 10 \
https://github.com/ophub/luci-app-amlogic/releases |
grep -oE 'expanded_assets/[0-9]+.[0-9]+.[0-9]+(-[0-9]+)?' | sed 's|expanded_assets/||g' |
sort -urV | head -n 1
)"
if [[ -z "${latest_version}" ]]; then
process_msg "01.01 Query failed, please try again." "1"
else
process_msg "01.01 Latest version: ${latest_version}"
sleep 2
fi
}
download_plugin() {
process_msg "02. Start downloading the latest plugin..."
# Delete other ipk files
rm -f ${tmp_dir}/*.ipk ${tmp_dir}/*.apk
# Check if the package manager is opkg or apk
package_manager=""
if command -v opkg >/dev/null 2>&1; then
package_manager="ipk"
elif command -v apk >/dev/null 2>&1; then
package_manager="apk"
else
process_msg "No supported package manager found. Please install opkg or apk." "1"
fi
process_msg "package_manager: ${package_manager}"
# Set the plugin download path
download_repo="https://github.com/ophub/luci-app-amlogic/releases/download"
# Intelligent File Discovery
plugin_file_name=""
lang_file_list=""
# Method 1: Use GitHub API if 'jq' is installed (Preferred Method)
if command -v jq >/dev/null 2>&1; then
process_msg "Using GitHub API with jq to find package files."
api_url="https://api.github.com/repos/ophub/luci-app-amlogic/releases/tags/${latest_version}"
# Fetch all asset names from the API
asset_list="$(curl -fsSL -m 15 "${api_url}" | jq -r '.assets[].name' | xargs)"
if [[ -n "${asset_list}" ]]; then
# Discover exact filenames using regular expressions from the asset list
plugin_file_name="$(echo "${asset_list}" | tr ' ' '\n' | grep -oE "^luci-app-amlogic.*${package_manager}$" | head -n 1)"
lang_file_list=($(echo "${asset_list}" | tr ' ' '\n' | grep -oE "^luci-i18n-amlogic.*${package_manager}$"))
else
process_msg "Warning: Failed to fetch data from GitHub API." "1"
fi
else
process_msg "jq not found, Aborting." "1"
fi
# Validation and Download
if [[ -z "${plugin_file_name}" || "${#lang_file_list[@]}" -eq "0" ]]; then
process_msg "Could not discover plugin(.${package_manager}) in the release. Aborting." "1"
fi
process_msg "02.01 Found plugin file: ${plugin_file_name}"
process_msg "02.02 Found language file: $(echo ${lang_file_list[@]} | xargs)"
# Download the main plugin file
plugin_full_url="${download_repo}/${latest_version}/${plugin_file_name}"
process_msg "02.03 Downloading main plugin [ ${plugin_file_name} ]..."
curl -fsSL "${plugin_full_url}" -o "${tmp_dir}/${plugin_file_name}"
[[ "${?}" -ne "0" ]] && process_msg "02.03 Plugin [ ${plugin_file_name} ] download failed." "1"
# Download language packs
for langfile in "${lang_file_list[@]}"; do
lang_full_url="${download_repo}/${latest_version}/${langfile}"
process_msg "02.04 Downloading language pack [ ${langfile} ]..."
curl -fsSL "${lang_full_url}" -o "${tmp_dir}/${langfile}"
[[ "${?}" -ne "0" ]] && process_msg "02.04 Language pack [ ${langfile} ] download failed." "1"
done
# The .apk filename is preceded by a tilde (~) instead of a dot (.).
for file in ${tmp_dir}/*.apk; do
[[ -f "${file}" ]] || continue
base_name="$(basename "${file}")"
new_name="$(echo "${base_name}" | sed -E 's/\.([a-f0-9]{7}\.apk)/~\1/')"
if [[ "${base_name}" != "${new_name}" ]]; then
mv -f "${file}" "${tmp_dir}/${new_name}" || true
fi
done
sync && sleep 2
}
install_plugin() {
process_msg "03. Start installing plugins..."
# Force plug-in reinstallation
if [[ "${package_manager}" == "opkg" ]]; then
opkg --force-reinstall install ${tmp_dir}/*.ipk
elif [[ "${package_manager}" == "apk" ]]; then
apk add --force-overwrite --allow-untrusted ${tmp_dir}/*.apk
fi
# Delete cache file
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache/* 2>/dev/null
rm -f ${tmp_dir}/*.ipk ${tmp_dir}/*.apk
process_msg "03.01 The plugin has been installed successfully, Path: System -> Amlogic Service."
}
query_version
download_plugin
install_plugin
exit 0