home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / set-time-for-puppy < prev    next >
Encoding:
Text File  |  2006-02-03  |  1.4 KB  |  52 lines

  1. #!/bin/sh
  2.  
  3. # A small script used to set the time under Linux with hwclock...
  4. # MU: updated for puppy 1.0.7.
  5.  
  6. # Title to be used for all Xdialog boxes.
  7. TITLE="Set time tool"
  8.  
  9. # Now check for hwclock existence...
  10. if ! [ -f /usr/sbin/hwclock ] ; then
  11.    Xdialog --title "$TITLE" --msgbox "/usr/sbin/hwclock not found..." 0 0
  12.    exit 0
  13. fi
  14.  
  15. # Get the date (returned in DD/MM/YYYY format by Xdialog.
  16. ENTEREDDATE=`Xdialog --stdout --title "$TITLE" --calendar "Please set the date..." 0 0 0 0 0`
  17. if [ ! $? -eq 0 ]; then
  18.    exit
  19. fi
  20.  
  21. # Convert the date to the MM/DD/YYYY format needed by hwclock.
  22. NEWDATE=`echo "$ENTEREDDATE" | awk --source 'BEGIN { FS="/" }' --source '{ print $2 "/" $1 "/" $3 }'`
  23.  
  24. # Get the time in HH:MM:SS format.
  25. NEWTIME=`Xdialog --stdout --title "$TITLE" --timebox "Please set the time..." 0 0`
  26. if [ ! $? -eq 0 ]; then
  27.    Xdialog --title "$TITLE" --msgbox "Aborted." 0 0
  28.    exit
  29. fi
  30.  
  31.  
  32. # Set the hardware clock (RTC) and then the system clock
  33.  
  34. D=`echo $NEWDATE|sed "s/^...//" | sed "s/\/.*$//"`
  35.  
  36. M=`echo $NEWDATE|sed "s/\/.*$//"`
  37. Y=`echo $NEWDATE|sed "s/^........//" | sed "s/ .*$//"`
  38.  
  39. H=`echo $NEWTIME|sed "s/^.* //" | sed "s/://g" | sed "s/..$//"`
  40.  
  41. DT=`echo $M$D$H$Y`
  42.  
  43. date $DT
  44.  
  45.  
  46. Xdialog --title "info" --msgbox "Your screen might turn black now for some seconds, just wait..." 0 0
  47.  
  48. /usr/sbin/hwclock --systohc --localtime
  49.  
  50. THEDATE=`date`
  51. Xdialog --title "info" --msgbox "Finished. Time was set to $THEDATE" 0 0
  52.