mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-20 03:50:37 +02:00
change tz to new bash internal test, remove tabs
This commit is contained in:
parent
fe4e84f3c2
commit
54aca57abb
1 changed files with 125 additions and 123 deletions
|
@ -1,11 +1,11 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# written by Tobias Powalowski <tpowa@archlinux.org>
|
# written by Tobias Powalowski <tpowa@archlinux.org>
|
||||||
|
|
||||||
ANSWER="/tmp/.tz"
|
ANSWER="/tmp/.tz"
|
||||||
TITLE="Arch Linux Time And Date Setting"
|
TITLE="Arch Linux Time And Date Setting"
|
||||||
BASEDIR="/usr/share/zoneinfo"
|
BASEDIR="/usr/share/zoneinfo"
|
||||||
|
|
||||||
if [ "$1" = "--setup" ]; then
|
if [[ "${1}" = "--setup" ]]; then
|
||||||
EXIT="Return to Main Menu"
|
EXIT="Return to Main Menu"
|
||||||
else
|
else
|
||||||
EXIT="Exit"
|
EXIT="Exit"
|
||||||
|
@ -14,12 +14,12 @@ fi
|
||||||
abort()
|
abort()
|
||||||
{
|
{
|
||||||
DIALOG --yesno "Abort Time And Date Setting?" 6 40 || return 0
|
DIALOG --yesno "Abort Time And Date Setting?" 6 40 || return 0
|
||||||
[ -e /tmp/.timezone ] && rm -f /tmp/.timezone
|
[[ -e /tmp/.timezone ]] && rm -f /tmp/.timezone
|
||||||
[ -e /tmp/.hardwareclock ] && rm -f /tmp/.hardwareclock
|
[[ -e /tmp/.hardwareclock ]] && rm -f /tmp/.hardwareclock
|
||||||
[ -e /tmp/.tz ] && rm -f /tmp/.tz
|
[[ -e /tmp/.tz ]] && rm -f /tmp/.tz
|
||||||
[ -e /etc/localtime ] && rm -f /etc/localtime
|
[[ -e /etc/localtime ]] && rm -f /etc/localtime
|
||||||
[ -e /var/lib/hwclock/adjtime ] && rm -f /var/lib/hwclock/adjtime
|
[[ -e /var/lib/hwclock/adjtime ]] && rm -f /var/lib/hwclock/adjtime
|
||||||
[ -e /tmp/.tz-running ] && rm /tmp/.tz-running
|
[[ -e /tmp/.tz-running ]] && rm /tmp/.tz-running
|
||||||
clear
|
clear
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
@ -30,48 +30,48 @@ abort()
|
||||||
# parameters: see dialog(1)
|
# parameters: see dialog(1)
|
||||||
# returns: whatever dialog did
|
# returns: whatever dialog did
|
||||||
DIALOG() {
|
DIALOG() {
|
||||||
dialog --backtitle "$TITLE" --aspect 15 "$@"
|
dialog --backtitle "${TITLE}" --aspect 15 "$@"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
dohwclock() {
|
dohwclock() {
|
||||||
if [ "$HARDWARECLOCK" = "UTC" ]; then
|
if [[ "${HARDWARECLOCK}" = "UTC" ]]; then
|
||||||
HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
|
HWCLOCK_PARAMS="${HWCLOCK_PARAMS} --utc"
|
||||||
echo UTC > /tmp/.hardwareclock
|
echo UTC > /tmp/.hardwareclock
|
||||||
else
|
else
|
||||||
HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
|
HWCLOCK_PARAMS="${HWCLOCK_PARAMS} --localtime"
|
||||||
echo localtime > /tmp/.hardwareclock
|
echo localtime > /tmp/.hardwareclock
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ ! -d /var/lib/hwclock ] && mkdir -p /var/lib/hwclock
|
[[ ! -d /var/lib/hwclock ]] && mkdir -p /var/lib/hwclock
|
||||||
if [ ! -f /var/lib/hwclock/adjtime ]; then
|
if [[ ! -f /var/lib/hwclock/adjtime ]]; then
|
||||||
echo "0.0 0 0.0" > /var/lib/hwclock/adjtime
|
echo "0.0 0 0.0" > /var/lib/hwclock/adjtime
|
||||||
fi
|
fi
|
||||||
hwclock $HWCLOCK_PARAMS
|
hwclock ${HWCLOCK_PARAMS}
|
||||||
}
|
}
|
||||||
|
|
||||||
dotimezone () {
|
dotimezone () {
|
||||||
REGIONS=""
|
REGIONS=""
|
||||||
SET_ZONE=""
|
SET_ZONE=""
|
||||||
for i in $(grep ^[A-Z] $BASEDIR/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do
|
for i in $(grep ^[A-Z] ${BASEDIR}/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do
|
||||||
REGIONS="$REGIONS $i -"
|
REGIONS="${REGIONS} ${i} -"
|
||||||
done
|
done
|
||||||
while ! [ "$SET_ZONE" = "1" ]; do
|
while ! [[ "${SET_ZONE}" = "1" ]]; do
|
||||||
SET_REGION=""
|
SET_REGION=""
|
||||||
DIALOG --menu "Please Select A Region:" 22 60 16 $REGIONS 2>$ANSWER && SET_REGION="1"
|
DIALOG --menu "Please Select A Region:" 22 60 16 ${REGIONS} 2>${ANSWER} && SET_REGION="1"
|
||||||
region=$(cat $ANSWER)
|
region=$(cat ${ANSWER})
|
||||||
if [ "${SET_REGION}" = "1" ]; then
|
if [[ "${SET_REGION}" = "1" ]]; then
|
||||||
ZONES=""
|
ZONES=""
|
||||||
for i in $(grep ^[A-Z] $BASEDIR/zone.tab | grep $region/ | cut -f 3 | sed -e "s#$region/##g"| sort -u); do
|
for i in $(grep ^[A-Z] ${BASEDIR}/zone.tab | grep ${region}/ | cut -f 3 | sed -e "s#${region}/##g"| sort -u); do
|
||||||
ZONES="$ZONES $i -"
|
ZONES="${ZONES} ${i} -"
|
||||||
done
|
done
|
||||||
DIALOG --menu "Please Select A Timezone:" 22 60 16 $ZONES 2>$ANSWER && SET_ZONE="1"
|
DIALOG --menu "Please Select A Timezone:" 22 60 16 ${ZONES} 2>${ANSWER} && SET_ZONE="1"
|
||||||
zone=$(cat $ANSWER)
|
zone=$(cat ${ANSWER})
|
||||||
if [ "${SET_ZONE}" = "1" ]; then
|
if [[ "${SET_ZONE}" = "1" ]]; then
|
||||||
DIALOG --infobox "Setting Timezone to $region/$zone ..." 0 0
|
DIALOG --infobox "Setting Timezone to ${region}/${zone} ..." 0 0
|
||||||
echo $region/$zone > /tmp/.timezone
|
echo ${region}/${zone} > /tmp/.timezone
|
||||||
[ -e /etc/localtime ] && rm -f /etc/localtime
|
[[ -e /etc/localtime ]] && rm -f /etc/localtime
|
||||||
cp $BASEDIR/$region/$zone /etc/localtime
|
cp ${BASEDIR}/${region}/${zone} /etc/localtime
|
||||||
dohwclock
|
dohwclock
|
||||||
S_NEXTITEM="2"
|
S_NEXTITEM="2"
|
||||||
fi
|
fi
|
||||||
|
@ -86,7 +86,7 @@ dotimeset() {
|
||||||
SET_TIME=""
|
SET_TIME=""
|
||||||
USE_NTPDATE=""
|
USE_NTPDATE=""
|
||||||
HARDWARECLOCK=""
|
HARDWARECLOCK=""
|
||||||
if [ ! -s /tmp/.timezone ]; then
|
if [[ ! -s /tmp/.timezone ]]; then
|
||||||
DIALOG --msgbox "Error:\nYou have to select a region and timezone first." 0 0
|
DIALOG --msgbox "Error:\nYou have to select a region and timezone first." 0 0
|
||||||
S_NEXTITEM="1"
|
S_NEXTITEM="1"
|
||||||
dotimezone || return 1
|
dotimezone || return 1
|
||||||
|
@ -96,10 +96,10 @@ DIALOG --infobox "Syncing hardwareclock to systemclock ..." 0 0
|
||||||
HWCLOCK_PARAMS="--hctosys"
|
HWCLOCK_PARAMS="--hctosys"
|
||||||
dohwclock
|
dohwclock
|
||||||
DIALOG --yesno "Your current time and date is:\n$(date)\n\nDo you want to change it?" 0 0 && SET_TIME="1"
|
DIALOG --yesno "Your current time and date is:\n$(date)\n\nDo you want to change it?" 0 0 && SET_TIME="1"
|
||||||
if [ "${SET_TIME}" = "1" ]; then
|
if [[ "${SET_TIME}" = "1" ]]; then
|
||||||
[ $(which ntpdate) ] && DIALOG --defaultno --yesno "'ntpdate' was detected on your system.\n\nDo you want to use 'ntpdate' for syncing your clock,\nby using the internet clock pool?\n(You need a working internet connection for doing this!)" 0 0 && USE_NTPDATE="1"
|
[[ $(which ntpdate) ]] && DIALOG --defaultno --yesno "'ntpdate' was detected on your system.\n\nDo you want to use 'ntpdate' for syncing your clock,\nby using the internet clock pool?\n(You need a working internet connection for doing this!)" 0 0 && USE_NTPDATE="1"
|
||||||
if [ "${USE_NTPDATE}" = "1" ]; then
|
if [[ "${USE_NTPDATE}" = "1" ]]; then
|
||||||
if [ ! $(ntpdate pool.ntp.org) ]; then
|
if [[ ! $(ntpdate pool.ntp.org) ]]; then
|
||||||
DIALOG --msgbox "An error has occured, time was not changed!" 0 0
|
DIALOG --msgbox "An error has occured, time was not changed!" 0 0
|
||||||
S_NEXTITEM="2"
|
S_NEXTITEM="2"
|
||||||
return 1
|
return 1
|
||||||
|
@ -108,22 +108,22 @@ if [ "${SET_TIME}" = "1" ]; then
|
||||||
else
|
else
|
||||||
# display and ask to set date/time
|
# display and ask to set date/time
|
||||||
CANCEL=""
|
CANCEL=""
|
||||||
dialog --calendar "Set the date.\nUse <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || CANCEL="1"
|
dialog --calendar "Set the date.\nUse <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2> ${ANSWER} || CANCEL="1"
|
||||||
if [ "$CANCEL" = "1" ]; then
|
if [[ "${CANCEL}" = "1" ]]; then
|
||||||
S_NEXTITEM="2"
|
S_NEXTITEM="2"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local _date="$(cat $ANSWER)"
|
local _date="$(cat ${ANSWER})"
|
||||||
dialog --timebox "Set the time.\nUse <TAB> to navigate and up/down to change values." 0 0 2> $ANSWER || CANCEL="1"
|
dialog --timebox "Set the time.\nUse <TAB> to navigate and up/down to change values." 0 0 2> ${ANSWER} || CANCEL="1"
|
||||||
if [ "$CANCEL" = "1" ]; then
|
if [[ "${CANCEL}" = "1" ]]; then
|
||||||
S_NEXTITEM="2"
|
S_NEXTITEM="2"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local _time="$(cat $ANSWER)"
|
local _time="$(cat ${ANSWER})"
|
||||||
# save the time
|
# save the time
|
||||||
# DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
|
# DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
|
||||||
local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
|
local _datetime="$(echo "${_date}" "${_time}" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
|
||||||
date -s "$_datetime"
|
date -s "${_datetime}"
|
||||||
DIALOG --infobox "Syncing systemclock to hardwareclock ..." 0 0
|
DIALOG --infobox "Syncing systemclock to hardwareclock ..." 0 0
|
||||||
HWCLOCK_PARAMS="--systohc"
|
HWCLOCK_PARAMS="--systohc"
|
||||||
dohwclock
|
dohwclock
|
||||||
|
@ -134,17 +134,17 @@ S_NEXTITEM="3"
|
||||||
}
|
}
|
||||||
|
|
||||||
mainmenu() {
|
mainmenu() {
|
||||||
if [ -n "$S_NEXTITEM" ]; then
|
if [[ -n "${S_NEXTITEM}" ]]; then
|
||||||
DEFAULT="--default-item $S_NEXTITEM"
|
DEFAULT="--default-item ${S_NEXTITEM}"
|
||||||
else
|
else
|
||||||
DEFAULT=""
|
DEFAULT=""
|
||||||
fi
|
fi
|
||||||
DIALOG $DEFAULT --backtitle "$TITLE" --title " MAIN MENU " \
|
DIALOG ${DEFAULT} --backtitle "${TITLE}" --title " MAIN MENU " \
|
||||||
--menu "Use the UP and DOWN arrows to navigate menus.\nUse TAB to switch between buttons and ENTER to select." 17 58 13 \
|
--menu "Use the UP and DOWN arrows to navigate menus.\nUse TAB to switch between buttons and ENTER to select." 17 58 13 \
|
||||||
"1" "Select Region and Timezone" \
|
"1" "Select Region and Timezone" \
|
||||||
"2" "Set Time and Date" \
|
"2" "Set Time and Date" \
|
||||||
"3" "$EXIT" 2>$ANSWER
|
"3" "${EXIT}" 2>${ANSWER}
|
||||||
case $(cat $ANSWER) in
|
case $(cat ${ANSWER}) in
|
||||||
"1")
|
"1")
|
||||||
dotimezone
|
dotimezone
|
||||||
;;
|
;;
|
||||||
|
@ -152,7 +152,7 @@ mainmenu() {
|
||||||
dotimeset
|
dotimeset
|
||||||
;;
|
;;
|
||||||
"3")
|
"3")
|
||||||
[ -e /tmp/.tz-running ] && rm /tmp/.tz-running
|
[[ -e /tmp/.tz-running ]] && rm /tmp/.tz-running
|
||||||
clear
|
clear
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
*)
|
*)
|
||||||
|
@ -164,23 +164,23 @@ mainmenu() {
|
||||||
: >/tmp/.timezone
|
: >/tmp/.timezone
|
||||||
: >/tmp/.tz
|
: >/tmp/.tz
|
||||||
|
|
||||||
if [ ! -d $BASEDIR ]; then
|
if [[ ! -d ${BASEDIR} ]]; then
|
||||||
echo "Cannot load timezone data, as none were found in $BASEDIR" >&2
|
echo "Cannot load timezone data, as none were found in ${BASEDIR}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! $(which hwclock) ]; then
|
if [[ ! $(which hwclock) ]]; then
|
||||||
echo "'hwclock' binary not found!" >&2
|
echo "'hwclock' binary not found!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ ! $(which date) ]; then
|
if [[ ! $(which date) ]]; then
|
||||||
echo "'date' binary not found!" >&2
|
echo "'date' binary not found!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e /tmp/.tz-running ]; then
|
if [[ -e /tmp/.tz-running ]]; then
|
||||||
echo "tz already runs on a different console!"
|
echo "tz already runs on a different console!"
|
||||||
echo "Please remove /tmp/.tz-running first to launch tz!"
|
echo "Please remove /tmp/.tz-running first to launch tz!"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -193,3 +193,5 @@ done
|
||||||
|
|
||||||
clear
|
clear
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
# vim: set ts=4 sw=4 et:
|
Loading…
Reference in a new issue