67 lines
1.8 KiB
Bash
67 lines
1.8 KiB
Bash
# ------------------------------------------------------------------------------
|
|
# Configure NTP
|
|
# This file is part of the init.sh project
|
|
# Copyright (c) 2019-2022 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.6"
|
|
export DEP_conf_ntp=""
|
|
|
|
conf_ntp()
|
|
{
|
|
if [[ $(pidof systemd) ]]; then
|
|
prnt I "Disabling 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 "Installing NTP configuration file..."
|
|
local dest="/etc/ntp.conf.work"
|
|
backup_dist /etc/ntp.conf
|
|
tag_file $dest
|
|
install_file 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_must_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
|