[Git][NTPsec/ntpsec][master] 2 commits: ntpleapfetch: do not wait forever to read the remote leapfile.

Gary E. Miller gitlab at mg.gitlab.com
Wed Sep 27 01:51:31 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
b491a456 by Gary E. Miller at 2017-09-26T18:38:18-07:00
ntpleapfetch: do not wait forever to read the remote leapfile.

- - - - -
1a218f3b by Gary E. Miller at 2017-09-26T18:50:09-07:00
ntpleapfetch: allow sha1sum or shasum to be used.

This fixes CentOS 6 and other older distributions.

- - - - -


1 changed file:

- ntpclients/ntpleapfetch


Changes:

=====================================
ntpclients/ntpleapfetch
=====================================
--- a/ntpclients/ntpleapfetch
+++ b/ntpclients/ntpleapfetch
@@ -11,7 +11,7 @@ VERSION="1.003"
 # leap-seconds file manager/updater
 
 # Depends on:
-#  wget sed, tr, shasum, logger
+#  wget sed, tr, shasum/sha1sum, logger
 
 # ########## Default configuration ##########
 #
@@ -44,7 +44,7 @@ LOGFAC=daemon
 
 PATHLIST="/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
 
-REQUIREDCMDS=" wget logger tr sed shasum"
+REQUIREDCMDS=" wget logger tr sed"
 
 SELF="`basename $0`"
 
@@ -107,7 +107,7 @@ need not be run more frequently than about once every three weeks.
 
 For cron-friendly behavior, define CRONJOB=1 in the crontab.
 
-This script depends on:$REQUIREDCMDS
+This script depends on: sha1sum/shasum $REQUIREDCMDS
 
 Version $VERSION
 EOF
@@ -211,6 +211,16 @@ for P in $REQUIREDCMDS ; do
     exit 1
 done
 
+# find sha1sum or shasum
+if >/dev/null 2>&1 which "sha1sum" ; then
+    SHASUM="sha1sum"
+elif >/dev/null 2>&1 which "shasum" ; then
+    SHASUM="shasum"
+else
+    echo "FATAL: Can not find sha1sum or shasum command, please install"
+    exit 1
+fi
+
 # Handle logging
 
 if ! LOGGER="`2>/dev/null which logger`" ; then
@@ -266,10 +276,12 @@ function verifySHA1 {
     local DATA="`echo \"$RAW\" | sed -e'/^#h/d' -e's/^#[\$@]//g' | tr -d '[:space:]'`"
 
     # Compute the SHA1 hash of the data, removing the marker and filename
-    # Computed in binary mode, which shouldn't matter since whitespace has been removed
-    # shasum comes in several flavors; a portable one is available in Perl (with Digest::SHA)
+    # Computed in binary mode, which shouldn't matter since whitespace
+    # has been removed
+    # shasum/sha1sum comes in several flavors;
+    # a portable one is available in Perl (with Digest::SHA)
 
-    local DSHA1="`echo -n \"$DATA\" | shasum | sed -e's/[? *].*$//'`"
+    local DSHA1="`echo -n \"$DATA\" | $SHASUM | sed -e's/[? *].*$//'`"
 
     # Extract the file's hash. Restore any leading zeroes in hash segments.
 
@@ -336,7 +348,7 @@ if [ -n "$FORCE" ] || ! verifySHA1 $LEAPFILE "$VERBOSE" || [ $EXPIRES -lt `date 
         if [ -n "$VERBOSE" ]; then
             log "info" "Attempting download from $LEAPSRC, try $TRY.."
         fi
-        if wget $PROTO $PREFER -o ${TMPFILE}.log $LEAPSRC -O $TMPFILE ; then
+        if wget -T 10 $PROTO $PREFER -o ${TMPFILE}.log $LEAPSRC -O $TMPFILE ; then
             log "info" "Download of $LEAPSRC succeeded"
             if [ -n "$VERBOSE" ]; then
                 cat ${TMPFILE}.log



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/97cfaa6a4a8eb7654485492b05397b70577030c7...1a218f3b34d1eaf45404b819ef2a2a73bac123a7

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/97cfaa6a4a8eb7654485492b05397b70577030c7...1a218f3b34d1eaf45404b819ef2a2a73bac123a7
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170927/8ef992e7/attachment.html>


More information about the vc mailing list