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}") BUS=$(getBus "${LOADER_DISK}")
# Check if machine has EFI # Check if machine has EFI
[ -d /sys/firmware/efi ] && EFI=1 || EFI=0 [ -d /sys/firmware/efi ] && EFI=1 || EFI=0
# NTP Check
localtime
# Print Title centralized # Print Title centralized
clear clear

View File

@ -533,21 +533,28 @@ function ntpCheck() {
local KEYMAP="$(readConfigKey "keymap" "${USER_CONFIG_FILE}")" local KEYMAP="$(readConfigKey "keymap" "${USER_CONFIG_FILE}")"
if [ "${OFFLINE}" == "false" ]; then if [ "${OFFLINE}" == "false" ]; then
# Timezone # Timezone
if [ "${ARCNIC}" == "auto" ]; then local REGION="$(readConfigKey "time.region" "${USER_CONFIG_FILE}")"
local REGION="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)" local TIMEZONE="$(readConfigKey "time.timezone" "${USER_CONFIG_FILE}")"
local TIMEZONE="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)" if [ -z "${REGION}" ] || [ -z "${TIMEZONE}" ]; then
[ -z "${KEYMAP}" ] && KEYMAP="$(curl -m 5 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')" if [ "${ARCNIC}" == "auto" ]; then
else local REGION="$(curl -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)"
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 -m 5 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)"
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 -m 5 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')"
[ -z "${KEYMAP}" ] && KEYMAP="$(curl --interface ${ARCNIC} -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 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 fi
if [ -z "${LAYOUT}" ]; then if [ -z "${LAYOUT}" ]; then
[ -n "${KEYMAP}" ] && KEYMAP="$(echo ${KEYMAP} | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | tr -d '[:punct:]' | tr -d '[:digit:]')" [ -n "${KEYMAP}" ] && KEYMAP="$(echo ${KEYMAP} | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | tr -d '[:punct:]' | tr -d '[:digit:]')"