Created
June 29, 2022 01:44
-
-
Save daktak/3b6a7fd8cb2d8fc259f29d389a5a7a21 to your computer and use it in GitHub Desktop.
Qubes-os update template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NEW_TEMPLATE=$2 | |
OLD_TEMPLATE=$1 | |
DVM_NAME=$4 | |
OLD_DVM_NAME=$3 | |
if [[ -z ${NEW_TEMPLATE} ]]; then | |
echo "update-template.sh oldtemplate newtemplate [olddvm] [newdvm]" | |
exit 1 | |
fi | |
if [[ -z ${DVM_NAME} ]]; then | |
DVM_NAME="${NEW_TEMPLATE}-dvm" | |
fi | |
if [[ -z ${OLD_DVM_NAME} ]]; then | |
OLD_DVM_NAME="${OLD_TEMPLATE}-dvm" | |
fi | |
OLD_IFS=$IFS | |
VMLIST_RAW=$(qvm-ls --raw-data --fields=name,template,state,class | grep -v sys- ) | |
VMLIST=($VMLIST_RAW) | |
length=${#VMLIST[@]} | |
function update_qube() { | |
VM_NAME=$(echo $1 | cut -f1 -d'|') | |
TEMPLATE_NAME=$(echo $RAW | cut -f2 -d'|') | |
STATUS=$(echo $RAW | cut -f3 -d'|') | |
CLASS=$(echo $RAW | cut -f4 -d'|') | |
if [[ "${TEMPLATE_NAME}" == "${OLD_TEMPLATE}" || "${TEMPLATE_NAME}" == "${OLD_DVM_NAME}" ]]; then | |
if [[ "${VM_NAME}" -ne "${OLD_DVM_NAME}" ]]; then | |
echo $VM_NAME | |
if [[ "${STATUS}" == "Halted" ]]; then | |
if [[ "${CLASS}" == "AppVM" ]]; then | |
qvm-prefs $VM_NAME template $NEW_TEMPLATE | |
elif [[ "${CLASS}" == "DispVM" ]]; then | |
qvm-prefs $VM_NAME template $DVM_NAME | |
fi | |
else | |
echo "Qube is running" | |
if [[ "$2" == "yes" ]]; then | |
qvm-shutdown --force --wait $VM_NAME | |
if [[ "${CLASS}" == "AppVM" ]]; then | |
qvm-prefs $VM_NAME template $NEW_TEMPLATE | |
elif [[ "${CLASS}" == "DispVM" ]]; then | |
qvm-prefs $VM_NAME template $DVM_NAME | |
fi | |
qvm-start $VM_NAME | |
fi | |
fi | |
fi | |
fi | |
} | |
DVM_EXISTS=$(qvm-ls --raw-data --fields=name,template,state,class $DVM_NAME) | |
if [[ $? -ne 0 ]]; then | |
qvm-create -l red -t $NEW_TEMPLATE $DNM_NAME | |
qvm-prefs $DVM_NAME template_for_dispvms True | |
qvm-features $DVM_NAME appmenus-dispvm 1 | |
qubes-prefs default-dispvm $DVM_NAME | |
fi | |
#update halted non sys qubes | |
for (( i=0; i<length; i++ )); do | |
RAW=${VMLIST[$i]} | |
update_qube $RAW | |
done | |
SYS_QUBES='sys-usb sys-net sys-firewall' | |
for i in $SYS_QUBES; do | |
RAW=$(qvm-ls --raw-data --fields=name,template,state,class $i) | |
update_qube $RAW yes | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment