From 843fa0aa305e8162966ae30dc26a6144dcaec862 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Thu, 31 Oct 2024 10:52:53 +0100 Subject: [PATCH] functions: optimize logic for online check Signed-off-by: AuxXxilium --- files/initrd/opt/arc/include/functions.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/files/initrd/opt/arc/include/functions.sh b/files/initrd/opt/arc/include/functions.sh index a8e64292..1fc146d0 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -499,16 +499,19 @@ function onlineCheck() { REGION="$(curl -m 10 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f1)" TIMEZONE="$(curl -m 10 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)" [ -z "${KEYMAP}" ] && KEYMAP="$(curl -m 10 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')" - writeConfigKey "time.region" "${REGION}" "${USER_CONFIG_FILE}" - writeConfigKey "time.timezone" "${TIMEZONE}" "${USER_CONFIG_FILE}" if [ -n "${REGION}" ] && [ -n "${TIMEZONE}" ]; then - ln -sf "/usr/share/zoneinfo/${REGION}/${TIMEZONE}" /etc/localtime writeConfigKey "arc.offline" "false" "${USER_CONFIG_FILE}" [ $(echo "${ARC_VERSION}" | grep "dev" | wc -l) -eq 0 ] && NEWTAG="$(curl -m 10 -skL "https://api.github.com/repos/AuxXxilium/arc/releases" | jq -r ".[].tag_name" | grep -v "dev" | sort -rV | head -1)" [ $(echo "${ARC_VERSION}" | grep "dev" | wc -l) -gt 0 ] && NEWTAG="$(curl -m 10 -skL "https://api.github.com/repos/AuxXxilium/arc/releases" | jq -r ".[].tag_name" | grep "dev" | sort -rV | head -1)" + writeConfigKey "time.region" "${REGION}" "${USER_CONFIG_FILE}" + writeConfigKey "time.timezone" "${TIMEZONE}" "${USER_CONFIG_FILE}" + updateOffline else + REGION="$(readConfigKey "time.region" "${USER_CONFIG_FILE}")" + TIMEZONE="$(readConfigKey "time.timezone" "${USER_CONFIG_FILE}")" writeConfigKey "arc.offline" "true" "${USER_CONFIG_FILE}" fi + [ -n "${TIMEZONE}" ] && [ -n "${REGION}" ] && ln -sf "/usr/share/zoneinfo/${REGION}/${TIMEZONE}" /etc/localtime if [ -z "${LAYOUT}" ]; then [ -n "${KEYMAP}" ] && KEYMAP="$(echo ${KEYMAP} | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | tr -d '[:punct:]' | tr -d '[:digit:]')" [ -n "${KEYMAP}" ] && writeConfigKey "keymap" "${KEYMAP}" "${USER_CONFIG_FILE}"