cli: add support for --reset-volumes on container upgrade

The weird `if env | grep -q 'reset-volumes'` construct is due to Klish
not sanitizing names before constructing variables, which leads to env
variables with '-' in them, not allowed in POSIX sh.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-03-01 06:58:21 +01:00
parent 8fac3720fb
commit a5687bda7f
2 changed files with 25 additions and 1 deletions
+7 -1
View File
@@ -179,8 +179,14 @@
<COMMAND name="upgrade" help="Upgrade image of a container (writable layer is lost!)">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<SWITCH name="optional" min="0" max="1">
<COMMAND name="reset-volumes" help="Delete named volumes, re-initialize from new image (all config lost!)" />
</SWITCH>
<ACTION sym="script" out="tty" interrupt="true">
doas container upgrade $KLISH_PARAM_name
if env | grep -q 'reset-volumes' >/dev/null; then
opt="-R"
fi
doas container $opt upgrade $KLISH_PARAM_name
</ACTION>
</COMMAND>
</COMMAND>