Welcome to kriss.run!


Back

timezone.sh

#!/usr/bin/env bash

__set_timezone() {
    if [ "$EUID" -ne 0 ]; then
        echo "Please run as root."
        exit 1
    fi

    if [ -z "$(command -v timedatectl)" ]; then
        echo "timedatectl is not available on this system."
        exit 1
    fi

    current_timezone=$(timedatectl | grep "Time zone" | awk '{print $3}')
    target_timezone="Europe/Oslo"

    echo "Current timezone: $current_timezone"

    if [ "$current_timezone" != "$target_timezone" ]; then
        echo "Setting the timezone to $target_timezone"
        timedatectl set-timezone "$target_timezone"
    else
        echo "The timezone is already set to $target_timezone"
    fi
}

__set_timezone