diff --git a/scripts/post_install/auto_post_install.sh b/scripts/post_install/auto_post_install.sh index 0d60d03..75da603 100644 --- a/scripts/post_install/auto_post_install.sh +++ b/scripts/post_install/auto_post_install.sh @@ -164,7 +164,7 @@ remove_subscription_banner() { # ========================================================== -configure_time_sync() { +configure_time_sync_() { msg_info2 "$(translate "Configuring system time settings...")" @@ -204,6 +204,44 @@ configure_time_sync() { } + + +configure_time_sync() { + msg_info2 "$(translate "Configuring system time settings...")" + + this_ip=$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null) + if [ -z "$this_ip" ]; then + msg_warn "$(translate "Failed to obtain public IP address - keeping current timezone settings")" + return 0 + fi + + timezone=$(curl -s --connect-timeout 10 "https://ipapi.co/${this_ip}/timezone" 2>/dev/null) + if [ -z "$timezone" ] || [ "$timezone" = "undefined" ]; then + msg_warn "$(translate "Failed to determine timezone from IP address - keeping current timezone settings")" + return 0 + fi + + msg_ok "$(translate "Found timezone $timezone for IP $this_ip")" + + if timedatectl set-timezone "$timezone"; then + msg_ok "$(translate "Timezone set to $timezone")" + + if timedatectl set-ntp true; then + msg_ok "$(translate "Time settings configured - Timezone:") $timezone" + register_tool "time_sync" true + + systemctl restart postfix 2>/dev/null || true + else + msg_warn "$(translate "Failed to enable automatic time synchronization")" + fi + else + msg_warn "$(translate "Failed to set timezone - keeping current settings")" + fi +} + + + + # ========================================================== skip_apt_languages() { msg_info "$(translate "Configuring APT to skip downloading additional languages...")"