You've already forked ntp-client-ubuntu
initial commit
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -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.
|
||||
59
README.md
Normal file
59
README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# NTP Client for Ubuntu 24.04 Server
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](./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).
|
||||
|
||||
---
|
||||
4
last-tested
Normal file
4
last-tested
Normal file
@@ -0,0 +1,4 @@
|
||||
------------------------------------
|
||||
Last tested: 15-10-2025 (DD-MM-YYYY)
|
||||
Environment: Ubuntu Server 24.04 LTS
|
||||
------------------------------------
|
||||
85
ntp-client-install
Executable file
85
ntp-client-install
Executable file
@@ -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
|
||||
#
|
||||
Reference in New Issue
Block a user