Skip to main content

TimeZone Date Time for Debian and Ubuntu.

🛠️ System Maintenance & Timezone Setup Script

A production-ready, interactive Bash script for Debian 10–13 and Ubuntu 18–24 that automates system updates, timezone configuration, and NTP time synchronization — all wrapped in a clean, colorized terminal interface with full logging and error handling.


✨ Features

  • 🎨 Beautiful TUI — Colorized output with spinners, progress bars, and ASCII-bordered sections
  • 🔍 Auto OS Detection — Detects Debian 10–13 and Ubuntu 18–24 automatically; exits gracefully on unsupported systems
  • 🔐 Smart Privilege Handling — Works as root or detects sudo availability automatically
  • 📦 System Update — Shows full list of upgradable packages (name → new_version), runs upgrade, dist-upgrade, autoremove, autoclean with live progress
  • 🌍 Timezone Configuration — Interactive menu with common zones, custom input, and full Debian-specific handling
  • 🕐 NTP Synchronization — Enables and verifies systemd-timesyncd with real-time sync confirmation
  • 📝 Full Logging — Every action logged to /var/log/system-maintenance.log with timestamps
  • 💾 Config Backups — Automatically backs up /etc/timezone and /etc/localtime before any changes
  • 🔁 Reboot Prompt — Detects kernel updates and prompts for reboot if needed
  • 🛡️ Error Handling — Uses set -euo pipefail + trap ERR for bulletproof execution

📋 Requirements

Requirement Notes
Bash 4.0+ Pre-installed on all target distros
systemd Required (all target distros use it)
apt Debian/Ubuntu package manager
sudo or root For system-level changes

Missing dependencies (lsb-release, pv, systemd-timesyncd) are automatically installed by the script.


🚀 Usage

🚀 One-Line Download & Execute :
apt update && apt install -y curl && clear && \
curl -s https://docs.greenhome.stream/attachments/7071 -o /tmp/timezone-setup.sh && \
bash /tmp/timezone-setup.sh

OR

1. Download and make executable
chmod +x system-maintenance.sh
2. Run as root or with sudo
# As root
./system-maintenance.sh

# As a sudo-capable user
sudo ./system-maintenance.sh

🔄 What the Script Does (Step by Step)

Step 1 — Privilege Check

Detects if running as root. If not, verifies sudo access before proceeding.

Step 2 — OS Detection

Reads /etc/os-release or uses lsb_release to identify the distro and version. Exits with a clear error message if the OS is unsupported.

Step 3 — Dependency Check

Silently refreshes the apt cache and installs any missing required packages (lsb-release, pv, systemd-timesyncd).

Step 4 — System Update (optional, prompted)

  • Prompts: "Perform full system update? [Y/n]" (defaults to Yes after 30s)
  • Displays a formatted list of all upgradable packages with version arrows (1.2.0 → 1.3.0)
  • Detects kernel updates and flags for reboot
  • Runs with live spinners: apt upgradedist-upgradeautoremoveautoclean

Step 5 — Timezone Configuration (optional, prompted)

  • Shows the current active timezone
  • Prompts: "Set timezone? Default: Europe/Athens [Y/n]"
  • Presents a menu of 9 common timezones + custom input option
  • Validates the chosen timezone against /usr/share/zoneinfo/
  • Backs up existing config before applying changes
  • On Debian: additionally updates /etc/localtime symlink, writes /etc/timezone, and runs dpkg-reconfigure tzdata
  • On Ubuntu: timedatectl set-timezone alone is sufficient
  • Verifies the applied timezone matches the selection

Step 6 — NTP Synchronization (optional, prompted)

  • Prompts: "Enable NTP sync with systemd-timesyncd? [Y/n]"
  • Runs timedatectl set-ntp true
  • Enables and starts systemd-timesyncd via systemctl
  • Waits up to 15 seconds for sync confirmation with a live progress bar
  • Displays service status and full timedatectl status output

Step 7 — Final Summary

Prints a formatted table with:

  • Detected OS and version
  • Active timezone
  • NTP enabled/synchronized state
  • Current date and time
  • Log file path
  • Reboot prompt if a kernel update was applied

📁 Log File

All actions are recorded in: /var/log/system-maintenance.log If the script lacks write permission to /var/log/, it falls back to: /tmp/system-maintenance.log

Log entries include timestamps and status for every operation performed.


🌍 Supported Timezones (Built-in Menu)

# Timezone Offset
1 Europe/Athens (default) UTC+2/+3
2 Europe/London UTC+0/+1
3 Europe/Berlin UTC+1/+2
4 Europe/Paris UTC+1/+2
5 America/New_York UTC-5/-4
6 America/Chicago UTC-6/-5
7 America/Denver UTC-7/-6
8 America/Los_Angeles UTC-8/-7
9 UTC UTC+0
0 Custom Manual input

🐧 Compatibility Matrix

OS Versions Tested
Debian 10 (Buster), 11 (Bullseye), 12 (Bookworm), 13 (Trixie)
Ubuntu 18.04, 20.04, 22.04, 24.04
Other Any non-Debian/Ubuntu ❌ Exits gracefully

⚠️ Notes

  • The script is idempotent — safe to run multiple times without side effects
  • Config files are backed up with a timestamp suffix before any modification
  • All prompts have a 30-second timeout that defaults to the safe/recommended option
  • systemd-timesyncd and chrony should not run simultaneously; this script only manages timesyncd