ud-mailgate: remove exception for münchen.debian.net
[mirror/userdir-ldap.git] / ud-replicate
1 #! /bin/bash
2
3 #   Copyright (c) 1999-2001  Jason Gunthorpe <jgg@debian.org>
4 #   Copyright (c) 2002-2003,2006  Ryan Murray <rmurray@debian.org>
5 #   Copyright (c) 2004-2005  Joey Schulze <joey@infodrom.org>
6 #   Copyright (c) 2008,2011 Peter Palfrader <peter@palfrader.org>
7 #   Copyright (c) 2008 Stephen Gran <sgran@debian.org>
8 #
9 #   This program is free software; you can redistribute it and/or modify
10 #   it under the terms of the GNU General Public License as published by
11 #   the Free Software Foundation; either version 2 of the License, or
12 #   (at your option) any later version.
13 #
14 #   This program is distributed in the hope that it will be useful,
15 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #   GNU General Public License for more details.
18 #
19 #   You should have received a copy of the GNU General Public License
20 #   along with this program; if not, write to the Free Software
21 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 set -e
24
25 # Without effect on the commandline
26 if [ -z "$TERM" -o "$TERM" = "dumb" ]
27 then
28     exec > /dev/null 2>&1
29     sleep $(( $RANDOM % 120 ))
30 else
31     verbose=-v
32 fi
33
34 tempdir=''
35 tempfile=''
36 tempfile2=''
37
38 cleanup ()
39 {
40   rm -rf $tempdir
41   rm -f  $tempfile
42   rm -f  $tempfile2
43 }
44
45 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
46 export PATH
47 HOST=`hostname -f`
48 SYNCHOST=`ud-config synchost`;
49 LOCALSYNCON=`ud-config localsyncon`;
50 EMAILAPPEND=`ud-config emailappend`;
51 cd /var/lib/misc
52 exec 200< "."
53 if ! flock -w 60 -e 200; then
54     log "Cannot acquire lock on `pwd`"
55     exit 1
56 fi
57
58 trap cleanup exit
59
60 case $HOST in
61 $LOCALSYNCON)
62     udhost=
63     ;;
64 *)
65     udhost="sshdist@$SYNCHOST:"
66     ;;
67 esac
68
69 tempfile=$(mktemp)
70 tempfile2=$(mktemp)
71
72 if [ -e /var/lib/misc/thishost/dns-sshfp ]; then
73   cp /var/lib/misc/thishost/dns-sshfp $tempfile
74 fi
75
76 if [ -e /var/lib/misc/thishost/dns-zone ]; then
77   cp /var/lib/misc/thishost/dns-zone $tempfile2
78 fi
79
80 rsync ${verbose} --delete-after --times -e 'ssh -i /etc/ssh/ssh_host_rsa_key -o ControlPath=/var/run/.ud-replicate.ssh.socket -o ControlMaster=auto -o ControlPersist=2h -o BatchMode=yes' -rp "${udhost}/var/cache/userdir-ldap/hosts/$HOST" .
81
82 rm -f __db.passwd.db.t
83 makedb "$HOST/passwd.tdb" -o passwd.db.t
84 if [ -s "$HOST/shadow.tdb" ]
85 then
86     rm -f __db.shadow.db.t
87     (umask 027 && makedb "$HOST/shadow.tdb" -o shadow.db.t)
88     chown root.shadow shadow.db.t
89     chmod 0640 shadow.db.t
90     mv -f shadow.db.t shadow.db
91 fi
92 rm -f __db.group.db.t
93 makedb "$HOST/group.tdb" -o group.db.t
94 mv -f passwd.db.t passwd.db
95 mv -f group.db.t group.db
96 if [ -e "$HOST/ssh-rsa-shadow" ]; then
97         ln -sf $HOST/ssh-rsa-shadow .
98         ln -sf `pwd -P`/ssh-rsa-shadow /etc/ssh
99 else
100         rm -f ssh-rsa-shadow /etc/ssh/ssh-rsa-shadow
101 fi
102 ln -sf $HOST/ssh_known_hosts .
103 ln -sf `pwd -P`/ssh_known_hosts /etc/ssh
104
105 if [ -e ${HOST}/ssh-keys.tar.gz ]; then
106   export TMPDIR='/tmp/'
107   tempdir=$(mktemp -d)
108   tar -C "$tempdir" -xf ${HOST}/ssh-keys.tar.gz
109   mkdir -p userkeys
110   chmod 755 $tempdir
111   rsync -a --delete-after $tempdir/ userkeys/
112 fi
113
114 if [ -e ${HOST}/web-passwords ]; then
115         chown root:www-data ${HOST}/web-passwords
116         chmod 0640 ${HOST}/web-passwords
117 fi
118
119 if [ -d "/etc/exim4" -a -e "$HOST/bsmtp" ]; then
120         if perl -e 'exit !((stat "/etc/exim4/bsmtp")[9] < time()-3600)'; then
121                 cp "$HOST/bsmtp" /etc/exim4/bsmtp
122         fi
123 fi
124 if [ -d "/etc/postfix" -a -f "$HOST/forward-alias" ]; then
125         sed -e "s/:/@$EMAILAPPEND/" $HOST/forward-alias > /etc/postfix/debian
126         /usr/sbin/postmap hash:/etc/postfix/debian < /etc/postfix/debian || true
127 fi
128
129 rebuild_zones=0
130 if [ -e /var/lib/misc/thishost/dns-sshfp ]; then
131   if ! cmp -s /var/lib/misc/thishost/dns-sshfp "$tempfile"; then
132     rebuild_zones=1
133   fi
134 fi
135
136 if [ -e /var/lib/misc/thishost/dns-zone ]; then
137   if ! cmp -s /var/lib/misc/thishost/dns-zone "$tempfile2"; then
138     rebuild_zones=1
139   fi
140 fi
141
142 if [ "${rebuild_zones}" -gt 0 ]; then
143   sudo -u dnsadm /srv/dns.debian.org/bin/update
144 fi
145
146 if [ -d "/etc/freeradius" -a -e "$HOST/rtc-passwords" ]; then
147         if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.freerad; then
148                 install -o freerad -g freerad -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.freerad
149                 service freeradius reload
150         fi
151 fi
152 if [ -d "/etc/reTurn" -a -e "$HOST/rtc-passwords" ]; then
153         if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.return; then
154                 install -o return -g return -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.return
155                 service resiprocate-turn-server reload
156         fi
157 fi
158 if [ -d "/etc/prosody" -a -e "$HOST/rtc-passwords" ]; then
159         if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.prosody; then
160                 install -o prosody -g prosody -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.prosody
161                 service prosody reload
162         fi
163 fi