#!/bin/sh
#written by pizzasgood, 2009
#GPL license /usr/share/doc/legal/gpl-2.0.txt
#120202 rodin.s: internationalized.

export TEXTDOMAIN=set_hwclock_type
export OUTPUT_CHARSET=UTF-8

[ -f /etc/clock ] && . /etc/clock

if [ "$HWCLOCKTIME" = "utc" ]; then
    utc_flag='on'
    local_flag='off'
else
    utc_flag='off'
    local_flag='on'
fi

HWCLOCKTIME=$(Xdialog --title "`gettext \"Set HW-Clock Type\"`" --radiolist "`gettext \"What should the hardware clock be interpreted as?\"`" 0 0 0 localtime "" $local_flag utc "" $utc_flag 2>&1)
if [ $? -ne 0 ]; then
    exit
fi

if [ "$HWCLOCKTIME" = "utc" ] || [ "$HWCLOCKTIME" = "localtime" ]; then
    if [ "$(grep "^HWCLOCKTIME=" /etc/clock)" = "" ]; then
        echo "HWCLOCKTIME='$HWCLOCKTIME'" >> /etc/clock
    else
        hwPATTERN="s/^HWCLOCKTIME=[^#]*/HWCLOCKTIME='$HWCLOCKTIME'/"
        sed -i "$hwPATTERN" /etc/clock
    fi

    RET=$(Xdialog --title "`gettext \"Set HW-Clock Type\"`" --ok-label "`gettext \"Yes\"`" --cancel-label "`gettext \"No\"`" --radiolist "`gettext \"Update the software clock or the hardware clock? \n...if you don't know or uncertain, that's ok, just click the 'No' button\"`" 0 0 0 software "to match hardware" on hardware "to match software" off 2>&1)
    if [ $? -ne 0 ]; then
        exit
    fi

    if [ "$RET" = "software" ]; then
      hwclock --hctosys --$HWCLOCKTIME
    elif [ "$RET" = "hardware" ]; then
      hwclock --systohc --$HWCLOCKTIME
    fi

    Xdialog --title "$(gettext 'Set HW-Clock Type')" --infobox "$(gettext 'Done')" 0 0 4000

fi
