ntp-client-install/ntp-client-install
2024-11-08 12:25:13 +01:00

39 lines
999 B
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 $scriptdir\n\n"; exit 1; fi
#
# 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
rm ntpconf
#
# End of script
#