#!/bin/sh
# setclock: set the system's CMOS and system times from the network.
# Copyright 1994-6 John A. Phillips - john@linux.demon.co.uk
# usage: setclock [GMT|local]

# Set the zone for the CMOS clock if specified, or use the default.
zone=${1:-GMT}

# Assign the servers to set the system date and time.  If you use more 
# than one time server it takes longer but you get more reliability.
# servers="ntp.demon.co.uk"
servers="ntp.demon.co.uk ntp1.demon.co.uk ntp2.demon.co.uk"

# Assign a temporary file.
tmpfile=/tmp/demon.time.$$

# Check for valid zones.
if [ $zone != "GMT" -a $zone != "local" ]; then
    echo "usage: setclock [GMT|local]"
    exit 1
fi

# Make sure we clean up on any exit
trap "rm -f $tmpfile" 0

# Set the system date and time from the list of servers.
/usr/sbin/netdate $servers >$tmpfile 2>&1

# Set the system's CMOS clock from the system date and time.
if [ $zone = "local" ]; then
    /sbin/clock -w >>$tmpfile 2>&1
else
    /sbin/clock -u -w >>$tmpfile 2>&1
fi

# Show the date and time.
/bin/echo ""
/bin/cat $tmpfile
/bin/echo ""
