From bb278c7ba9f4fc36dbe060304cf5f73da2d9460e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Apr 2022 13:13:01 +0200 Subject: [PATCH] [shellprocess] Migrate towards 'standard' variable substitutions --- src/modules/shellprocess/Tests.cpp | 14 +++++++------- src/modules/shellprocess/Tests.h | 2 +- src/modules/shellprocess/shellprocess.conf | 14 ++++++++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/modules/shellprocess/Tests.cpp b/src/modules/shellprocess/Tests.cpp index c1489c1ab..5d3a503fd 100644 --- a/src/modules/shellprocess/Tests.cpp +++ b/src/modules/shellprocess/Tests.cpp @@ -146,14 +146,14 @@ script: QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).value( "script" ); QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(--- script: - - "ls @@ROOT@@" + - "ls ${ROOT}" )" ) ) .value( "script" ); QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(--- script: - - mktemp -d @@ROOT@@/calatestXXXXXXXX - - "chown @@USER@@ @@ROOT@@/calatest*" - - rm -rf @@ROOT@@/calatest* + - mktemp -d ${ROOT}/calatestXXXXXXXX + - "chown ${USER} ${ROOT}/calatest*" + - rm -rf ${ROOT}/calatest* )" ) ) .value( "script" ); @@ -167,13 +167,13 @@ script: qDebug() << "Expect WARNING, ERROR, WARNING"; - // Doesn't use @@ROOT@@, so no failures + // Doesn't use ${ROOT}, so no failures QVERIFY( bool( CommandList( plainScript, false, 10s ).run() ) ); - // Doesn't use @@ROOT@@, but does chroot, so fails + // Doesn't use ${ROOT}, but does chroot, so fails QVERIFY( !bool( CommandList( plainScript, true, 10s ).run() ) ); - // Does use @@ROOT@@, which is not set, so fails + // Does use ${ROOT}, which is not set, so fails QVERIFY( !bool( CommandList( rootScript, false, 10s ).run() ) ); // .. fails for two reasons QVERIFY( !bool( CommandList( rootScript, true, 10s ).run() ) ); diff --git a/src/modules/shellprocess/Tests.h b/src/modules/shellprocess/Tests.h index cabeaada2..c44fa853b 100644 --- a/src/modules/shellprocess/Tests.h +++ b/src/modules/shellprocess/Tests.h @@ -31,7 +31,7 @@ private Q_SLOTS: void testProcessFromObject(); // Create from a complex YAML list void testProcessListFromObject(); - // Check @@ROOT@@ substitution + // Check variable substitution void testRootSubstitution(); }; diff --git a/src/modules/shellprocess/shellprocess.conf b/src/modules/shellprocess/shellprocess.conf index 07947f38f..9ff83221e 100644 --- a/src/modules/shellprocess/shellprocess.conf +++ b/src/modules/shellprocess/shellprocess.conf @@ -7,11 +7,13 @@ # If the top-level key *dontChroot* is true, then the commands # are executed in the context of the live system, otherwise # in the context of the target system. In all of the commands, -# the following substitutions will take place: -# - `@@ROOT@@` is replaced by the root mount point of the **target** -# system from the point of view of the command (for chrooted -# commands, that will be */*). -# - `@@USER@@` is replaced by the username, set on the user page. +# the following variable expansions will take place: +# - `ROOT` is replaced by the root mount point of the **target** +# system from the point of view of the command (when run in the target +# system, e.g. when *dontChroot* is false, that will be `/`). +# - `USER` is replaced by the username, set on the user page. +# +# Variables are written as `${var}`, e.g. `${ROOT}`. # # The (global) timeout for the command list can be set with # the *timeout* key. The value is a time in seconds, default @@ -72,7 +74,7 @@ dontChroot: false # ignored; the slowloris command has a different timeout from the # other commands in the list): script: - - "-touch @@ROOT@@/tmp/thingy" + - "-touch ${ROOT}/tmp/thingy" - "/usr/bin/true" - command: "/usr/local/bin/slowloris" timeout: 3600