81 lines
2.0 KiB
Bash
81 lines
2.0 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..."
|
|
if [[ -n $NTP_SERV ]]; then
|
|
svc_stop $NTP_SERV
|
|
else
|
|
svc_stop ntp
|
|
fi
|
|
|
|
if [[ -n $NTP_SERV ]]; then
|
|
local conf_file="/etc/$NTP_SERV/ntp.conf"
|
|
else
|
|
local conf_file="/etc/ntp.conf"
|
|
fi
|
|
|
|
prnt I "Installing NTP configuration file..."
|
|
local dest="${conf_file}.work"
|
|
backup_dist "$conf_file"
|
|
install_file ntp.conf "$dest"
|
|
tag_file "$dest"
|
|
local line=""
|
|
for srv in $NTP_SERVERS; do
|
|
line="${line}server $srv iburst\n"
|
|
done
|
|
sed -i -e "s/@SERVERLIST@/$line/" "$dest" &&
|
|
mv -fv "$dest" "$conf_file"
|
|
|
|
prnt I "Starting service ntp..."
|
|
|
|
if [[ -n $NTP_SERV ]]; then
|
|
svc_start $NTP_SERV
|
|
else
|
|
svc_start ntp
|
|
fi
|
|
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
|