[shellprocess] Migrate towards 'standard' variable substitutions

This commit is contained in:
Adriaan de Groot 2022-04-12 13:13:01 +02:00
parent 3bf0a93b86
commit bb278c7ba9
3 changed files with 16 additions and 14 deletions

View File

@ -146,14 +146,14 @@ script:
QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).value( "script" ); QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).value( "script" );
QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(--- QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
script: script:
- "ls @@ROOT@@" - "ls ${ROOT}"
)" ) ) )" ) )
.value( "script" ); .value( "script" );
QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(--- QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
script: script:
- mktemp -d @@ROOT@@/calatestXXXXXXXX - mktemp -d ${ROOT}/calatestXXXXXXXX
- "chown @@USER@@ @@ROOT@@/calatest*" - "chown ${USER} ${ROOT}/calatest*"
- rm -rf @@ROOT@@/calatest* - rm -rf ${ROOT}/calatest*
)" ) ) )" ) )
.value( "script" ); .value( "script" );
@ -167,13 +167,13 @@ script:
qDebug() << "Expect WARNING, ERROR, WARNING"; 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() ) ); 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() ) ); 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() ) ); QVERIFY( !bool( CommandList( rootScript, false, 10s ).run() ) );
// .. fails for two reasons // .. fails for two reasons
QVERIFY( !bool( CommandList( rootScript, true, 10s ).run() ) ); QVERIFY( !bool( CommandList( rootScript, true, 10s ).run() ) );

View File

@ -31,7 +31,7 @@ private Q_SLOTS:
void testProcessFromObject(); void testProcessFromObject();
// Create from a complex YAML list // Create from a complex YAML list
void testProcessListFromObject(); void testProcessListFromObject();
// Check @@ROOT@@ substitution // Check variable substitution
void testRootSubstitution(); void testRootSubstitution();
}; };

View File

@ -7,11 +7,13 @@
# If the top-level key *dontChroot* is true, then the commands # If the top-level key *dontChroot* is true, then the commands
# are executed in the context of the live system, otherwise # are executed in the context of the live system, otherwise
# in the context of the target system. In all of the commands, # in the context of the target system. In all of the commands,
# the following substitutions will take place: # the following variable expansions will take place:
# - `@@ROOT@@` is replaced by the root mount point of the **target** # - `ROOT` is replaced by the root mount point of the **target**
# system from the point of view of the command (for chrooted # system from the point of view of the command (when run in the target
# commands, that will be */*). # system, e.g. when *dontChroot* is false, that will be `/`).
# - `@@USER@@` is replaced by the username, set on the user page. # - `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 (global) timeout for the command list can be set with
# the *timeout* key. The value is a time in seconds, default # 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 # ignored; the slowloris command has a different timeout from the
# other commands in the list): # other commands in the list):
script: script:
- "-touch @@ROOT@@/tmp/thingy" - "-touch ${ROOT}/tmp/thingy"
- "/usr/bin/true" - "/usr/bin/true"
- command: "/usr/local/bin/slowloris" - command: "/usr/local/bin/slowloris"
timeout: 3600 timeout: 3600