Allow packages to be removed on low memory nodes. (#1684)

We haven't supported installing packages on low memory node for a few years now, but
we will want to provide a mechanism to remove them even with the new UI.
This commit is contained in:
Tim Wilkinson 2024-11-11 18:50:13 -08:00 committed by GitHub
parent 83c8dc2d17
commit 25572f014e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 20 deletions

View File

@ -235,6 +235,7 @@ const po = getPackageOptions();
{{_R("dialog-header", "Packages")}} {{_R("dialog-header", "Packages")}}
<div id="package-update"> <div id="package-update">
{{_R("dialog-messages")}} {{_R("dialog-messages")}}
{% if (!hardware.isLowMemNode()) { %}
<div class="cols"> <div class="cols">
<div> <div>
<div class="o">Download Package</div> <div class="o">Download Package</div>
@ -263,6 +264,7 @@ const po = getPackageOptions();
{{_H("Upload a package file from your computer. Once the package has been selected it can be uploaded and installed {{_H("Upload a package file from your computer. Once the package has been selected it can be uploaded and installed
using the button at the base of the dialog.")}} using the button at the base of the dialog.")}}
<div><hr></div> <div><hr></div>
{% } %}
<div class="cols"> <div class="cols">
<div> <div>
<div class="o">Remove Package</div> <div class="o">Remove Package</div>
@ -274,6 +276,7 @@ const po = getPackageOptions();
</div> </div>
{{_H("Remove a currently installed package from the node by first selecting it and {{_H("Remove a currently installed package from the node by first selecting it and
then using the button at the based of the dialog to remove it.")}} then using the button at the based of the dialog to remove it.")}}
{% if (!hardware.isLowMemNode()) { %}
{{_R("dialog-advanced")}} {{_R("dialog-advanced")}}
<div> <div>
{% if (includeAdvanced) { %} {% if (includeAdvanced) { %}
@ -290,13 +293,14 @@ const po = getPackageOptions();
to a local server, especially if you'd like to do this without a connection to the Internet.")}} to a local server, especially if you'd like to do this without a connection to the Internet.")}}
{% } %} {% } %}
</div> </div>
{% } %}
<div style="flex:1"></div> <div style="flex:1"></div>
<div class="cols" style="padding-top:16px"> <div class="cols" style="padding-top:16px">
<div id="package-upload"> <div id="package-upload">
<progress value="0" max="100"> <progress value="0" max="100">
</div> </div>
<div style="flex:0"> <div style="flex:0">
<button id="fetch-and-update" disabled hx-trigger="none" hx-encoding="multipart/form-data">Fetch and Install</button> <button id="fetch-and-update" disabled hx-trigger="none" hx-encoding="multipart/form-data">{{!hardware.isLowMemNode() ? 'Fetch and Install' : 'Remove'}}</button>
</div> </div>
</div> </div>
{{_H("<br>Depending on the package option selected above, this button will initiate the download, upload, install or remove process.")}} {{_H("<br>Depending on the package option selected above, this button will initiate the download, upload, install or remove process.")}}
@ -394,7 +398,7 @@ const po = getPackageOptions();
source: e.currentTarget, source: e.currentTarget,
swap: "none" swap: "none"
}).then(_ => { }).then(_ => {
htmx.find("#fetch-and-update").innerText = "Fetch and Install"; htmx.find("#fetch-and-update").innerText = !hardware.isLowMemNode() ? "Fetch and Install" : "Remove";
htmx.find("#remove-package").value = "-"; htmx.find("#remove-package").value = "-";
}); });
} }

View File

@ -51,10 +51,6 @@
{{_R("health")}} {{_R("health")}}
</div> </div>
{{_R("firmware")}} {{_R("firmware")}}
{% if (auth.isAdmin && !hardware.isLowMemNode()) { %}
<div id="packages" class="ctrl" hx-get="status/e/packages" hx-target="#ctrl-modal">
{{_R("packages")}} {{_R("packages")}}
</div>
{% } %}
<hr> <hr>
{{_R("network")}} {{_R("network")}}

View File

@ -33,21 +33,26 @@
*/ */
%} %}
{% {%
let count = 0; if (auth.isAdmin) {
if (!fs.access("/etc/cron.boot/reinstall-packages")) { let count = 0;
const opkgs = {}; if (!fs.access("/etc/cron.boot/reinstall-packages")) {
map(split(fs.readfile("/etc/permpkg"), "\n"), p => opkgs[p] = true); const opkgs = {};
const f = fs.popen("/bin/opkg list-installed"); map(split(fs.readfile("/etc/permpkg"), "\n"), p => opkgs[p] = true);
if (f) { const f = fs.popen("/bin/opkg list-installed");
for (let l = f.read("line"); length(l); l = f.read("line")) { if (f) {
const m = match(l, /^[^ \t]+/); for (let l = f.read("line"); length(l); l = f.read("line")) {
if (m && !opkgs[m[0]]) { const m = match(l, /^[^ \t]+/);
count++; if (m && !opkgs[m[0]]) {
count++;
}
} }
f.close();
} }
f.close();
} }
} if (count > 0 || !hardware.isLowMemNode()) {
%} %}
<div class="t">{{count}}</div> <div id="packages" class="ctrl" hx-get="status/e/packages" hx-target="#ctrl-modal">
<div class="s">installed packages</div> <div class="t">{{count}}</div>
<div class="s">installed packages</div>
</div>
{% } } %}