#!/bin/bash

#used for cli command "set date"
#input : $1 the date to set,format hh:mm[:ss]; YYYY/MM/DD-hh:mm[:ss]; MMDDhhmm[YYYY][.ss]
#no output

#ntp_run=`ps|grep -v grep|grep ntpd|wc -l`
ntp_run=`/etc/init.d/ntp status | grep "is running" | wc -l`

if [ $ntp_run -ge 1 ]; then
	echo "Please shutdown the ntp server first!"
else
        date=$1
        date=${date//-/ }
        tmp=`echo $date | grep ":" | wc -l`
        if [ $tmp -eq 0 ]; then
            sudo date "$date"
        else
            sudo date -s "$date"
        fi
	#sudo date -s $1
	sudo hwclock  -w -u
fi

exit 0
