#!/bin/ash
#
#
#
 if [ ! -s /etc/ntp.conf ]; then
   echo "server pool.ntp.org" > /etc/ntp.conf
 fi
 case "$1" in
 '-q')
 busybox ntpd -nq > /dev/null 2>&1 &
 ;;
 'start')
 ntpd stop
 sleep 0.1
 busybox ntpd -l
 ;;
 'stop')
 kill $(cat /var/run/ntpd.pid 2>/dev/null) 2>/dev/null
 ;;
 'restart')
 ntpd start
 ;;
 'test')
 if [ ! -e /var/run/ntpd.pid ]; then
   echo "Your NTP Server seems to be down."
   read -p "Do you wish to start it now (y/n)?: " CHOICE
   CHOICE=y$CHOICE
   if [ $CHOICE = yy ]; then
     ntpd start
   fi
 fi
 clear
 ntpdate -d localhost
 ;;
 'help')
 echo "ntpd start --> start NTP server"
 echo "ntpd stop --> stop NTP server"
 echo "ntpd restart --> restart NTP server"
 echo "ntpd test --> test NTP server"
 ;;
 *)
 echo "Usage:"
 ntpd help
 ;;
 esac