| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| CONF=/etc/ntp.conf |
| SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface} |
| |
| ntp_replace_conf() { |
| echo "$1" | diff -q ${CONF} - > /dev/null 2>&1 |
| if [ $? -eq 1 ]; then |
| echo "$1" > ${CONF} |
| restorecon ${CONF} >/dev/null 2>&1 |
| systemctl try-restart ntpd.service > /dev/null 2>&1 || |
| service ntpd condrestart > /dev/null 2>&1 |
| fi |
| } |
| |
| ntp_config() { |
| if [ ! "${PEERNTP}" = "no" ] && [ -n "${new_ntp_servers}" ] && |
| [ -e ${CONF} ] && [ -d ${SAVEDIR} ]; then |
| local conf=$(grep -v '^server .* # added by /sbin/dhclient-script$' < ${CONF}) |
| local unique_servers=$(comm -23 \ |
| <(for s in ${new_ntp_servers}; do echo $s; done | sort -u) \ |
| <(echo "$conf" | awk '$1=="peer"||$1=="server"{print $2}' | sort -u)) |
| |
| conf=$(echo "$conf" |
| for s in ${unique_servers}; do |
| echo "server ${s} ${NTPSERVERARGS} # added by /sbin/dhclient-script" |
| done) |
| |
| [ -f ${SAVECONF} ] || touch ${SAVECONF} |
| ntp_replace_conf "$conf" |
| fi |
| } |
| |
| ntp_restore() { |
| if [ -e ${CONF} ] && [ -f ${SAVECONF} ]; then |
| local conf=$(grep -v '^server .* # added by /sbin/dhclient-script$' < ${CONF}) |
| |
| ntp_replace_conf "$conf" |
| rm -f ${SAVECONF} |
| fi |
| } |