arc: rewrite timezone/region check

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-09-05 22:36:30 +02:00
parent 3fba97c0c9
commit 949ab7fe2e
2 changed files with 23 additions and 14 deletions

View File

@ -19,6 +19,8 @@ ARCBRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")"
BUS=$(getBus "${LOADER_DISK}")
# Check if machine has EFI
[ -d /sys/firmware/efi ] && EFI=1 || EFI=0
# NTP Check
localtime
# Print Title centralized
clear

View File

@ -533,21 +533,28 @@ function ntpCheck() {
local KEYMAP="$(readConfigKey "keymap" "${USER_CONFIG_FILE}")"
if [ "${OFFLINE}" == "false" ]; then
# Timezone
if [ "${ARCNIC}" == "auto" ]; then
local REGION="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)"
local TIMEZONE="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)"
[ -z "${KEYMAP}" ] && KEYMAP="$(curl -m 5 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')"
else
local REGION="$(curl --interface ${ARCNIC} -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)"
local TIMEZONE="$(curl --interface ${ARCNIC} -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)"
[ -z "${KEYMAP}" ] && KEYMAP="$(curl --interface ${ARCNIC} -m 5 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')"
local REGION="$(readConfigKey "time.region" "${USER_CONFIG_FILE}")"
local TIMEZONE="$(readConfigKey "time.timezone" "${USER_CONFIG_FILE}")"
if [ -z "${REGION}" ] || [ -z "${TIMEZONE}" ]; then
if [ "${ARCNIC}" == "auto" ]; then
local REGION="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)"
local TIMEZONE="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)"
[ -z "${KEYMAP}" ] && KEYMAP="$(curl -m 5 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')"
else
local REGION="$(curl --interface ${ARCNIC} -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)"
local TIMEZONE="$(curl --interface ${ARCNIC} -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)"
[ -z "${KEYMAP}" ] && KEYMAP="$(curl --interface ${ARCNIC} -m 5 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')"
fi
writeConfigKey "time.region" "${REGION}" "${USER_CONFIG_FILE}"
writeConfigKey "time.timezone" "${TIMEZONE}" "${USER_CONFIG_FILE}"
fi
if [ -n "${REGION}" ] && [ -n "${TIMEZONE}" ]; then
ln -fs /usr/share/zoneinfo/${REGION}/${TIMEZONE} /etc/localtime
TZ="${REGION}/${TIMEZONE}"
# NTP
/etc/init.d/S49ntpd restart > /dev/null 2>&1
#hwclock --systohc > /dev/null 2>&1
fi
writeConfigKey "time.region" "${REGION}" "${USER_CONFIG_FILE}"
writeConfigKey "time.timezone" "${TIMEZONE}" "${USER_CONFIG_FILE}"
ln -fs /usr/share/zoneinfo/${REGION}/${TIMEZONE} /etc/localtime
# NTP
/etc/init.d/S49ntpd restart > /dev/null 2>&1
#hwclock --systohc > /dev/null 2>&1
fi
if [ -z "${LAYOUT}" ]; then
[ -n "${KEYMAP}" ] && KEYMAP="$(echo ${KEYMAP} | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | tr -d '[:punct:]' | tr -d '[:digit:]')"