You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ublinux-init/ublinux/rc.preinit.d/21-ntp

35 lines
1.5 KiB

#!/usr/bin/env bash
#
# Initial script for Live operating system
# This script are launching before starting init from linux-live script.
# Current dir allways must be set to root (/)
# All system path must be relative, except initrd dirs
ENABLED=yes
[ "$ENABLED" != "yes" ] && exit 0
DEBUGMODE=no
PATH=.:/:/usr/bin:/usr/local/bin:/usr/local/sbin
unset ROOTFS; [[ -d /usr/lib/ublinux ]] || ROOTFS=.
SOURCE=${ROOTFS}/usr/lib/ublinux/functions; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
SOURCE=${ROOTFS}/usr/lib/ublinux/os-config; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
debug_mode "$0" "$@"
SYSCONF="${ROOTFS}/${SYSCONF}"
SOURCE=${SYSCONF}/config; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
SOURCE=${SYSCONF}/network; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
NTPSERVERS_DEFAULT="ntp1.vniiftri.ru ntp2.vniiftri.ru ntp3.vniiftri.ru ntp4.vniiftri.ru ntp21.vniiftri.ru ru.pool.ntp.org"
NTPSERVERS_FALLBACK="0.ru.pool.ntp.org 1.ru.pool.ntp.org 2.ru.pool.ntp.org 3.ru.pool.ntp.org"
[[ -n $1 ]] && NTPSERVERS=$1
if [[ -n ${NTPSERVERS} && ${NTPSERVERS,,} != "dhcp" ]]; then
[[ ${NTPSERVERS,,} == "default" ]] && NTPSERVERS=${NTPSERVERS_DEFAULT}
mkdir -p ${ROOTFS}/etc/systemd/timesyncd.conf.d
echo "[Time]" > ${ROOTFS}/etc/systemd/timesyncd.conf.d/ubconfig.conf
echo "NTP=${NTPSERVERS}" | tr ',;' ' ' >> ${ROOTFS}/etc/systemd/timesyncd.conf.d/ubconfig.conf
echo "FallbackNTP=${NTPSERVERS_FALLBACK}" >> ${ROOTFS}/etc/systemd/timesyncd.conf.d/ubconfig.conf
fi