2013-07-22 17:57:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-01-27 08:22:33 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2008-10-20 22:39:25 +02:00
|
|
|
# written by Tobias Powalowski <tpowa@archlinux.org>
|
2023-07-17 08:34:15 +02:00
|
|
|
. /usr/lib/archboot/basic-common.sh
|
2023-07-17 08:43:20 +02:00
|
|
|
_TITLE="Archboot ${_RUNNING_ARCH} | Basic Setup | Clock Configuration"
|
2023-07-13 14:56:53 +02:00
|
|
|
|
2023-07-14 15:34:35 +02:00
|
|
|
_hwclock() {
|
2023-07-14 15:48:10 +02:00
|
|
|
_DATE_PROGRAM=timedatectl
|
2023-01-09 18:17:27 +01:00
|
|
|
echo 0.0 0 0.0 > /etc/adjtime
|
|
|
|
echo 0 >> /etc/adjtime
|
2023-07-14 15:53:06 +02:00
|
|
|
echo UTC >> /etc/adjtime
|
|
|
|
timedatectl set-local-rtc 0
|
2008-10-20 22:39:25 +02:00
|
|
|
}
|
|
|
|
|
2023-07-14 15:34:35 +02:00
|
|
|
_timezone () {
|
2023-07-14 15:31:43 +02:00
|
|
|
_SET_ZONE=""
|
2023-07-21 21:15:00 +02:00
|
|
|
if ping -c1 www.google.com &>/dev/null; then
|
2023-07-21 22:03:14 +02:00
|
|
|
_ZONE="$(curl -s "http://ip-api.com/csv/?fields=timezone")"
|
2023-07-21 21:15:00 +02:00
|
|
|
_SET_ZONE=1
|
|
|
|
fi
|
2023-07-14 15:31:43 +02:00
|
|
|
while [[ -z "${_SET_ZONE}" ]]; do
|
|
|
|
_CONTINUE=""
|
|
|
|
while [[ -z "${_CONTINUE}" ]]; do
|
|
|
|
_REGIONS="America - Europe - Africa - Asia - Australia -"
|
|
|
|
#shellcheck disable=SC2086
|
2023-07-15 13:53:54 +02:00
|
|
|
if _dialog --cancel-label "${_LABEL}" --title " Timezone Region " --menu "" 11 30 6 ${_REGIONS} 2>${_ANSWER}; then
|
2023-07-14 15:31:43 +02:00
|
|
|
_REGION=$(cat ${_ANSWER})
|
|
|
|
_ZONES=""
|
|
|
|
_CONTINUE=1
|
|
|
|
else
|
|
|
|
_abort
|
|
|
|
fi
|
|
|
|
done
|
2023-07-14 15:42:43 +02:00
|
|
|
_ZONES=""
|
|
|
|
for i in $(timedatectl --no-pager list-timezones | grep -w "${_REGION}" | cut -d '/' -f 2 | sort -u); do
|
|
|
|
_ZONES="${_ZONES} ${i} -"
|
2023-07-14 15:31:43 +02:00
|
|
|
done
|
2023-07-14 15:42:43 +02:00
|
|
|
#shellcheck disable=SC2086
|
2023-07-15 08:35:49 +02:00
|
|
|
if _dialog --cancel-label "Back" --title " Timezone " --menu "" 21 30 16 ${_ZONES} 2>${_ANSWER}; then
|
2023-07-14 15:42:43 +02:00
|
|
|
_SET_ZONE="1"
|
|
|
|
_ZONE=$(cat ${_ANSWER})
|
|
|
|
[[ "${_ZONE}" == "${_REGION}" ]] || _ZONE="${_REGION}/${_ZONE}"
|
|
|
|
else
|
|
|
|
_SET_ZONE=""
|
|
|
|
fi
|
2023-01-09 09:05:40 +01:00
|
|
|
done
|
2023-07-21 21:15:00 +02:00
|
|
|
_dialog --infobox "Setting Timezone to ${_ZONE}..." 3 50
|
|
|
|
timedatectl set-timezone "${_ZONE}"
|
2023-07-22 07:14:16 +02:00
|
|
|
sleep 2
|
2008-10-20 22:39:25 +02:00
|
|
|
|
2023-07-14 15:34:35 +02:00
|
|
|
_timeset() {
|
2023-07-14 15:47:11 +02:00
|
|
|
_hwclock
|
|
|
|
# check internet connection
|
|
|
|
if ping -c1 www.google.com &>/dev/null; then
|
2023-07-19 08:39:09 +02:00
|
|
|
_dialog --infobox "Syncing clock with NTP pool..." 3 45
|
2023-07-22 07:14:16 +02:00
|
|
|
sleep 2
|
2023-07-19 08:39:09 +02:00
|
|
|
# sync immediatly with standard pool
|
|
|
|
if ! systemctl restart systemd-timesyncd; then
|
|
|
|
_dialog --msgbox "An error has occured, time was not changed!" 0 0
|
|
|
|
_SET_TIME=""
|
|
|
|
else
|
|
|
|
# enable background syncing
|
|
|
|
timedatectl set-ntp 1
|
|
|
|
_SET_TIME="1"
|
2023-07-14 15:12:42 +02:00
|
|
|
fi
|
2023-07-14 15:47:11 +02:00
|
|
|
fi
|
|
|
|
if [[ -z "${_SET_TIME}" ]]; then
|
|
|
|
timedatectl set-ntp 0
|
2023-07-14 16:01:57 +02:00
|
|
|
# display and ask to set date/time
|
2023-07-21 15:27:59 +02:00
|
|
|
_dialog --title " Date " --no-cancel --calendar "Use <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2>"${_ANSWER}"
|
|
|
|
_DATE="$(cat "${_ANSWER}")"
|
|
|
|
_dialog --title " Time " --no-cancel --timebox "Use <TAB> to navigate and up/down to change values." 0 0 2>"${_ANSWER}"
|
|
|
|
_TIME="$(cat "${_ANSWER}")"
|
2023-07-14 15:47:11 +02:00
|
|
|
# save the time
|
|
|
|
# DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
|
|
|
|
_DATETIME="$(echo "${_DATE}" "${_TIME}" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
|
|
|
|
timedatectl set-time "${_DATETIME}"
|
2023-07-14 16:20:37 +02:00
|
|
|
_SET_TIME="1"
|
2023-07-14 15:47:11 +02:00
|
|
|
fi
|
2008-10-20 22:39:25 +02:00
|
|
|
}
|
2023-03-07 17:29:18 +01:00
|
|
|
|
2023-07-17 08:34:15 +02:00
|
|
|
_check
|
2023-07-14 15:47:11 +02:00
|
|
|
_SET_TIME=""
|
|
|
|
while [[ -z "${_SET_TIME}" ]]; do
|
2023-07-14 16:34:34 +02:00
|
|
|
_timezone
|
|
|
|
_timeset
|
2023-07-14 15:47:11 +02:00
|
|
|
done
|
2023-07-21 16:00:05 +02:00
|
|
|
_dialog --infobox "Clock configuration completed successfully." 3 50
|
2023-07-22 07:14:16 +02:00
|
|
|
sleep 2
|
2023-07-17 08:34:15 +02:00
|
|
|
_cleanup
|
2013-07-22 17:57:18 +02:00
|
|
|
# vim: set ts=4 sw=4 et:
|