Skip to content

Instantly share code, notes, and snippets.

@mig5
Last active July 18, 2018 12:04
Show Gist options
  • Save mig5/e6fcd033df11b0800bbd to your computer and use it in GitHub Desktop.
Save mig5/e6fcd033df11b0800bbd to your computer and use it in GitHub Desktop.
qubes-template-update
#!/bin/bash
#
# Script to update template images in a big batch
#
# Get a list of templates
TEMPLATES=$(qvm-ls | grep Tpl | awk {'print $1'} |cut -d[ -f2 | cut -d] -f1)
usage()
{
cat << EOF
usage: $0
This script will power up template images and run software
updates on them.
Currently only Fedora and Debian-based templates are supported.
Whonix templates, although Debian-based, are not supported,
because there is the chance that Tor is not connected yet.
EOF
}
# Parse arguments
while getopts ":h" OPTION
do
case $OPTION in
h)
usage
exit
;;
?)
usage
exit 1
;;
esac
done
for template in ${TEMPLATES[@]}; do
echo "Attempting to run updates on $template"
if [[ $template == *"whonix"* ]]; then
echo "Don't run Whonix updates with this script, because Tor may not be connected. Run them manually after whonixcheck completes"
else
# Attempt to detect whether this is a Debian system
qvm-run -u root -a --nogui -p $template "test -f /etc/debian_version"
if [ $? -eq 0 ]; then
# Debian
qvm-run -u root -a --nogui -p $template "apt-get update; DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade; apt-get clean"
else
# Fedora
qvm-run -u root -a --nogui -p $template "yum -y update; yum clean all"
fi
qvm-shutdown $template
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment