Skip to content

Commit d087f6c

Browse files
Merge branch 'cjom:main' into main
2 parents 52ae09d + eb2ed5e commit d087f6c

File tree

9 files changed

+373
-12
lines changed

9 files changed

+373
-12
lines changed

.github/workflows/build-openwrt.yaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
branches:
1111
- main
1212
schedule:
13-
- cron: "38 1 * * *"
13+
- cron: "38 1 */3 * *"
1414

1515
env:
1616
REMOTE_REPOSITORY: pesa1234/openwrt
@@ -55,13 +55,13 @@ jobs:
5555
sudo apt autoremove -y && sudo apt clean -y
5656
5757
- name: Checkout remote repository
58-
uses: actions/checkout@v4
58+
uses: actions/checkout@v6
5959
with:
6060
repository: ${{ env.REMOTE_REPOSITORY }}
6161
ref: ${{ needs.check_commits.outputs.remote_branch }}
6262

6363
- name: Checkout current repository
64-
uses: actions/checkout@v4
64+
uses: actions/checkout@v6
6565
with:
6666
path: "builder_repo"
6767

@@ -83,31 +83,35 @@ jobs:
8383
8484
- name: Setup configuration and custom files
8585
run: |
86+
# delete unneeded folders and patch files with repository info
87+
rm -frv builder_repo/.git builder_repo/.github
88+
for file in $(grep -rl XXXXXX builder_repo/); do echo "Patching: $file"; sed -i 's|XXXXXX/YYYYYY|${{ github.repository }}|g' "$file" || exit 1; done
89+
patch -p1 < builder_repo/attendedsysupgrade-with-GitHub.patch
8690
mv -v builder_repo/files ./
87-
sed -i 's|XXXXXX/XXXXXX|${{ github.repository }}|' ./files/usr/bin/upgrade_custom_openwrt || exit 1
88-
chmod 755 ./files/usr/bin/upgrade_custom_openwrt
91+
chmod -v 755 files/usr/bin/upgrade_custom_openwrt files/www/cgi-bin/github_*
8992
mv -v builder_repo/${{ env.CONFIG_FILE }} .config
93+
rm -rfv builder_repo
9094
make defconfig
9195
9296
- name: Build firmware
9397
run: |
9498
make download -j$(nproc) || {
9599
echo "Retrying..."
96-
sleep 30
100+
sleep 60
97101
make download -j1 V=s
98102
}
99103
make -j$(nproc) || {
100104
echo "Retrying..."
101-
sleep 30
105+
sleep 60
102106
make -j1 V=s
103107
}
104108
mkdir -p firmware
105-
find ./bin -type f \( -iname 'openwrt-*-sysupgrade.bin' -or -iname 'config.buildinfo' \) -exec mv -v {} ./firmware/ \; ||:
109+
find ./bin -type f \( -iname 'openwrt-*-sysupgrade.bin' -or -iname 'config.buildinfo' -or -iname 'version.buildinfo' \) -exec mv -v {} ./firmware/ \; ||:
106110
mv .config firmware/full.config ||:
107-
cd firmware && find -iname 'openwrt-*-sysupgrade.bin' -exec sh -c "sha256sum {} >sha256sums" \; ||:
111+
cd firmware && sha256sum openwrt-*-sysupgrade.bin >sha256sums ||:
108112
109113
- name: Upload artifacts
110-
uses: actions/upload-artifact@v4
114+
uses: actions/upload-artifact@v6.0.0
111115
with:
112116
name: gl-mt6000-firmware
113117
path: firmware/*
@@ -131,6 +135,7 @@ jobs:
131135
132136
- name: Clean up old releases
133137
run: |
134-
gh api repos/${{ github.repository }}/releases --paginate --jq '.[10:] | .[] | "\(.id) \(.tag_name)"' | while read id tag; do
138+
# '.[0:10][]' limits to the 10 most recent releases
139+
gh api repos/${{ github.repository }}/releases | jq -r '.[10:][] | "\(.id) \(.tag_name)"' | while read id tag; do
135140
gh api -X DELETE "repos/${{ github.repository }}/releases/$id" && gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" 2>/dev/null ||:
136141
done

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Compared to his custom firmware, this firmware adds:
1212
- **Wireguard VPN**
1313
- **Policy Based Routing** (select what goes through VPN and what not)
1414
- **AdBlock Fast** (ads and malware blocking at DNS level)
15+
- **Custom Attended Sysupgrade** (install custom firmware from GitHub)
1516

1617
And also:
1718
- **REMOVED:** odhcp, upnp, iptables, avahi, samba, usb storage and probably more stuff I forgot to mention.
@@ -26,8 +27,25 @@ Check the content of [`mt6000.config`](mt6000.config) for details.
2627

2728

2829

30+
## About Custom Attended Sysupgrade
31+
32+
Using Luci's menu "System" --> "Attended Sysupgrade" it is now possible to select and install custom firmware from GitHub.
33+
34+
![Custom Attended Sysupgrade](attended-sysupgrade-custom.png)
35+
36+
![Dropdown list](attended-sysupgrade-releases.png)
37+
38+
Notes:
39+
- if you fork this repository, this will be adapted to look for upgrades in your repository.
40+
41+
42+
2943
## About upgrade_custom_openwrt script
3044

45+
```
46+
THIS IS NOW DEPRECATED, ALTHOUGHT THE SCRIPT IS STILL INCLUDED
47+
```
48+
3149
I added a script to make upgrading OpenWRT super easy. Just run from a SSH terminal:
3250
- `upgrade_custom_openwrt --now` to check if a newer firmware is available and upgrade if so.
3351
- `upgrade_custom_openwrt --wait` to wait for clients activity to stop before upgrading.

attended-sysupgrade-custom.png

47.3 KB
Loading

attended-sysupgrade-releases.png

40.7 KB
Loading
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
--- a/feeds/luci/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js
2+
+++ b/feeds/luci/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js
3+
@@ -51,6 +51,12 @@
4+
params: ['keep'],
5+
});
6+
7+
+const callFileExec = rpc.declare({
8+
+ object: 'file',
9+
+ method: 'exec',
10+
+ params: ['command', 'params'],
11+
+});
12+
+
13+
/**
14+
* Returns the branch of a given version. This helps to offer upgrades
15+
* for point releases (aka within the branch).
16+
@@ -694,7 +700,7 @@
17+
const data = {
18+
system_board: promises[1],
19+
advanced_mode: uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0,
20+
- url: uci.get_first('attendedsysupgrade', 'server', 'url').replace(/\/+$/, ''),
21+
+ url: (uci.get_first('attendedsysupgrade', 'server', 'url') || '').replace(/\/+$/, ''),
22+
branch: get_branch(promises[1].release.version),
23+
revision: promises[1].release.revision,
24+
efi: promises[2],
25+
@@ -745,13 +751,218 @@
26+
E(
27+
'button',
28+
{
29+
- class: 'btn cbi-button cbi-button-positive important',
30+
+ class: 'btn cbi-button cbi-button-action important',
31+
click: ui.createHandlerFn(this, this.handleCheck, data, firmware),
32+
},
33+
- _('Search for firmware upgrade')
34+
+ _('Search for official firmware upgrade')
35+
+ ),
36+
+ ' ',
37+
+ E(
38+
+ 'button',
39+
+ {
40+
+ class: 'btn cbi-button cbi-button-positive important',
41+
+ click: ui.createHandlerFn(this, this.handleGithubFirmware, firmware),
42+
+ },
43+
+ _('Check for GitHub firmware')
44+
+ ),
45+
+ ]);
46+
+ },
47+
+
48+
+ handleGithubFirmware: function(firmware) {
49+
+ ui.showModal(_('Fetching GitHub firmware info...'), [
50+
+ E(
51+
+ 'p',
52+
+ { class: 'spinning' },
53+
+ _('Fetching available firmware releases from GitHub')
54+
+ ),
55+
+ ]);
56+
+
57+
+ // Call the CGI script to get the list of available firmware releases
58+
+ fetch('/cgi-bin/github_check')
59+
+ .then(response => response.json())
60+
+ .then(data => {
61+
+ if (data.error) {
62+
+ ui.showModal(_('Error'), [
63+
+ E('p', _('Error fetching firmware info: %s').format(data.error)),
64+
+ E('div', { class: 'right' }, [
65+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
66+
+ ]),
67+
+ ]);
68+
+ return;
69+
+ }
70+
+
71+
+ // Check if data is an array (multiple releases) or single object
72+
+ let releases = Array.isArray(data) ? data : [data];
73+
+
74+
+ if (releases.length === 0) {
75+
+ ui.showModal(_('No releases found'), [
76+
+ E('p', _('No firmware releases found on GitHub')),
77+
+ E('div', { class: 'right' }, [
78+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
79+
+ ]),
80+
+ ]);
81+
+ return;
82+
+ }
83+
+
84+
+ // Create a dropdown to select the release
85+
+ let releaseSelect = E('select', { 'class': 'cbi-input-select' });
86+
+
87+
+ // Populate the dropdown with available releases
88+
+ releases.forEach((release, index) => {
89+
+ let optionText = release.tag ? `${release.tag} (${release.version})` : release.version;
90+
+ releaseSelect.appendChild(E('option', { 'value': index }, optionText));
91+
+ });
92+
+
93+
+ let keep = E('input', { type: 'checkbox' });
94+
+ keep.checked = true;
95+
+
96+
+ // Create element for the URL
97+
+ const urlElement = E('td', { class: 'td left' });
98+
+
99+
+ // Function to update the URL based on selected release
100+
+ const updateDetails = function() {
101+
+ const selectedIndex = releaseSelect.value;
102+
+ const selectedRelease = releases[selectedIndex];
103+
+
104+
+ if (selectedRelease) {
105+
+ // Clear previous link and create a new one
106+
+ urlElement.innerHTML = '';
107+
+ urlElement.appendChild(E('a', { href: 'https://github.com/XXXXXX/YYYYYY/releases/tag/' + selectedRelease.tag, target: '_blank' }, _('View on GitHub')));
108+
+ }
109+
+ };
110+
+
111+
+ // Add event listener to update details when selection changes
112+
+ releaseSelect.addEventListener('change', updateDetails);
113+
+
114+
+ let modal_body = [
115+
+ E('p', _('Select a firmware release to install:')),
116+
+ E('div', { class: 'table' }, [
117+
+ E('tr', { class: 'tr' }, [
118+
+ E('td', { class: 'td left', width: '33%' }, _('Release')),
119+
+ E('td', { class: 'td left' }, [releaseSelect])
120+
+ ])
121+
+ ]),
122+
+ E('div', { class: 'table mt-2' }, [
123+
+ E('tr', { class: 'tr' }, [
124+
+ E('td', { class: 'td left', width: '33%' }, _('URL')),
125+
+ urlElement
126+
+ ])
127+
+ ]),
128+
+ E(
129+
+ 'p',
130+
+ { class: 'mt-2' },
131+
+ E('label', { class: 'btn' }, [
132+
+ keep,
133+
+ ' ',
134+
+ _('Keep settings and retain the current configuration'),
135+
+ ])
136+
+ ),
137+
+ E('div', { class: 'right' }, [
138+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Cancel')),
139+
+ ' ',
140+
+ E(
141+
+ 'button',
142+
+ {
143+
+ class: 'btn cbi-button cbi-button-positive important',
144+
+ click: ui.createHandlerFn(this, function () {
145+
+ const selectedIndex = releaseSelect.value;
146+
+ const selectedRelease = releases[selectedIndex];
147+
+
148+
+ if (selectedRelease && selectedRelease.tag) {
149+
+ this.handleGithubInstall(selectedRelease.tag, keep.checked);
150+
+ } else {
151+
+ ui.showModal(_('Error'), [
152+
+ E('p', _('Invalid release selected')),
153+
+ E('div', { class: 'right' }, [
154+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
155+
+ ]),
156+
+ ]);
157+
+ }
158+
+ }),
159+
+ },
160+
+ _('Install selected firmware')
161+
+ ),
162+
+ ]),
163+
+ ];
164+
+
165+
+ // Initialize details for the initially selected release (first option)
166+
+ updateDetails();
167+
+
168+
+ ui.showModal(_('Available GitHub Releases'), modal_body);
169+
+ })
170+
+ .catch(error => {
171+
+ ui.showModal(_('Error'), [
172+
+ E('p', _('Error fetching firmware info: %s').format(error.message)),
173+
+ E('div', { class: 'right' }, [
174+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
175+
+ ]),
176+
+ ]);
177+
+ });
178+
+ },
179+
+
180+
+ handleGithubInstall: function(tag, keep) {
181+
+ ui.showModal(_('Downloading from GitHub...'), [
182+
+ E(
183+
+ 'p',
184+
+ { class: 'spinning' },
185+
+ _('Downloading firmware from GitHub to device')
186+
),
187+
]);
188+
+
189+
+ // Call the CGI script to download the firmware to /tmp/firmware.bin
190+
+ // Pass the selected tag as a parameter to the github_fetch script
191+
+ fetch(`/cgi-bin/github_fetch?tag=${encodeURIComponent(tag)}`)
192+
+ .then(response => response.json())
193+
+ .then(data => {
194+
+ if (data.error) {
195+
+ ui.showModal(_('Error'), [
196+
+ E('p', _('Error downloading firmware: %s').format(data.error)),
197+
+ E('div', { class: 'right' }, [
198+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
199+
+ ]),
200+
+ ]);
201+
+ return;
202+
+ }
203+
+
204+
+ if (data.success) {
205+
+ // Firmware is already downloaded to the device and SHA256 verified by the CGI script
206+
+ // Path returned by the CGI script: ${data.path || '/tmp/firmware.bin'}
207+
+ ui.showModal(_('Installing...'), [
208+
+ E('div', { class: 'spinning' }, [
209+
+ E('p', _('Installing the sysupgrade image...')),
210+
+ E('p',
211+
+ _('Once the image is written, the system will reboot.')
212+
+ + ' ' +
213+
+ _('This should take at least a minute, so please wait for the login screen.')
214+
+ ),
215+
+ E('b', _('While you are waiting, do not unpower device!')),
216+
+ ]),
217+
+ ]);
218+
+
219+
+ L.resolveDefault(callUpgradeStart(keep), {}).then((response) => {
220+
+ // Wait 10 seconds before we try to reconnect...
221+
+ let hosts = keep ? [] : ['192.168.1.1', 'openwrt.lan'];
222+
+ setTimeout(() => { ui.awaitReconnect(...hosts); }, 10000);
223+
+ });
224+
+ } else {
225+
+ ui.showModal(_('Error'), [
226+
+ E('p', _('Unexpected response from firmware download script')),
227+
+ E('div', { class: 'right' }, [
228+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
229+
+ ]),
230+
+ ]);
231+
+ }
232+
+ })
233+
+ .catch(error => {
234+
+ ui.showModal(_('Download Error'), [
235+
+ E('p', _('Error downloading firmware from GitHub: %s').format(error.message)),
236+
+ E('div', { class: 'right' }, [
237+
+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
238+
+ ]),
239+
+ ]);
240+
+ });
241+
},
242+
+
243+
handleSaveApply: null,
244+
handleSave: null,
245+
handleReset: null,

files/etc/uci-defaults/999-QOL_config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ set firewall.@zone[1].forward='DROP'
3737
# uHTTPd settings
3838
set uhttpd.main.redirect_https='1'
3939

40+
commit wireless
41+
commit firewall
42+
commit uhttpd
4043
EOI

files/usr/bin/upgrade_custom_openwrt

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if [ -e /var/run/upgrade_openwrt ]; then
44
printf "*** UPGRADE SCRIPT ALREADY RUNNING ***\n*** Delete '/var/run/upgrade_openwrt' if not. ***\n"
55
else
66
touch /var/run/upgrade_openwrt
7-
GITHUBREPOSITORY='XXXXXX/XXXXXX'
7+
GITHUBREPOSITORY='XXXXXX/YYYYYY'
88
eval "$(grep -m 1 DISTRIB_REVISION /etc/openwrt_release)"
99
SYSUPGRADEFILE=$(curl -sS https://api.github.com/repos/${GITHUBREPOSITORY}/releases/latest | jq -r --arg exclude "$DISTRIB_REVISION" '.assets[] | select(.browser_download_url | contains("sysupgrade")) | select((($exclude | length) == 0) or (.browser_download_url | contains($exclude) | not)) | .browser_download_url')
1010

0 commit comments

Comments
 (0)