Skip to content

Instantly share code, notes, and snippets.

@UndeadDevel
Created January 29, 2024 19:45
Show Gist options
  • Save UndeadDevel/0a9e238db4fe58055eb8b1a40515f3b6 to your computer and use it in GitHub Desktop.
Save UndeadDevel/0a9e238db4fe58055eb8b1a40515f3b6 to your computer and use it in GitHub Desktop.
QubesOS: give or remove default (viz. TOR for anon-qubes) network of the in-focus qube
#!/bin/bash
CUR_WIN_ID=$(xdotool getwindowfocus)
CUR_VM=$(xprop _QUBES_VMNAME -id $CUR_WIN_ID | cut -d \" -f 2)
if [[ "$CUR_VM" != *"not found"* ]];then
if ! qvm-prefs "$CUR_VM" netvm | head -c1 | grep -E '.';then
TEXT="TOR"
while read -r line
do
if [[ "$line" == "anon-vm" ]];then
TEXT="TOR"
break
else
TEXT="DEFAULT"
fi
done <<< $(qvm-tags "$CUR_VM")
ANSWER=$(notify-send -A Y="Yes" -A N="No" "Grant $TEXT network access to $CUR_VM" "Do you want to grant $TEXT network access to $CUR_VM?")
if [[ "$ANSWER" == "Y" ]];then
if [[ "$TEXT" == "DEFAULT" ]];then
qvm-start --skip-if-running $(qubes-prefs default_netvm) &&
qvm-prefs "$CUR_VM" netvm -D &&
notify-send "Granted $CUR_VM $TEXT network access!" "The netvm of $CUR_VM was set to $(qvm-prefs "$CUR_VM" netvm)."
else
qvm-start --skip-if-running sys-whonix &&
qvm-prefs "$CUR_VM" netvm sys-whonix &&
notify-send "Granted $CUR_VM $TEXT network access!" "The netvm of $CUR_VM was set to $(qvm-prefs "$CUR_VM" netvm)."
fi
fi
else
qvm-prefs "$CUR_VM" netvm None
notify-send "Disconnected $CUR_VM from network!" "The netvm of $CUR_VM was set to None (n/a)."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment