Code:
#!/bin/bash
# Time, Date and Timezone configuration utility for Linux Lite
# Fork of Date and Time Setting Tool Copyright 2009,2011 by Tony Brijeski under the GPL V2
# TODO: add timezone settings, test on a live dvd, use image-list for the main dialog,
DIALOG="`which zenity` --width 400"
TITLE="--window-icon=/usr/share/icons/hicolor/24x24/apps/gnome-panel-clock.png --print-partial --title="
TEXT="--text="
ENTRY="--entry "
ENTRYTEXT="--entry-text "
MENU="--list --print-column=1 --column=Pick --column=Info"
YESNO="--question "
MSGBOX="--info "
SCALE="--scale "
PASSWORD="--entry --hide-text "
TITLETEXT="Linux Lite Date and Time Setting Tool"
if [ $EUID -ne 0 ]; then
gksu -m '
<b>Lite Time requires Administrative privileges</b>
Please enter your password to continue.' bash $0
exit
else :
fi
while [ "$SETCHOICE" != "Exit" ]; do
DAY="`date +%d`"
MONTH="`date +%m`"
YEAR="`date +%Y`"
MINUTE="`date +%M`"
HOUR="`date +%H`"
SETCHOICE=`$DIALOG --height 300 $TITLE"$TITLETEXT" $MENU $TEXT"Set Year Date and Time Tool\n\nTime=$HOUR:$MINUTE\nDate=$MONTH-$DAY-$YEAR\n\n" Exit "Quit" SETTIME "Set Current Time" SETDATE "Set Current Date"`
SETCHOICE=`echo $SETCHOICE | cut -d "|" -f 1`
if [ "$SETCHOICE" = "SETTIME" ]; then
HOUR="`date +%H`"
HOUR=`echo $HOUR | sed -e 's/^0//g'`
SETHOUR=`$DIALOG $TITLE"$TITLETEXT" $SCALE --value=$HOUR --min-value=0 --max-value=23 $TEXT"Move the slider to the correct Hour"`
if [ "$?" = "0" ]; then
if [ "${#SETHOUR}" = "1" ]; then
SETHOUR="0$SETHOUR"
fi
MINUTE="`date +%M`"
MINUTE=`echo $MINUTE | sed -e 's/^0//g'`
fi
SETMINUTE=`$DIALOG $TITLE"$TITLETEXT" $SCALE --value=$MINUTE --min-value=0 --max-value=59 $TEXT"Move the slider to the correct Minute"`
if [ "$?" = "0" ]; then
if [ "${#SETMINUTE}" = "1" ]; then
SETMINUTE="0$SETMINUTE"
fi
date $MONTH$DAY$SETHOUR$SETMINUTE$YEAR
hwclock --systohc
fi
fi
if [ "$SETCHOICE" = "SETDATE" ]; then
DAY="`date +%d`"
DAY=`echo $DAY | sed -e 's/^0//g'`
MONTH="`date +%m`"
MONTH=`echo $MONTH | sed -e 's/^0//g'`
YEAR="`date +%Y`"
SETYEAR=`$DIALOG $TITLE"$TITLETEXT" $SCALE --value=$YEAR --min-value=2000 --max-value=2020 $TEXT"Move the slider to the correct Year"`
if [ "$?" = "0" ]; then
SETMONTH=`$DIALOG $TITLE"$TITLETEXT" $SCALE --value=$MONTH --min-value=1 --max-value=12 $TEXT"Move the slider to the correct Month"`
if [ "$?" = "0" ]; then
if [ "${#SETMONTH}" = "1" ]; then
SETMONTH="0$SETMONTH"
fi
SETDAY=`$DIALOG $TITLE"$TITLETEXT" $SCALE --value=$DAY --min-value=1 --max-value=31 $TEXT"Move the slider to the correct Day"`
if [ "$?" = "0" ]; then
if [ "${#SETDAY}" = "1" ]; then
SETDAY="0$SETDAY"
fi
MINUTE="`date +%M`"
HOUR="`date +%H`"
date $SETMONTH$SETDAY$HOUR$MINUTE$SETYEAR
hwclock --systohc
fi
fi
fi
fi
done
exit 0