# HG changeset patch # User mas90 # Date 1233772678 0 # Wed Feb 04 18:37:58 2009 +0000 # Node ID 4f4fb6d9e33b309a340c8e492504093ea9e70ca5 # Parent 8475fffdb7b8fd36acab2b834ade760f95bcaa7c Revert [366] as it doesn't work when an hour would wrap diff --git a/fetch-sanesecurity-sigs b/fetch-sanesecurity-sigs --- a/fetch-sanesecurity-sigs +++ b/fetch-sanesecurity-sigs @@ -76,11 +76,10 @@ # enable compression. rsync_extra_opts="--contimeout=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 +# 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" # Randomly sleep before downloading if running noninteractively? # (Please leave this enabled, as it reduces peak load on the mirrors) @@ -124,7 +123,7 @@ echo "(This should only occur once)" >&2 mkdir -p "$gpg_homedir" chmod 0700 "$gpg_homedir" - gpg_tmp="$(mktemp -t fetch-sanesecurity-sigs.pubkey.XXXXXXXXXX)" + gpg_tmp="$(mktemp -t fetch-sanesecurity-sigs.XXXXXXXXXX)" if ! wget -O "$gpg_tmp" "$gpg_key_url" then echo "ERROR: could not fetch GnuPG public key; aborting" >&2 @@ -140,16 +139,25 @@ rm -f "$gpg_tmp" fi -stamp_prev="$data_dir/update-stamp" -if [ "$enforce_min_interval" = "1" -a -f "$data_dir/update-stamp" ] +# 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 ] then - stamp_current="$(mktemp -t fetch-sanesecurity-sigs.stamp.XXXXXXXXXX)" - if [ "$stamp_prev" -nt "$stamp_current" ] + 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" ] then - echo "Must wait at least 30 minutes between updates; aborting" >&2 + echo "Must wait at least $min_interval minutes between updates; aborting" >&2 exit 2 fi - rm -f "$stamp_current" fi # Random sleep (see comment in configuration section) @@ -177,13 +185,10 @@ 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