core-admin/dom0/qvm-tools/qvm-sync-dom0-clock

35 lines
883 B
Plaintext
Raw Normal View History

2011-08-02 14:12:03 +02:00
#!/bin/sh
CLOCK_VM=`qvm-get-clockvm`
2011-08-02 14:12:03 +02:00
QREXEC_CLIENT=/usr/lib/qubes/qrexec_client
if [ -z "$CLOCK_VM" ]; then
echo "ClockVM not set, exiting!" >&2
2011-08-02 14:12:03 +02:00
exit 1
fi
if ! xl domid "$CLOCK_VM" > /dev/null 2>&1; then
echo "ClockVM not started, exiting!"
2011-08-02 14:12:03 +02:00
exit 1
fi
# dd is supposed to not allow memory exhaustion
# grep does basic sanity checking
# there seems to be no way to pass output of date +%s.%N to date,
# so we use human-readable format
CURRENT_TIME="$($QREXEC_CLIENT -d $CLOCK_VM 'user:date -u' |
2011-08-02 14:12:03 +02:00
dd count=1 2>/dev/null |
grep '^[A-Za-z]* [A-Za-z]* [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [A-Z]* [0-9][0-9][0-9][0-9]$'|
head -1)"
if [ -n "$CURRENT_TIME" ] ; then
echo Syncing Dom0 clock: setting time "$CURRENT_TIME"...
sudo date -u -s "$CURRENT_TIME" ;
echo Done.
else
echo "Error while parsing the time obtained from the ClockVM ($CLOCK_VM).."
2011-08-02 14:12:03 +02:00
fi