Skip to content

Commit 6f72088

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 42030a6 + 656e9ea commit 6f72088

File tree

7 files changed

+77
-22
lines changed

7 files changed

+77
-22
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ Using Luci's menu "System" --> "Attended Sysupgrade" it is now possible to selec
3939

4040
<sub>Installing Custom Firmware</sub>
4141
![Installing Custom Firmware](attended-sysupgrade-installing.png)
42-
42+
43+
<sub>GitHub repository</sub>
44+
![GitHub repository used](attended-sysupgrade-server.png)
45+
4346
Notes:
44-
- if you fork this repository, this will be adapted to look for upgrades in your repository.
47+
- if you fork this repository, this will be adapted to look for upgrades in your repository by default.
4548

4649

4750

attended-sysupgrade-server.png

79.8 KB
Loading

attendedsysupgrade-with-GitHub.patch

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
/**
1414
* Returns the branch of a given version. This helps to offer upgrades
1515
* for point releases (aka within the branch).
16-
@@ -694,7 +700,7 @@
16+
@@ -694,7 +700,8 @@
1717
const data = {
1818
system_board: promises[1],
1919
advanced_mode: uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0,
2020
- url: uci.get_first('attendedsysupgrade', 'server', 'url').replace(/\/+$/, ''),
2121
+ url: (uci.get_first('attendedsysupgrade', 'server', 'url') || '').replace(/\/+$/, ''),
22+
+ github_repo: uci.get_first('attendedsysupgrade', 'server', 'github_repo') || 'XXXXXX/YYYYYY',
2223
branch: get_branch(promises[1].release.version),
2324
revision: promises[1].release.revision,
2425
efi: promises[2],
25-
@@ -745,13 +751,218 @@
26+
@@ -745,13 +752,218 @@
2627
E(
2728
'button',
2829
{
@@ -38,14 +39,15 @@
3839
+ 'button',
3940
+ {
4041
+ class: 'btn cbi-button cbi-button-positive important',
41-
+ click: ui.createHandlerFn(this, this.handleGithubFirmware, firmware),
42+
+ click: ui.createHandlerFn(this, this.handleGithubFirmware, data, firmware),
4243
+ },
4344
+ _('Check for GitHub firmware')
44-
+ ),
45-
+ ]);
46-
+ },
45+
),
46+
]);
47+
},
4748
+
48-
+ handleGithubFirmware: function(firmware) {
49+
+ handleGithubFirmware: function(data, firmware) {
50+
+ const githubRepo = data.github_repo;
4951
+ ui.showModal(_('Fetching GitHub firmware info...'), [
5052
+ E(
5153
+ 'p',
@@ -55,7 +57,7 @@
5557
+ ]);
5658
+
5759
+ // Call the CGI script to get the list of available firmware releases
58-
+ fetch('/cgi-bin/github_check')
60+
+ fetch('/cgi-bin/github_check?repo=' + encodeURIComponent(githubRepo))
5961
+ .then(response => response.json())
6062
+ .then(data => {
6163
+ if (data.error) {
@@ -95,7 +97,6 @@
9597
+
9698
+ // Create element for the URL
9799
+ const urlElement = E('td', { class: 'td left' });
98-
+
99100
+ // Function to update the URL based on selected release
100101
+ const updateDetails = function() {
101102
+ const selectedIndex = releaseSelect.value;
@@ -104,7 +105,7 @@
104105
+ if (selectedRelease) {
105106
+ // Clear previous link and create a new one
106107
+ urlElement.innerHTML = '';
107-
+ urlElement.appendChild(E('a', { href: 'https://github.com/XXXXXX/YYYYYY/releases/tag/' + selectedRelease.tag, target: '_blank' }, _('View on GitHub')));
108+
+ urlElement.appendChild(E('a', { href: 'https://github.com/' + githubRepo + '/releases/tag/' + selectedRelease.tag, target: '_blank' }, _('View on GitHub')));
108109
+ }
109110
+ };
110111
+
@@ -146,7 +147,7 @@
146147
+ const selectedRelease = releases[selectedIndex];
147148
+
148149
+ if (selectedRelease && selectedRelease.tag) {
149-
+ this.handleGithubInstall(selectedRelease.tag, keep.checked);
150+
+ this.handleGithubInstall(selectedRelease.tag, keep.checked, githubRepo);
150151
+ } else {
151152
+ ui.showModal(_('Error'), [
152153
+ E('p', _('Invalid release selected')),
@@ -177,18 +178,18 @@
177178
+ });
178179
+ },
179180
+
180-
+ handleGithubInstall: function(tag, keep) {
181+
+ handleGithubInstall: function(tag, keep, githubRepo) {
181182
+ ui.showModal(_('Downloading from GitHub...'), [
182183
+ E(
183184
+ 'p',
184185
+ { class: 'spinning' },
185186
+ _('Downloading firmware from GitHub to device')
186-
),
187-
]);
187+
+ ),
188+
+ ]);
188189
+
189190
+ // Call the CGI script to download the firmware to /tmp/firmware.bin
190191
+ // Pass the selected tag as a parameter to the github_fetch script
191-
+ fetch(`/cgi-bin/github_fetch?tag=${encodeURIComponent(tag)}`)
192+
+ fetch(`/cgi-bin/github_fetch?tag=${encodeURIComponent(tag)}&repo=${encodeURIComponent(githubRepo)}`)
192193
+ .then(response => response.json())
193194
+ .then(data => {
194195
+ if (data.error) {
@@ -238,8 +239,35 @@
238239
+ ]),
239240
+ ]);
240241
+ });
241-
},
242+
+ },
242243
+
243244
handleSaveApply: null,
244245
handleSave: null,
245246
handleReset: null,
247+
--- a/feeds/luci/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/configuration.js
248+
+++ b/feeds/luci/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/configuration.js
249+
@@ -32,6 +32,14 @@
250+
)
251+
);
252+
253+
+ o = s.option(
254+
+ form.Value,
255+
+ 'github_repo',
256+
+ _('GitHub Repository'),
257+
+ _('GitHub repository for firmware releases (owner/name)')
258+
+ );
259+
+ o.placeholder = 'XXXXXX/YYYYYY';
260+
+
261+
s = m.section(form.TypedSection, 'client', _('Client'));
262+
s.anonymous = true;
263+
264+
--- a/feeds/packages/utils/attendedsysupgrade-common/files/attendedsysupgrade.defaults
265+
+++ b/feeds/packages/utils/attendedsysupgrade-common/files/attendedsysupgrade.defaults
266+
@@ -7,6 +7,7 @@
267+
uci -q batch <<EOF
268+
set attendedsysupgrade.server=server
269+
set attendedsysupgrade.server.url='https://sysupgrade.openwrt.org'
270+
+set attendedsysupgrade.server.github_repo='XXXXXX/YYYYYY'
271+
272+
set attendedsysupgrade.client=client
273+
set attendedsysupgrade.client.upgrade_packages='1'

files/www/cgi-bin/github_check

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44
echo "Content-Type: application/json"
55
echo ""
66

7+
QUERY_STRING="${QUERY_STRING:-$1}"
8+
REPO=$(printf '%s' "$QUERY_STRING" | sed -n 's/.*[?&]*repo=\([^&]*\).*/\1/p')
9+
# Decode percent-encoding
10+
REPO=$(printf '%b' "$(printf '%s' "$REPO" | sed 's/+/ /g;s/%/\\x/g')")
11+
12+
# Validate repo format (owner/name, alphanumeric with hyphens/underscores/dots)
13+
if ! printf '%s' "$REPO" | grep -qE '^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$'; then
14+
printf '{"error":"missing or invalid repo parameter"}'
15+
exit 1
16+
fi
17+
718
# Create a temporary file for the final JSON objects
819
temp_json="/tmp/github_versions_$$.tmp"
920
> "$temp_json" # Clear the file
1021

11-
curl -sS https://api.github.com/repos/XXXXXX/YYYYYY/releases | \
22+
curl -sS "https://api.github.com/repos/$REPO/releases" | \
1223
jq -r '.[] | "\(.tag_name) \(.assets[] | select(.browser_download_url | contains("sysupgrade")) | .browser_download_url)"' | \
1324
while read -r tag url; do
1425
if [ -z "$url" ] || [ -z "$tag" ]; then

files/www/cgi-bin/github_fetch

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@ QUERY_STRING="${QUERY_STRING:-$1}"
99
# Extract tag parameter (simple URL-decode of %XX sequences and +->space not needed here)
1010
# Use parameter expansion and sed to get tag value if present, otherwise use whole string
1111
TAG=$(printf '%s' "$QUERY_STRING" | sed -n 's/.*[?&]*tag=\([^&]*\).*/\1/p')
12-
[ -z "$TAG" ] && TAG="$QUERY_STRING"
1312
# Decode percent-encoding (handles %2B, %2F, etc.)
1413
TAG=$(printf '%b' "$(printf '%s' "$TAG" | sed 's/+/ /g;s/%/\\x/g')")
1514

15+
# Extract repo parameter
16+
REPO=$(printf '%s' "$QUERY_STRING" | sed -n 's/.*[?&]*repo=\([^&]*\).*/\1/p')
17+
REPO=$(printf '%b' "$(printf '%s' "$REPO" | sed 's/+/ /g;s/%/\\x/g')")
18+
19+
# Validate repo format (owner/name, alphanumeric with hyphens/underscores/dots)
20+
if ! printf '%s' "$REPO" | grep -qE '^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$'; then
21+
printf '{"error":"missing or invalid repo parameter"}'
22+
exit 1
23+
fi
24+
1625
# basic validation
1726
if [ -z "$TAG" ]; then
1827
printf '{"error":"missing tag"}'
1928
exit 1
2029
fi
2130

2231
# Fetch release metadata once
23-
RELEASE_JSON=$(curl -sS "https://api.github.com/repos/XXXXXX/YYYYYY/releases/tags/$TAG") || {
32+
RELEASE_JSON=$(curl -sS "https://api.github.com/repos/$REPO/releases/tags/$TAG") || {
2433
printf '{"error":"failed to fetch release metadata"}'
2534
exit 1
2635
}
@@ -36,7 +45,7 @@ FILENAME=$(basename "$URL")
3645
# Try: 1) sha256sums asset file, 2) asset .digest field (sha256:)
3746
SHA256_URL=$(printf '%s' "$RELEASE_JSON" | jq -r '.assets[] | select(.browser_download_url|contains("sha256sums")) | .browser_download_url // empty' | head -n1)
3847
# download sha256sums and extract matching line
39-
[ -n "$SHA256_URL" ] && SHA256=$(curl -sSL "$SHA256_URL" | sed -n "s|\([0-9a-fA-F]*\).*${FILENAME}|\1|p")
48+
[ -n "$SHA256_URL" ] && SHA256=$(curl -sSL "$SHA256_URL" | sed -n "s|\([0-9a-fA-F]*\).*${FILENAME}.*|\1|p")
4049
# fallback to metadata if present
4150
[ -z "$SHA256" ] && SHA256=$(printf '%s' "$RELEASE_JSON" | jq -r '.assets[] | select(.browser_download_url|contains("sysupgrade")) | .digest // empty' | sed -n 's/^sha256://p' | head -n1)
4251

mt6000.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ CONFIG_PACKAGE_libip4tc=y
172172
CONFIG_PACKAGE_libip6tc=y
173173

174174

175+
## Base options
176+
CONFIG_PACKAGE_attendedsysupgrade-common=y
177+
CONFIG_PACKAGE_luci-app-attendedsysupgrade=y
178+
175179
## Compiler and Toolchain Optimization
176180
CONFIG_TARGET_OPTIMIZATION="-O2 -pipe -mcpu=cortex-a53+crc+crypto"
177181
CONFIG_USE_GC_SECTIONS=y

0 commit comments

Comments
 (0)