Is it possible to run a script from dom0 in a template? I was playing around with qvm-run -u root template xfce4-terminal --command="bash -c 'command'"
and was wondering if one could run a whole script which is residing in dom0 in a template.
By default, no. There is an open issue about this (with some suggested workarounds):
You can trivially do this with a salt call to
cmd.script
salt://PATH_TO_SCRIPT;
cmd.script
There are many things I do not understand about Salt, and this is yet another one, but it re-ignites my motivation to get a handle on salt. Thank you.
More generally, does anyone know some documentation source, or a heavily commented set of files which might have helped me discover this?
…and which would help me more generally to understand the concepts behind and underlying salt.
[ I’ve tried the salt upstream, and various other sites, but I found myself confused by a lot of the docs and guides which seem to confound the concepts I am familiar with, like execution, state, action, etc.
Maybe it’s more obvious if one comes from ansible or something similar, but I don’t… and every time I try to work out what is happening in Salt it makes me feel really stupid! ]
Well, yes… with an artifice. Read on.
Yeah, I gave up on salt, and until Ansible is fully supported, I use dom0 scripts to set up custom templates (for Librewolf, Brave etc). To run scripts, I use a construct like this:
# [...]
# Let's say I want to run the script /home/user/scripts/setup_brave_tpl.sh ...
# ... in a clone of debian-12-minimal called deb12min-brave
dom0scr="/home/user/scripts/setup_brave_tpl.sh"
bravetpl="deb12min-brave"
cat $dom0scr | \
qvm-run --pass-io -u root $bravetpl "cat >> /root/setup.sh"
echo "chmod 755 /root/setup.sh && /root/setup.sh" | \
qvm-run --pass-io -u root $bravetpl bash
# [...]
Error handling is weak, but I use this for simple things and salt error handling is not great either
EDIT: the source script is in dom0:/home/user/scripts, not in /root!
I apologise to @qubesfan35267 - I only meant to say thanks to Unman, but then I got carried away. I did not mean to hijack.
For my problem with salt I made a new topic, here :
Ok thank you for your replies, very helpful. But I wanted to keep it simple so I came up with a little work around that seems sufficient to me. I wrote a little script - it copies the script from dom0 to the template, executes it and afterwards it deletes everything:
#!/bin/bash
echo "Name template you want to setup:"
read qube
echo "Name path to script:"
read pathtoscript
qvm-run -u root $qube xterm -e "rm /home/user/QubesIncoming/dom0/*.*"
qvm-copy-to-vm $qube $pathtoscript
qvm-run -u root $qube xterm -e "bash /home/user/QubesIncoming/dom0/*.sh && rm /home/user/QubesIncoming/dom0/*.sh && rmdir /home/user/QubesIncoming/dom0 && poweroff"
Feel free to comment!
I think I made a similar script once…
For sure, I made it to use command line arguments, because it means I can use ctrl-r key in bash shell to modify or to repeat my previous commands. (history command is very useful, but it took me years to discover ctrl-r, and it changed my life.)
If I had your script, it is 100% sure I will one day give the name of “the qube where I am doing a really important work assignment”, and poweroff
will spoil my day. I would surely test that the name is for a template, and only do poweroff if it is true.
Ah, the voice of experience Been there, too.