Portable, perl-less way of enforcing minimum update interval (blame^W thanks to Tony Finch :-) )
1 files changed, 16 insertions(+), 21 deletions(-)

M fetch-sanesecurity-sigs
M fetch-sanesecurity-sigs +16 -21
@@ 76,10 76,11 @@ mirror="rsync://rsync.sanesecurity.net/s
 # enable compression.
 rsync_extra_opts="--contimeout=30"
 
-# Minimum interval between updates, in minutes
-# (Note that the download servers may be configured to drop connections made
-# at too great a rate)
-min_interval="30"
+# Enforce a minimum of 30 minutes between updates?
+# (Please leave this enabled in order to avoid overloading the download
+# servers.  Note that the servers may be configured to drop connections made
+# at too great a rate.)
+enforce_min_interval=1
 
 # Randomly sleep before downloading if running noninteractively?
 # (Please leave this enabled, as it reduces peak load on the mirrors)

          
@@ 123,7 124,7 @@ then
 	echo "(This should only occur once)" >&2
 	mkdir -p "$gpg_homedir"
 	chmod 0700 "$gpg_homedir"
-	gpg_tmp="$(mktemp -t fetch-sanesecurity-sigs.XXXXXXXXXX)"
+	gpg_tmp="$(mktemp -t fetch-sanesecurity-sigs.pubkey.XXXXXXXXXX)"
 	if ! wget -O "$gpg_tmp" "$gpg_key_url"
 	then
 		echo "ERROR: could not fetch GnuPG public key; aborting" >&2

          
@@ 139,25 140,16 @@ then
 	rm -f "$gpg_tmp"
 fi
 
-# This appears to be the most portable way to find the current timestamp
-# (suggestions on how to avoid calling perl are very welcome)
-time_now="$(perl -le print+time)"
-if [ ! "$time_now" -gt 1 ]
+stamp_prev="$data_dir/update-stamp"
+if [ "$enforce_min_interval" = "1" -a -f "$data_dir/update-stamp" ]
 then
-	echo "Could not find current timestamp -- is perl installed?" >&2
-	exit 5
-fi
-
-# Check that min_interval seconds have elapsed since last run
-if [ -s "$data_dir/update-stamp" ]
-then
-	time_then="$(cat "$data_dir/update-stamp")"
-	minutes_elapsed=$(( (time_now - time_then) / 60 ))
-	if [ "$minutes_elapsed" -lt "$min_interval" ]
+	stamp_current="$(mktemp -t fetch-sanesecurity-sigs.stamp.XXXXXXXXXX)"
+	if [ "$stamp_prev" -nt "$stamp_current" ]
 	then
-		echo "Must wait at least $min_interval between updates; aborting" >&2
+		echo "Must wait at least 30 minutes between updates; aborting" >&2
 		exit 2
 	fi
+	rm -f "$stamp_current"
 fi
 
 # Random sleep (see comment in configuration section)

          
@@ 185,10 177,13 @@ then
 	echo "rsync failed; aborting." >&2
 	exit 3
 fi
-echo "$time_now" > "$data_dir/update-stamp"
 chmod 0644 "$cache_dir"/*
 echo
 
+# Minimum interval enforcement:
+# create a file with a timestamp 30 minutes in the future
+touch -t $(printf "$(date +%Y%m%d%H)%02d" $(( 1$(date +%M) - 70)) ) "$stamp_prev"
+
 # Iterate through the databases in the cache
 installed=0
 for db in "$cache_dir"/*.?db "$cache_dir"/*.ftm