commit 53f4e1f3584fdb0d9d67819fb3b705036ac10852 Author: allan Date: Thu Oct 23 15:41:31 2025 +0200 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3eaaa81 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Allan Christensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8908b82 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# NTP Client for Ubuntu 24.04 Server +[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#) +[![Shell](https://img.shields.io/badge/shell-bash-121011)](#) +[![App](https://img.shields.io/badge/app-ntp_client-0098D4)](#) +[![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE) + +Automated Bash installer script for configuring an **NTP client** on Ubuntu 24.04 Server. + +This is a **production-focused installer**, not a demo. + +--- + +### Preparing +Update your package index before running the installer: + +``` +sudo apt update -y +``` + +### Download the Script +Clone the repository from your Git server: + +``` +git clone https://git.x-files.dk/server/ntp-client-ubuntu.git +``` + +``` +cd ntp-client-ubuntu +``` + +### Usage +Run the script using: + +``` +sudo ./ntp-client-install +``` + +### Check if it's Working +Use the following command to verify synchronization with NTP servers: + +``` +ntpq -p +``` + +### Post-install +Nothing to do. + +--- + +### More Information + +More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) + +--- + +### License +Licensed under the [MIT License](./LICENSE). + +--- diff --git a/last-tested b/last-tested new file mode 100644 index 0000000..3f1f6ef --- /dev/null +++ b/last-tested @@ -0,0 +1,4 @@ +------------------------------------ +Last tested: 15-10-2025 (DD-MM-YYYY) +Environment: Ubuntu Server 24.04 LTS +------------------------------------ diff --git a/ntp-client-install b/ntp-client-install new file mode 100755 index 0000000..c9627c1 --- /dev/null +++ b/ntp-client-install @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +# Author : Allan Christensen +# First Created : 05012022 (DD-MM-YYYY) +# Description : Installs Ntp client on Ubuntu 24.04 +# License : MIT License (see LICENSE file for details) + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo ""; exit 1; fi + +# +# Install and enable NTP +# +apt install -y ntp ntpdate && systemctl enable ntp + +# +# Disable systemd-timesyncd NTP +# +timedatectl set-ntp off + +# +# Sync time once +# +ntpdate -u 0.pool.ntp.org + +# +# Determine which NTP config file to use +# +# Default NTP config file +conf_file="/etc/ntp.conf" + +# +# If ntpsec is installed, override with ntpsec's config file +# +if [ -f /etc/ntpsec/ntp.conf ]; then conf_file="/etc/ntpsec/ntp.conf" ; fi + +# +# Backup existing config file +# +backup_file="${conf_file}.bak"; cp "$conf_file" "$backup_file" + +# +# Define NTP servers +# +ntp_servers="server 0.pool.ntp.org +server 1.pool.ntp.org +server 2.pool.ntp.org +server 3.pool.ntp.org" + +# +# Comment out existing pool servers +# +sed -i '/pool.ntp.org/ s/^/# /g' "$conf_file" + +# +# Add the new defined servers +tmp_file="/tmp/ntpconf" ; printf "%s\n" "$ntp_servers" > "$tmp_file" + +# Insert after a line containing "Specify one" if it exists else append at the end +if grep -q "Specify one" "$conf_file"; then + sed -i "/Specify one/r $tmp_file" "$conf_file" +else + cat "$tmp_file" >> "$conf_file" +fi + +# +# Restart NTP service +# +systemctl restart ntp + +# +# Clean up +# +rm -f "$tmp_file" + +# +# All done +# +printf "\nAll Done...\n" + +# +# End of script +#