How to assigning a variable within a qube via dom0 (qvm-run)

I have separated and simplified an issue in my dom0 script.

Run test script in dom0:

#!/bin/bash

QVM="test-qube"

# create test qube
qvm-create ${QVM} --template debian-11 --label red

# test variable
qvm-run --pass-io --user user ${QVM} \
"VAR=123TEST"

# check VAR
qvm-run --pass-io --user user ${QVM} \
"echo VAR is: ${VAR}"

How to do the variable assignment via dom0?

1 Like

So what’s happening is that ${VAR} gets replaced with the value in dom0 before it’s passed to the qube. If VAR is not defined in dom0 nothing gets passed and the qube sees an empty "echo ".

[user@dom0 ~]$ VAR=123DOM0
[user@dom0 ~]$ qvm-run -p online "VAR=123TEST && echo $VAR"
123DOM0

To pass the actual variable name you need to escape the dollar sign:

[user@dom0 ~]$ qvm-run -p online "VAR=123TEST && echo \$VAR" 
123TEST

The other problem you have is that the variable is transient. To be able to use it all uses have to be in the same qvm-run call. Think of it as a new shell being opened for each qvm-run call.

[user@dom0 ~]$ qvm-run -p online "VAR=123TEST" 
[user@dom0 ~]$ qvm-run -p online "echo \$VAR" 

@whoami one possible solution here is to have all actions in a bash script that is stored somewhere in dom0, then qvm-copy-to-vm it into the target qube, make it executable and run it. Good luck!

Ok, thanks a lot @Sven !

These two information I missed:

#1

#2

Finally, it works :partying_face:

#!/bin/bash

# make a new (default) qube or use any standard AppVM (curl must be installed)
QVM="my-new-qube"

#URI_APPIMAGE="https://mail.tutanota.com/desktop/tutanota-desktop-linux.AppImage"
URI_APPIMAGE="https://releases.threema.ch/web-electron/v1/release/Threema-Latest.deb"

# get the file size (in MB)
qvm-run --no-gui --pass-io --quiet --user user ${QVM} \
"APPIMAGE_SIZE=\$(curl --silent --head --location ${URI_APPIMAGE} | \
grep --ignore content-length | \
sed s/[^0-9]//g | \
numfmt --to=si |& tail -1) && \
echo ...this is the file size: \${APPIMAGE_SIZE} && \
echo of ${URI_APPIMAGE}"

… one step further :slight_smile:

I hope I reach a phase soon to share my script with you. It will include examples of add key-repo, install deb (directly), install AppImages … There are still many ideas and “#TODO” listed in my code …

1 Like