-
Notifications
You must be signed in to change notification settings - Fork 0
/
qubes-template-update
executable file
·68 lines (61 loc) · 1.56 KB
/
qubes-template-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#
# Script to update template images in a big batch
#
# See https://mig5.net/content/batch-updating-templatevms-qubes-30
# Get a list of templates
list_templates() {
qvm-ls --raw-data name-raw type \
| while IFS='|' read name type; do
[ Tpl = "$type" ] && echo "$name"
done | sort
}
usage()
{
cat << EOF
usage: $0
This script will power up template images (if not already running)
and apply software updates on them.
Currently only Fedora and Debian-based templates are supported.
EOF
}
# Parse arguments
while getopts ":h" OPTION
do
case $OPTION in
h)
usage
exit
;;
?)
usage
exit 1
;;
esac
done
for template in `list_templates`; do
echo "Attempting to run updates on $template"
# First check if the VM is running, so we know if we should shut it down after
qvm-check --quiet --running $template
if [ $? -eq 1 ]; then
RUNNING=1
else
RUNNING=0
fi
# 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 "dnf -y update; dnf clean all"
fi
echo "$template has been updated"
if [ $RUNNING -eq 1 ]; then
# The Template wasn't running to begin with, let's shut it down
qvm-shutdown $template
else
echo "You should probably shutdown $template when it's convenient."
fi
done