ipif: "include" looks for the file in the directory where "include" appears
[userv-utils] / dyndns / update
CommitLineData
3988a733 1#!/bin/bash
711a0748 2
9028e234
IJ
3# Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
4# Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
5# Copyright 1999,2003
6# Chancellor Masters and Scholars of the University of Cambridge
7# Copyright 2010 Tony Finch <fanf@dotat.at>
711a0748 8#
9# This is free software; you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by
9028e234 11# the Free Software Foundation; either version 3 of the License, or
711a0748 12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
9028e234 20# along with userv-utils; if not, see http://www.gnu.org/licenses/.
711a0748 21
3988a733 22set -e
23
24zone="$1"
25subdomain="$2"
26interval_min="$3"
27interval_avg="$4"
28interval_mem="$5"
29
30now=`date +%s`
31charge=0
32
33case $subdomain in
34'@') files=_ ;;
35*) files=$subdomain ;;
36esac
37
38if test -f $files,timings && read lastup charge <$files,timings
39then
40 if [ $now -lt $[ $lastup + $interval_min ] ]; then
41 echo "wait $[ $lastup + $interval_min - $now ]"
42 echo >&2 "must wait at least $interval_min between updates"
43 exit 75
44 fi
45 charge=$[ $charge + $interval_avg - ($now - $lastup) ]
46 if [ $charge -gt $interval_mem ]; then
47 echo "wait $[ $charge - $interval_mem ]"
48 echo >&2 "must wait on average $interval_avg between updates"
49 exit 75
50 fi
51 if [ $charge -lt 0 ]; then charge=0; fi
52fi
53
54sort >$files,new
55
56if test -f $files,data
57then
58 set +e
59 diff >/dev/null $files,data $files,new
60 diff=$?
61 set -e
62
63 if [ $diff = 0 ]; then echo 'unchanged'; exit 0; fi
64 if [ $diff != 1 ]; then exit 1; fi
65fi
66
67echo $now $charge >$files,timings.new
68mv -f $files,timings.new $files,timings
69mv $files,new $files,data
70
6362f12c 71exec /usr/share/userv/dyndns/install $zone