#!/bin/sh
# setclock: set the system's CMOS and system times from the network.
# Copyright 1994-5 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.
# If ntp, ntp1 and ntp2 seem unreliable, you can use gate instead.
# servers="ntp.demon.co.uk ntp1.demon.co.uk ntp2.demon.co.uk"
servers="ntp.demon.co.uk"

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

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

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

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

# Get the current system date.
date 2>&1 >>$tmpfile

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

# Finally, tidy up.
rm -f $tmpfile
