-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathqubes-dom0-update
executable file
·160 lines (138 loc) · 4.4 KB
/
qubes-dom0-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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
UPDATEVM=`qubes-prefs --get updatevm`
UPDATES_STAT_FILE=/var/lib/qubes/updates/dom0-updates-available
if [ -z "$UPDATEVM" ]; then
echo "UpdateVM not set, exiting"
exit 1
fi
if [ "$1" = "--help" ]; then
echo "This tool is used to download packages for dom0. Without package list"
echo "it checks for updates for installed packages"
echo ""
echo "Usage: $0 [--clean] [--check-only] [--gui] [<pkg list>]"
echo " --clean clean yum cache before doing anything"
echo " --check-only only check for updates (no install)"
echo " --gui use gpk-update-viewer for update selection"
echo " <pkg list> download (and install if run by root) new packages"
echo " in dom0 instead of updating"
exit
fi
# Prevent template upgrade - this would override user changes
TEMPLATE_EXCLUDE_OPTS="--exclude=`rpm -qa --qf '%{NAME},' qubes-template-\*`"
PKGS=
YUM_OPTS="$TEMPLATE_EXCLUDE_OPTS"
GUI=
CHECK_ONLY=
ALL_OPTS="$TEMPLATE_EXCLUDE_OPTS $*"
QVMRUN_OPTS=
CLEAN=
# Filter out some yum options and collect packages list
while [ $# -gt 0 ]; do
case "$1" in
--enablerepo=*|\
--disablerepo=*)
;;
--clean)
CLEAN=1
;;
--gui)
GUI=1
;;
--check-only)
CHECK_ONLY=1
;;
-*)
YUM_OPTS="$YUM_OPTS $1"
;;
*)
PKGS="$PKGS $1"
;;
esac
shift
done
ID=$(id -ur)
if [ $ID != 0 -a -z "$GUI" -a -z "$CHECK_ONLY" ] ; then
echo "This script should be run as root (when used in console mode), use sudo." >&2
exit 1
fi
if [ "$GUI" == "1" -a -n "$PKGS" ]; then
echo "ERROR: GUI mode can be used only for updates" >&2
exit 1
fi
if [ "$GUI" == "1" ]; then
apps="yumex apper gpk-update-viewer"
if [ -n "$KDE_FULL_SESSION" ]; then
apps="apper yumex gpk-update-viewer"
fi
guiapp=
for app in $apps; do
if type $app &>/dev/null; then
guiapp=$app
case $guiapp in
apper) guiapp="apper --updates" ;;
*) guiapp=$app ;;
esac
break;
fi
done
if [ -z "$guiapp" ]; then
message1="You don't have installed any supported yum frontend."
message2="Install (using qubes-dom0-update) one of: $apps"
if [ "$KDE_FULL_SESSION" ]; then
kdialog --sorry "$message1<br/>$message2"
else
zenity --error --text "$message1\n$message2"
fi
exit 1
fi
fi
if [ "$GUI" != "1" ]; then
QVMRUN_OPTS=--nogui
fi
# Do not start VM automaticaly when running from cron (only checking for updates)
if [ "$CHECK_ONLY" == "1" ] && ! xl domid $UPDATEVM > /dev/null 2>&1; then
echo "ERROR: UpdateVM not running, not starting it in non-interactive mode" >&2
exit 1
fi
if [ -n "$CLEAN" ]; then
rm -f /var/lib/qubes/updates/rpm/*
fi
rm -f /var/lib/qubes/updates/errors
# We should ensure the clocks in Dom0 and UpdateVM are in sync
# becuase otherwise yum might complain about future timestamps
qvm-sync-clock
echo "Using $UPDATEVM as UpdateVM to download updates for Dom0; this may take some time..." >&2
# Start VM if not running already
qvm-run $QVMRUN_OPTS -a $UPDATEVM true || exit 1
tar c /var/lib/rpm /etc/yum.repos.d /etc/yum.conf 2>/dev/null | qvm-run -p "$UPDATEVM" 'tar x -C /var/lib/qubes/dom0-updates'
qvm-run $QVMRUN_OPTS --pass-io $UPDATEVM "/usr/lib/qubes/qubes-download-dom0-updates.sh --doit --nogui $ALL_OPTS"
RETCODE=$?
if [ "$CHECK_ONLY" == "1" ]; then
exit $RETCODE
elif [ "$RETCODE" -ne 0 ]; then
exit $RETCODE
fi
# Wait for download completed
while pidof -x qubes-receive-updates >/dev/null; do sleep 0.5; done
if [ -r /var/lib/qubes/updates/errors ]; then
echo "*** ERROR while receiving updates:" >&2
cat /var/lib/qubes/updates/errors >&2
echo "--> if you want to use packages that were downloaded correctly, use yum directly now" >&2
exit 1
fi
if [ "x$PKGS" != "x" ]; then
yum $YUM_OPTS install $PKGS
elif [ -f /var/lib/qubes/updates/repodata/repomd.xml ]; then
# Above file exists only when at least one package was downloaded
if [ "$GUI" == "1" ]; then
$guiapp
else
yum check-update
if [ $? -eq 100 ]; then
yum $YUM_OPTS update
fi
fi
yum -q check-update && rm -f $UPDATES_STAT_FILE
else
echo "No updates avaliable" >&2
fi