Files
init.sh/modules/conf_ntp.sh
2021-12-06 17:06:49 +01:00

66 lines
1.8 KiB
Bash

# ------------------------------------------------------------------------------
# Configure NTP
# This file is part of the init.sh project
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# Variable:
# * NTPSERVERS: list of NTP servers
# ------------------------------------------------------------------------------
export VER_conf_ntp="0.1.3"
export DEP_conf_ntp=""
conf_ntp()
{
if [[ $(pidof systemd) ]]; then
prnt I "Désactivation de Systemd-timesyncd..."
systemctl disable systemd-timesyncd || true
fi
prnt I "Installing ntp daemon..."
pkginst ntp
prnt I "Stopping service ntp..."
svc_stop ntp
prnt I "Installation du fichier de configuration de NTP."
local dest="/etc/ntp.conf.work"
backupdist /etc/ntp.conf
installfile ntp.conf $dest
local line=""
for srv in $NTP_SERVERS; do
line="${line}server $srv iburst\n"
done
sed -i -e "s/@SERVERLIST@/$line/" $dest &&
echo "# Generated on $(stdtime)" >> $dest &&
mv -fv $dest /etc/ntp.conf
prnt I "Starting service ntp..."
svc_start ntp
sleep 2 # short sleep so we're sure daemon is ready
ntptime
}
# NTP
precheck_conf_ntp()
{
if [[ -z $NTP_SERVERS ]]; then
prnt E "No configured NTP server!"
die 151
else
file_exists ntp.conf
prnt m "The NTP servers to be used will be:"
for srv in $NTP_SERVERS; do
prnt m " * $srv"
done
fi
}
export -f conf_ntp
export -f precheck_conf_ntp
# EOF