From a1915f070b4c51c9b640f8fd0d37ecdbe5b30d4c Mon Sep 17 00:00:00 2001 From: Aemeath <35622087+tickcount@users.noreply.github.com> Date: Thu, 22 Oct 2026 00:20:51 +0300 Subject: [PATCH] Dawnline 0.14.1 - The updater started without a command, with one it doesn't know, or with an install of nothing prints its usage and exits. It no longer counts that as a failed update: nothing goes into the service log, Activity or the update history, and Components shows no failed job. `updater --help` prints the same usage --- package/luci-app-dawnline/Makefile | 2 +- .../root/usr/libexec/dawnline/updater | 21 ++++++++++- .../root/usr/share/ucode/dawnline/util.uc | 2 +- tests/ucode/updater.test.uc | 36 +++++++++++++++++++ web/package-lock.json | 4 +-- web/package.json | 2 +- 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 tests/ucode/updater.test.uc diff --git a/package/luci-app-dawnline/Makefile b/package/luci-app-dawnline/Makefile index 3113dc0..b0d1a79 100644 --- a/package/luci-app-dawnline/Makefile +++ b/package/luci-app-dawnline/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-dawnline -PKG_VERSION:=0.14.0 +PKG_VERSION:=0.14.1 PKG_RELEASE:=1 PKG_LICENSE:=MIT # po//dawnline.po becomes luci-i18n-dawnline- (luci.mk), released diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/updater b/package/luci-app-dawnline/root/usr/libexec/dawnline/updater index 43b4b88..b44c862 100755 --- a/package/luci-app-dawnline/root/usr/libexec/dawnline/updater +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/updater @@ -24,6 +24,25 @@ import * as pkgs from 'dawnline.upd_pkgs'; import * as i18n from 'dawnline.i18n'; import { _, L_ } from 'dawnline.i18n'; +const USAGE = `Usage: + updater check [app|amneziawg|packages] + updater install app | app@ | app:reinstall | app:rollback + updater install amneziawg[:auto|slava|grey[:ru]] | amneziawg:rollback + updater install pkgs: + updater auto +`; + +// No command, one it doesn't know, or an install of nothing: the usage and exit, before anything is read or +// written (no job for Components, no history, nothing in the service log). Asked for help: the same, on stdout. +if (index([ '-h', '--help', 'help' ], ARGV[0]) >= 0) { + print(USAGE); + exit(0); +} +if (index([ 'check', 'install', 'auto' ], ARGV[0]) < 0 || (ARGV[0] == 'install' && !length(ARGV[1] ?? ''))) { + warn(USAGE); + exit(2); +} + // The phases and errors of a job LuCI started are in the admin's language (rpc/updates.uc hands it over). i18n.use(getenv('DAWNLINE_LANG')); @@ -313,7 +332,7 @@ function main() { else if (job.action == 'auto') auto(); else - die('Usage: updater check [app|amneziawg|packages] | install | auto'); + die(USAGE); job.state = 'done'; phase(_('Finished')); } diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc index 5805cf9..42f8804 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc @@ -5,7 +5,7 @@ import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs'; import { _ } from 'dawnline.i18n'; -export const VERSION = '0.14.0'; +export const VERSION = '0.14.1'; /** GitHub repository with Dawnline releases (updates and the installer). */ export const REPO = 'tickcount/luci-app-dawnline'; export const RUN_DIR = '/var/run/dawnline'; diff --git a/tests/ucode/updater.test.uc b/tests/ucode/updater.test.uc new file mode 100644 index 0000000..d71b75c --- /dev/null +++ b/tests/ucode/updater.test.uc @@ -0,0 +1,36 @@ +// usr/libexec/dawnline/updater: a call without a command it knows prints the usage and changes nothing (no job for +// Components, no history, no "update failed" in the service log). +import * as fs from 'fs'; + +const REPO = `${sourcepath(0, true)}/../..`; +const UPDATER = `${REPO}/package/luci-app-dawnline/root/usr/libexec/dawnline/updater`; +const MODULES = `${REPO}/package/luci-app-dawnline/root/usr/share/ucode/*.uc`; +const JOB = '/var/run/dawnline/update-job.json'; + +/** The updater run with `args`: { code, out } (stdout and stderr together). */ +function updater(args) { + let p = fs.popen(`ucode -L '${MODULES}' '${UPDATER}' ${args} 2>&1; echo "exit=$?"`, 'r'); + let out = p.read('all') ?? ''; + p.close(); + let m = match(out, /exit=([0-9]+)\s*$/); + return { code: m ? +m[1] : -1, out: replace(out, /exit=[0-9]+\s*$/, '') }; +} + +test('without a command it knows: the usage, nothing written', () => { + for (let args in [ '', 'frobnicate', 'install', "install ''" ]) { + fs.unlink(JOB); + let r = updater(args); + eq(r.code, 2, `exit code for "${args}"`); + ok(index(r.out, 'Usage:') == 0, `usage for "${args}"`); + ok(index(r.out, 'updater install app | app@') > 0, `the commands for "${args}"`); + ok(!fs.access(JOB), `no job for "${args}"`); + } +}); + +test('asked for help: the usage, exit 0', () => { + for (let args in [ '-h', '--help', 'help' ]) { + let r = updater(args); + eq(r.code, 0, `exit code for "${args}"`); + ok(index(r.out, 'Usage:') == 0, `usage for "${args}"`); + } +}); diff --git a/web/package-lock.json b/web/package-lock.json index 57100bf..2c8cb76 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "dawnline-web", - "version": "0.14.0", + "version": "0.14.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dawnline-web", - "version": "0.14.0", + "version": "0.14.1", "license": "MIT", "dependencies": { "qrcode-generator": "1.4.4" diff --git a/web/package.json b/web/package.json index f0948b6..a7f22c4 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "dawnline-web", - "version": "0.14.0", + "version": "0.14.1", "private": true, "license": "MIT", "type": "module",