#!/usr/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/ntp-update-leap-file - download and update leap second file # # Copyright (c) 2015-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation: jed # Last Update: $Id$ # # Usage: ntp-update-leap-file [--quiet][--file filename] # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # read eislib if [ -f /var/install/include/eislib ] then . /var/install/include/eislib fi # activate debug output #debug_ntp=true if ${debug_ntp:-false} then exec 2> /tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi #---------------------------------------------------------------------------- # my own echo #---------------------------------------------------------------------------- myecho () { if [ "${quiet}" != '--quiet' ] then # be verbose _me_exit=0 _me_switch='' _me_outstr='' while [ ${_me_exit} -eq 0 ] do case $1 in -n|-*std|*stdbr|-*info|-*warn|-*error|-*link|-*ok|-*fail|-*tty|-*html|-*file ) _me_switch="${_me_switch}$1 " shift ;; * ) _me_outstr="$*" _me_exit=1 ;; esac done if [ "${_EISLIB}" = 'true' ] then mecho ${_me_switch} "${_me_outstr}" else if [ -n "${_me_switch}" ] then # --info "TEXT" -> "INFO:Text" echo "`echo "${_me_switch}" | tr '[:lower:]' '[:upper:]' | sed 's/\-//g'`:${_me_outstr}" else echo "${_me_outstr}" fi fi fi } #============================================================================ # main #============================================================================ ntp_conffile=/etc/ntp.conf ntp_leapfile=`grep "^leapfile" ${ntp_conffile} | sed 's/^[^ ]* *//'` ntp_tmpfile=/tmp/ntp-leap.$$ download_url='https://data.iana.org/time-zones/data/leap-seconds.list' quiet='' download_only=0 if [ $# -gt 0 ] then # read parameter(s) while [ $# -gt 0 ] do case $1 in -*file ) # overwrite destination file if [ -n "$2" ] then download_only=1 ntp_leapfile="$2" shift fi shift ;; -*quiet ) quiet='--quiet' shift ;; * ) # skip unknown parameters shift ;; esac done fi if [ "${quiet}" != '--quiet' -a "${_EISLIB}" = 'true' ] then clrhome fi myecho --info "NTP download/update leap-second file" myecho myecho "downloading leap-seconds file '${download_url}' ..." myecho # set default generic error code wget_ret=1 # check availability pf wget.sh script WGETSH=`which wget.sh 2>/dev/null` if [ $? -eq 0 ] then # download command found for NUM in 1 2 3 4 5 do if [ "${quiet}" = '--quiet' ] then ${WGETSH} -O ${ntp_tmpfile} ${download_url} >/dev/null 2>/dev/null wget_ret=$? else ${WGETSH} -O ${ntp_tmpfile} ${download_url} wget_ret=$? fi if [ ${wget_ret} -eq 0 ] then break else if [ ${NUM} -ne 5 ] then sleep ${NUM} fi fi done if [ ${wget_ret} -eq 0 ] then # download successful if [ -s ${ntp_tmpfile} ] then # downloaded file not empty cmp -s ${ntp_tmpfile} ${ntp_leapfile} if [ $? -eq 0 ] then # files are the same myecho "leap-second file '${ntp_leapfile}' is up-to-date." else # files differ myecho "updating file ..." if [ ${download_only} -eq 1 ] then # copy file to destination directory cp ${ntp_tmpfile} ${ntp_leapfile} else if [ -f ${ntp_leapfile} ] then # backup previous file cp ${ntp_leapfile} ${ntp_leapfile}.backup fi # move file to destination directory cp ${ntp_tmpfile} ${ntp_leapfile} /var/install/config.d/ntp.sh --quiet --setrights /etc/init.d/ntp ${quiet} restart fi fi else myecho --error "Downloaded leap-seconds file is empty!" fi else myecho --error "Download of the leap-seconds file failed!" fi fi rm -f ${ntp_tmpfile} if [ ${download_only} -eq 0 -a "${quiet}" != '--quiet' ] then myecho anykey fi #============================================================================ # end #============================================================================ exit ${wget_ret}