[Git][NTPsec/ntpsec][master] 3 commits: BASHisms
Matt Selsky
gitlab at mg.gitlab.com
Tue Dec 4 05:00:08 UTC 2018
Matt Selsky pushed to branch master at NTPsec / ntpsec
Commits:
67b84776 by James Browning at 2018-12-04T04:22:55Z
BASHisms
- - - - -
9159d724 by James Browning at 2018-12-04T04:24:25Z
Fix Stenn version
- - - - -
54dcb760 by James Browning at 2018-12-04T04:25:48Z
white spacing
- - - - -
1 changed file:
- ntpclients/ntpleapfetch
Changes:
=====================================
ntpclients/ntpleapfetch
=====================================
@@ -7,8 +7,6 @@
#
# Bugfixes and improvements would be appreciated by the author.
-VERSION="1.003"
-
# leap-seconds file manager/updater
# Depends on:
@@ -49,7 +47,7 @@ REQUIREDCMDS=" wget logger tr sed"
SELF="`basename $0`"
-function displayHelp {
+displayHelp() {
cat <<EOF
Usage: $SELF [options] [leapfile]
@@ -111,12 +109,12 @@ For cron-friendly behavior, define CRONJOB=1 in the crontab.
This script depends on: sha1sum/shasum $REQUIREDCMDS
-Version $VERSION
+Version @NTPSEC_VERSION_EXTENDED@
EOF
return 0
}
-function displayVersion {
+displayVersion() {
cat <<EOF
ntpleapfetch ntpsec- at NTPSEC_VERSION_EXTENDED@
EOF
@@ -155,18 +153,18 @@ while getopts 46p:P:s:e:f:Fc:r:i:lLt:hqvz:ZV opt; do
exit 1;
fi
;;
- P)
- LOGFAC="$OPTARG"
- ;;
+ P)
+ LOGFAC="$OPTARG"
+ ;;
s)
LEAPSRC="$OPTARG"
;;
e)
PREFETCH="$OPTARG"
;;
- f)
- NTPCONF="$OPTARG"
- ;;
+ f)
+ NTPCONF="$OPTARG"
+ ;;
F)
FORCE="Y"
;;
@@ -182,32 +180,32 @@ while getopts 46p:P:s:e:f:Fc:r:i:lLt:hqvz:ZV opt; do
t)
TMPFILE="$OPTARG"
;;
- l)
- SYSLOG="y"
- ;;
- L)
- SYSLOG=
- ;;
+ l)
+ SYSLOG="y"
+ ;;
+ L)
+ SYSLOG=
+ ;;
h)
displayHelp
exit 0
;;
- V)
- displayVersion
- exit 0
- ;;
- q)
- QUIET="Y"
- ;;
+ V)
+ displayVersion
+ exit 0
+ ;;
+ q)
+ QUIET="Y"
+ ;;
v)
VERBOSE="Y"
;;
- z)
- PATHLIST="$OPTARG:"
- ;;
- Z)
- PATHLIST=
- ;;
+ z)
+ PATHLIST="$OPTARG:"
+ ;;
+ Z)
+ PATHLIST=
+ ;;
*)
echo "$SELF -h for usage" >&2
exit 1
@@ -222,7 +220,7 @@ export PATH="$PATHLIST$PATH"
#
for P in $REQUIREDCMDS ; do
if >/dev/null 2>&1 which "$P" ; then
- continue
+ continue
fi
[ "$P" = "logger" ] && continue
echo "FATAL: missing $P command, please install"
@@ -245,23 +243,23 @@ if ! LOGGER="`2>/dev/null which logger`" ; then
LOGGER=
fi
-function log {
+log() {
# "priority" "message"
#
# Stdout unless syslog specified or logger isn't available
#
if [ -z "$SYSLOG" -o -z "$LOGGER" ]; then
- if [ -n "$QUIET" -a \( "$1" = "info" -o "$1" = "notice" -o "$1" = "debug" \) ]; then
- return 0
- fi
- echo "`echo \"$1\" | tr a-z A-Z`: $2"
- return 0
+ if [ -n "$QUIET" -a \( "$1" = "info" -o "$1" = "notice" -o "$1" = "debug" \) ]; then
+ return 0
+ fi
+ echo "`echo \"$1\" | tr a-z A-Z`: $2"
+ return 0
fi
# Also log to stdout if cron job && notice or higher
local S
if [ -n "$CRONJOB" -a \( "$1" != "info" \) -a \( "$1" != "debug" \) ] || [ -n "$VERBOSE" ]; then
- S="-s"
+ S="-s"
fi
$LOGGER $S -t "$SELF[$$]" -p "$LOGFAC.$1" "$2"
}
@@ -279,7 +277,7 @@ INTERVAL=$(( $INTERVAL *1 ))
# Date lines have comments.
# #h hex hex hex hex hex is the SHA1 checksum of the data & dates, excluding whitespace w/o leading zeroes
-function verifySHA1 {
+verifySHA1() {
if [ ! -f "$1" ]; then
return 1
@@ -318,7 +316,7 @@ function verifySHA1 {
fi
else
log "error" "Checksum of $1 is invalid:"
- [ -z "$FSHA1" ] && FSHA1="(no checksum record found in file)"
+ [ -z "$FSHA1" ] && FSHA1="(no checksum record found in file)"
log "error" "EXPECTED: $FSHA1"
log "error" "COMPUTED: $DSHA1"
return 1
@@ -382,8 +380,8 @@ if [ -n "$FORCE" ] || ! verifySHA1 $LEAPFILE "$VERBOSE" || [ $EXPIRES -lt `date
fi
if ! verifySHA1 $TMPFILE "$VERBOSE" ; then
- # There is no point in retrying, as the file on the server is almost
- # certainly corrupt.
+ # There is no point in retrying, as the file on the server is almost
+ # certainly corrupt.
log "warning" "Downloaded file $TMPFILE rejected -- saved for diagnosis"
cat ${TMPFILE}.log
@@ -392,24 +390,24 @@ if [ -n "$FORCE" ] || ! verifySHA1 $LEAPFILE "$VERBOSE" || [ $EXPIRES -lt `date
fi
rm -f ${TMPFILE}.log
- # Set correct permissions on temporary file
+ # Set correct permissions on temporary file
- REFFILE="$LEAPFILE"
+ REFFILE="$LEAPFILE"
if [ ! -f $LEAPFILE ]; then
- log "notice" "$LEAPFILE was missing, creating new copy - check permissions"
+ log "notice" "$LEAPFILE was missing, creating new copy - check permissions"
touch $LEAPFILE
- # Can't copy permissions from old file,
+ # Can't copy permissions from old file,
# copy from NTPCONF instead
- REFFILE="$NTPCONF"
+ REFFILE="$NTPCONF"
fi
chmod --reference=$REFFILE $TMPFILE
chown --reference=$REFFILE $TMPFILE
- ( which selinuxenabled && selinuxenabled && which chcon ) >/dev/null 2>&1
- if [ $? == 0 ] ; then
+ ( which selinuxenabled && selinuxenabled && which chcon ) >/dev/null 2>&1
+ if [ $? -eq 0 ] ; then
chcon --reference $REFFILE $TMPFILE
fi
- # Replace current file with validated new one
+ # Replace current file with validated new one
if mv -f $TMPFILE $LEAPFILE ; then
log "notice" "Installed new $LEAPFILE from $LEAPSRC"
@@ -418,30 +416,30 @@ if [ -n "$FORCE" ] || ! verifySHA1 $LEAPFILE "$VERBOSE" || [ $EXPIRES -lt `date
exit 1
fi
- # Restart NTP (or whatever else is specified)
-
- if [ -n "$RESTART" ]; then
- if [ -n "$VERBOSE" ]; then
- log "info" "Attempting restart action: $RESTART"
- fi
- R="$( 2>&1 $RESTART )"
- if [ $? -eq 0 ]; then
- log "notice" "Restart action succeeded"
- if [ -n "$VERBOSE" -a -n "$R" ]; then
- log "info" "$R"
- fi
- else
- log "error" "Restart action failed"
- if [ -n "$R" ]; then
- log "error" "$R"
- fi
- exit 2
- fi
- fi
+ # Restart NTP (or whatever else is specified)
+
+ if [ -n "$RESTART" ]; then
+ if [ -n "$VERBOSE" ]; then
+ log "info" "Attempting restart action: $RESTART"
+ fi
+ R="$( 2>&1 $RESTART )"
+ if [ $? -eq 0 ]; then
+ log "notice" "Restart action succeeded"
+ if [ -n "$VERBOSE" -a -n "$R" ]; then
+ log "info" "$R"
+ fi
+ else
+ log "error" "Restart action failed"
+ if [ -n "$R" ]; then
+ log "error" "$R"
+ fi
+ exit 2
+ fi
+ fi
exit 0
- fi
+ fi
- # Failed to download. See about trying again
+ # Failed to download. See about trying again
rm -f $TMPFILE
if [ $TRY -ge $MAXTRIES ]; then
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/57f94dacb506d89563dc984f420047d8af1f11cf...54dcb7604c8fb364bd8f5dcf57513b6b9f4b6a2a
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/57f94dacb506d89563dc984f420047d8af1f11cf...54dcb7604c8fb364bd8f5dcf57513b6b9f4b6a2a
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/20181204/c97a623d/attachment-0001.html>
More information about the vc
mailing list