set-time-for-puppy 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  3. # A small script used to set the time under Linux with hwclock...
  4. # MU: updated for puppy 1.0.7.
  5. #100525 hardware clock can be utc or localtime (thanks to pizzasgood).
  6. #120202 rodin.s: internationalized.
  7. export TEXTDOMAIN=set-time-for-puppy
  8. export TEXTDOMAINDIR=/usr/share/locale
  9. export OUTPUT_CHARSET=UTF-8
  10. eval_gettext () {
  11. local myMESSAGE=$(gettext "$1")
  12. eval echo \"$myMESSAGE\"
  13. }
  14. export LANGORG=$LANG
  15. . /etc/clock #100525
  16. # Title to be used for all Xdialog boxes.
  17. TITLE="$(gettext 'Set time tool')"
  18. # Get the date (returned in DD/MM/YYYY format by Xdialog.
  19. ENTEREDDATE=`Xdialog --stdout --title "$TITLE" --calendar "$(gettext 'Please set the date...')" 0 0 0 0 0`
  20. if [ ! $? -eq 0 ]; then
  21. exit
  22. fi
  23. # Convert the date to the MM/DD/YYYY format needed by hwclock.
  24. NEWDATE=`echo "$ENTEREDDATE" | awk --source 'BEGIN { FS="/" }' --source '{ print $2 "/" $1 "/" $3 }'`
  25. # Get the time in HH:MM:SS format.
  26. NEWTIME=`Xdialog --stdout --title "$TITLE" --timebox "$(gettext 'Please set the time...')" 0 0`
  27. if [ ! $? -eq 0 ]; then
  28. Xdialog --title "$TITLE" --msgbox "$(gettext 'Aborted.')" 0 0
  29. exit
  30. fi
  31. # Set the hardware clock (RTC) and then the system clock
  32. D=`echo $NEWDATE|sed "s/^...//" | sed "s/\/.*$//"`
  33. M=`echo $NEWDATE|sed "s/\/.*$//"`
  34. Y=`echo $NEWDATE|sed "s/^........//" | sed "s/ .*$//"`
  35. H=`echo $NEWTIME|sed "s/^.* //" | sed "s/://g" | sed "s/..$//"`
  36. DT=`echo $M$D$H$Y`
  37. date $DT
  38. Xdialog --title "$(gettext 'info')" --msgbox "$(gettext 'Your screen might turn black now for some seconds, just wait...')" 0 0
  39. hwclock --systohc --${HWCLOCKTIME} #100525
  40. THEDATE=`date`
  41. Xdialog --title "$(gettext 'info')" --msgbox "$(gettext 'Finished. Time was set to') $THEDATE" 0 0