@@ -1,8 +1,9 @@
[userv-utils] / dyndns / update
CommitLineData
3988a733 1#!/bin/bash
2set -e
3
4zone="$1"
5subdomain="$2"
6interval_min="$3"
7interval_avg="$4"
8interval_mem="$5"
9
10now=`date +%s`
11charge=0
12
13case $subdomain in
14'@') files=_ ;;
15*) files=$subdomain ;;
16esac
17
18if test -f $files,timings && read lastup charge <$files,timings
19then
20 if [ $now -lt $[ $lastup + $interval_min ] ]; then
21 echo "wait $[ $lastup + $interval_min - $now ]"
22 echo >&2 "must wait at least $interval_min between updates"
23 exit 75
24 fi
25 charge=$[ $charge + $interval_avg - ($now - $lastup) ]
26 if [ $charge -gt $interval_mem ]; then
27 echo "wait $[ $charge - $interval_mem ]"
28 echo >&2 "must wait on average $interval_avg between updates"
29 exit 75
30 fi
31 if [ $charge -lt 0 ]; then charge=0; fi
32fi
33
34sort >$files,new
35
36if test -f $files,data
37then
38 set +e
39 diff >/dev/null $files,data $files,new
40 diff=$?
41 set -e
42
43 if [ $diff = 0 ]; then echo 'unchanged'; exit 0; fi
44 if [ $diff != 1 ]; then exit 1; fi
45fi
46
47echo $now $charge >$files,timings.new
48mv -f $files,timings.new $files,timings
49mv $files,new $files,data
50
51exec /usr/local/lib/userv/dyndns/install $zone