ntp-client-install/ntp-client-install
2025-05-25 11:25:36 +00:00

47 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
#############################################################################
# First Created: 08012021 Author: Allan Desc: Installs Ntp client on Ubuntu #
#############################################################################
#
# Are we root
#
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo ""; exit 1; fi
#
# Are we in the right directory
#
scriptdir="ntp-client-install" && whereami=$(pwd |awk -F'/' '{print $NF}')
if [ "$whereami" != "$scriptdir" ]; then printf "\nWrong directory! Script must be run from %s\n\n" "$scriptdir"; exit 1; fi
#
# Define variables
#
line () { printf -- '-%.0s' {1..50}; printf '\n'; }
#
# Ntp configuration
#
ntpconf="
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
"
timedatectl set-ntp off
apt install -y ntpdate
apt install -y ntp
sed -i '/ubuntu.pool.ntp.org/ s/^/# /g' /etc/ntpsec/ntp.conf
printf '%s\n' "${ntpconf[@]}" |sed '$d' > ntpconf
sed -i "/Specify one/r ntpconf" /etc/ntpsec/ntp.conf
systemctl restart ntp
#
# All done clean up and display output
#
rm ntpconf
clear ; printf "\n" ; line ; printf "All Done...\n" ; line ; printf "\n"
#
# End of script
#