35 lines
883 B
Bash
Executable File
35 lines
883 B
Bash
Executable File
#!/bin/sh
|
|
|
|
CLOCK_VM=`qvm-get-clockvm`
|
|
|
|
QREXEC_CLIENT=/usr/lib/qubes/qrexec_client
|
|
|
|
if [ -z "$CLOCK_VM" ]; then
|
|
echo "ClockVM not set, exiting!" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! xl domid "$CLOCK_VM" > /dev/null 2>&1; then
|
|
echo "ClockVM not started, exiting!"
|
|
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' |
|
|
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).."
|
|
fi
|
|
|