summaryrefslogtreecommitdiff
path: root/net-misc/clockspeed/files/ntpclockset
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
committerV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
commit4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch)
treeba5f07bf3f9d22d82e54a462313f5d244036c768 /net-misc/clockspeed/files/ntpclockset
reinit the tree, so we can have metadata
Diffstat (limited to 'net-misc/clockspeed/files/ntpclockset')
-rw-r--r--net-misc/clockspeed/files/ntpclockset56
1 files changed, 56 insertions, 0 deletions
diff --git a/net-misc/clockspeed/files/ntpclockset b/net-misc/clockspeed/files/ntpclockset
new file mode 100644
index 000000000000..c4c9d1b68ccb
--- /dev/null
+++ b/net-misc/clockspeed/files/ntpclockset
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Updates by Sascha Silbe
+
+usage() {
+ cat << EOF
+Usage: ntpclockset [options] <NTP server>
+Example: ntpclockset -q 192.168.0.1
+
+Options:
+ --quiet (-q) be quiet (only show errors)
+ --help (-h) show this text and exit
+EOF
+ exit 1
+}
+
+quiet=0
+
+for curArg in "$@" ; do
+ case "${curArg}" in
+ -q|--quiet) quiet=1;;
+ -h|--help) usage;;
+ -*) echo "Invalid option '${curArg}'"
+ usage;;
+ *) NTPSERVER="${curArg}";;
+ esac
+done
+
+[ -z $NTPSERVER ] && NTPSERVER=`dnsip pool.ntp.org | awk '{print $1}'`
+
+tmpfile="`mktemp`"
+# display how much your clock is off by
+if ! sntpclock $NTPSERVER > ${tmpfile} ; then
+ echo "!!! Could not contact NTP server: $NTPSERVER" >&2
+ exit 2
+fi
+
+if [ ${quiet} -eq 0 ] ; then
+ echo ">>> Current clock sync:"
+ cat ${tmpfile} | clockview
+ echo
+ echo -n ">>> Now setting clock ..."
+fi
+cat ${tmpfile} | clockadd
+if [ ${quiet} -eq 0 ] ; then
+ echo " [ok]"
+ echo -n ">>> Writing time to hardware clock ..."
+fi
+/sbin/hwclock --systohc
+if [ ${quiet} -eq 0 ] ; then
+ echo " [ok]"
+ echo
+ echo ">>> New clock sync:"
+ sntpclock $NTPSERVER | clockview
+fi
+rm -f ${tmpfile}