Run Script From Template

In my default template, I created a small script to run in the terminal and would like to be able to use it via the application menu to give it to qubes. My current issue is that although I can get it to show up in the application menu by creating a desktop file, this does not seem to add the script to the PATH where it can be executed from the terminal in the qube.

[Desktop Entry]
Name=Upload File
Exec=/usr/local/bin/upfile
Terminal=true
Type=Application
Categories=Utility;Network

Is there a way to use the script from the terminal after adding it through the application menu?

/usr/local/bin/ is part of the persistent storage of AppVMs or DVM templates, so putting a file there in a base template will not make it available to qubes based on it. Instead, consider using the skel mechanism (search the forum or docs for this term).

Thanks for pointing that out. Using the script with the skel mechanism should allow qubes to inherit it, but seems to lose the advantage of the application menu. In addition, it would also give all qubes the script, so I would probably have to make another template based off my current default one specialized for the one script.

The script is made with a suite of others though, so skel should actually work quite well because I will not have to drag every script which would be a downside of the application menu.

If only some, already existing qubes should have the script, you could simply place that script into the /usr/local/bin of those qubes alone, while also putting the desktop file into /usr/local/share/applications/ of those same qubes.

This can be automated with Salt Stack; a less advanced method would be to do something like (from dom0 terminal, assuming the script and desktop file are in dom0)

#!/bin/bash
qvm-copy-to-vm $1 script.sh desktopfile.desktop
qvm-run $1 -- sudo mv ~/QubesIncoming/dom0/script.sh /usr/local/bin/
qvm-run $1 -- sudo mv ~/QubesIncoming/dom0/desktopfile.desktop /usr/local/share/applications/

as a dom0 script, which you call with the targetVM name…don’t forget to make your script.sh executable beforehand in dom0 (chmod +x script.sh).

Another possibility is to put the script in /usr/local.orig/bin. (I generally install “my” scripts and so forth there because there are a LOT of them and it keeps them readily distinguishable from the “regular” “professional” stuff in /usr/bin, while still being in my path.)

It will get copied into /usr/local/bin when the AppVM is created.

(This does mean if you want to add something else to /usr/local.orig/bin in the template after you have created the AppVM (or disposable template), you have to either recreate the AppVM (or disposable template) from scratch or go into it and copy it from /usr/local.orig/bin to /usr/local/bin.)