XFCE Menu system. Adding and altering the QubesManager to allow for the changes?

Wanting to get something like this added into the manager, just to execute the script for different things when they happen. the script itself I have built adds and removes the appropriate VM menus on the fly when it’s run, and I can cron it to run every few seconds.
However I would like to be able to run it when a guest starts or stops, and every time.
Also, to allow for the ability to have multiple locations for the menus themselves as well.

So at this time I have the following…

  1. Get the powered on guests.
  2. Have one folder that has all the configurations in it.
  3. Link back to the main folder for the ones that are active.
  4. Remove the links that are not powered on.

This reduces the size of the menu system to only what is powered on at the time.

Useful for those people that have many virtuals, but don’t always have them all turned on. So why have them in the menu when they can all be configured and powered on from the manager?

I know it’s not the prettiest way to achieve the desired result, but it works…

Firstly, add in to the /etc/xdg/menus/qubes-applications.menu the following…
Under “” tag" Powered Off" I put mine BEFORE the “” that preceeds the “”
So it looks like…

<Layout>
        <Filename>xfce4-run.desktop</Filename>
        <Filename>exo-terminal-emulator.desktop</Filename>
        <Separator/>
        <Menuname>System Tools</Menuname>
        <Menuname>Qubes Tools</Menuname>
        <Menuname>Powered Off</Menuname>
        <Separator/>
        <Merge type="all"/>
        <Separator/>
        <Filename>xfce4-session-logout.desktop</Filename>
    </Layout>

This enables me to have the Powered Off folder available.
Altering the Applications in the SETTINGS of the machine will revert it back to the live area as it doesn’t retain the folder. But this could be changed I’m sure. However with the script it doesn’t really matter too much. As you can have it running every 30 seconds for what it mattered.

The actual script to run is as follows.
If I could run a script whenever a machine is altered, shutdown or started, then I would alter the script to perform the actions based on that, but at this time, this is what I have.
Anyone that has any suggestions on how to add it into the Qubes Startup and Shutdown and Settings Alteration of guests, I would be happy to hear.

#!/bin/sh
list=`xl list | grep -iw -Eo "^([^ ]+) " | awk 'NR>2'`
active=()
for ix in $list
do
 active+=user-qubes-vm-directory-$ix.menu
done
lcv=1
lists=`find ~/.config/menus/applications-merged/user-qubes-*.menu*`
for i in $lists
do
    sed -i -e 's/<Menu><Name>Powered Off<\/Name>//g' $i
    sed -i -e 's/<\/Menu>//g' $i
  if ! [[ ${active[*]} =~ ${i##*/} ]]; then
    echo "Disabling ${i##*/}"
    sed -i -e 's/<Name>Applications<\/Name>/<Name>Applications<\/Name><Menu><Name>Powered Off<\/Name>/g' $i
    echo "</Menu></Menu></Menu>" >> $i
  elif [[ ${active[*]} =~ ${i##*/} ]]; then
    echo "Enabling ${i##*/}"
    sed -i -e 's/<Name>Applications<\/Name><Menu><Name>Powered Off<\/Name>/<Name>Applications<\/Name>/g' $i
    echo "</Menu></Menu>" >> $i
  fi
done

You can use libxl hook:

So that would run every time an action in the Qubes Manager is performed on the guest, including the Applications tab?

/etc/libvirt/hooks/libxl Executed when a libxl-handled Xen guest is started, stopped, or migrated

libvirt/docs/hooks.rst at master · libvirt/libvirt · GitHub

1 Like

Thanks for the details, works beautifully now.

It’s not the prettiest thing, but it’s fully functional
I have a logging function and line in there for the debug in case needed.

#!/bin/bash
guest_name="$1"
libvirt_operation="$2"
mydatetime=$(date '+%Y-%m-%d %H:%M:%S') #'%Y-%m-%d %H:%m:%s')
function adl(){
  #echo "$1" >> /allaccess/debug.log
}
adl "dbg[init]: $libvirt_operation $guest_name"
echo "$mydatetime $libvirt_operation" >> /allaccess/$guest_name.log
#ls -alh ~ >> /allaccess/ls.log
states=()
states+="started"
states+="stopped"

if [[ ${states[*]} =~ "$libvirt_operation" ]]; then
  ## Get all menu files for the virtual.
  lists=`find /home/*/.config/menus/applications-merged/*.menu -type f | grep -E "user\-qubes\-(vm|dispvm)\-directory-$guest_name.menu"`
  adl "dbg[lists]: $lists"

  for i in $lists
  do
    adl "dbg[i]: $i"
    ## Return the virtual to being in ACTIVE state in the menu.
    sed -i -e 's/<Menu><Name>Powered Off<\/Name>//g' $i
    sed -i -e 's/<\/Menu>//g' $i
    ## If Powered Off, add the Powered Off Menu Option.
    if ! [[ ${active[*]} =~ ${i##*/} ]]; then
      adl "dbg: Disabling ${i##*/}"
      sed -i -e 's/<Name>Applications<\/Name>/<Name>Applications<\/Name><Menu><Name>Powered Off<\/Name>/g' $i
      echo "</Menu></Menu></Menu>" >> $i
      echo "$mydatetime $libvirt_operation - Put into Power Off Menu " >> /allaccess/$guest_name.log
    ## If Powered On, put it into the main list. 
    elif [[ ${active[*]} =~ ${i##*/} ]]; then
    adl "dbg: Enabling ${i##*/}"
      sed -i -e 's/<Name>Applications<\/Name><Menu><Name>Powered Off<\/Name>/<Name>Applications<\/Name>/g' $i
      echo "</Menu></Menu>" >> $i 
      echo "$mydatetime $libvirt_operation - Put into Powered On Menu " >> /allaccess/$guest_name.log
    fi
  done  
fi
1 Like