SHARE
TWEET

Clever Solutions to Nonexistent Problems...

a guest Jun 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #Date and Time Setting Tool Copyright 2009,2011 by Tony Brijeski under the GPL V2
  3. # modified by skidoo
  4. ###   NOTE: no validation is performed ~~ user can choose "Feb 31"
  5.  
  6. DIALOG="`which yad` --width 400 --center"
  7. TITLE="--always-print-result --dialog-sep --title="
  8. TEXT="--text="
  9. ENTRY="--entry "
  10. ENTRYTEXT="--entry-text "
  11. MENU="--list --print-column=1 --column=Pick:HD --column=_"
  12. YESNO="--question "
  13. MSGBOX="--info "
  14. SCALE="--scale "
  15. PASSWORD="--entry --hide-text "
  16. TITLETEXT="manage Date and Time Settings"
  17. testroot="`whoami`"   #  howdy       backticks galore
  18.  
  19. if [ "$testroot" != "root" ]; then
  20.     gksu $0
  21.     exit 1
  22. fi
  23.  
  24. while [ "$SETCHOICE" != "Exit" ]; do
  25. DAY="`date +%d`"
  26. MONTH="`date +%m`"
  27. YEAR="`date +%Y`"
  28. MINUTE="`date +%M`"
  29. HOUR="`date +%H`"
  30. SETCHOICE=`$DIALOG --center --height 300 $TITLE"$TITLETEXT" $MENU $TEXT"\nTime=$HOUR:$MINUTE\nDate=$MONTH-$DAY-$YEAR\n\n" Exit "Quit" SETTIME "set Current Time" SETDATE "set Current Date"`
  31. SETCHOICE=`echo $SETCHOICE | cut -d "|" -f 1`
  32.  
  33. if [ "$SETCHOICE" = "SETTIME" ]; then
  34.     HOUR="`date +%H`"
  35.     HOUR=`echo $HOUR | sed -e 's/^0//g'`
  36.     SETHOUR=`$DIALOG --center $TITLE"$TITLETEXT" $SCALE --value=$HOUR --min-value=0 --max-value=23 $TEXT"Move the slider to the correct Hour"`
  37.     if [ "$?" = "0" ]; then
  38.         if [ "${#SETHOUR}" = "1" ]; then
  39.             SETHOUR="0$SETHOUR"
  40.         fi
  41.  
  42.         MINUTE="`date +%M`"
  43.         MINUTE=`echo $MINUTE | sed -e 's/^0//g'`
  44.     fi
  45.  
  46.     SETMINUTE=`$DIALOG --center $TITLE"$TITLETEXT" $SCALE --value=$MINUTE --min-value=0 --max-value=59 $TEXT"Move the slider to the correct Minute"`
  47.     if [ "$?" = "0" ]; then
  48.         if [ "${#SETMINUTE}" = "1" ]; then
  49.             SETMINUTE="0$SETMINUTE"
  50.         fi
  51.  
  52.         date $MONTH$DAY$SETHOUR$SETMINUTE$YEAR
  53.         hwclock --systohc
  54.     fi
  55. fi
  56.  
  57. if [ "$SETCHOICE" = "SETDATE" ]; then
  58.     DAY="`date +%d`"
  59.     DAY=`echo $DAY | sed -e 's/^0//g'`
  60.     MONTH="`date +%m`"
  61.     MONTH=`echo $MONTH | sed -e 's/^0//g'`
  62.     YEAR="`date +%Y`"
  63.     SETYEAR=`$DIALOG --center $TITLE"$TITLETEXT" $SCALE --value=$YEAR --min-value=2019 --max-value=2030 $TEXT"Move the slider to the correct Year"`
  64.  
  65.     if [ "$?" = "0" ]; then
  66.         SETMONTH=`$DIALOG --center $TITLE"$TITLETEXT" $SCALE --value=$MONTH --min-value=1 --max-value=12 $TEXT"Move the slider to the correct Month"`
  67.         if [ "$?" = "0" ]; then
  68.             if [ "${#SETMONTH}" = "1" ]; then
  69.                 SETMONTH="0$SETMONTH"
  70.             fi
  71.                           #    howdy     heh heh  no validation ~~ let's set it to Feb 31, eh?
  72.             SETDAY=`$DIALOG --center $TITLE"$TITLETEXT" $SCALE --value=$DAY --min-value=1 --max-value=31 $TEXT"Move the slider to the correct Day"`
  73.             if [ "$?" = "0" ]; then
  74.                 if [ "${#SETDAY}" = "1" ]; then
  75.                     SETDAY="0$SETDAY"
  76.                 fi
  77.  
  78.                 MINUTE="`date +%M`"
  79.                 HOUR="`date +%H`"
  80.                 date $SETMONTH$SETDAY$HOUR$MINUTE$SETYEAR
  81.                 hwclock --systohc
  82.             fi
  83.         fi
  84.     fi
  85. fi
  86. done
  87. exit 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top