ud-replicate: remove chroot support
[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 -f lock
41   rm -rf $tempdir
42   rm -f  $tempfile
43   rm -f  $tempfile2
44 }
45
46 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
47 export PATH
48 HOST=`hostname -f`
49 SYNCHOST=`ud-config synchost`;
50 LOCALSYNCON=`ud-config localsyncon`;
51 EMAILAPPEND=`ud-config emailappend`;
52 cd /tmp/
53 cd /var/lib/misc || cd /var/state/glibc/ || cd /var/db/
54 lockfile -r 1 -l 3600 lock
55 trap cleanup exit
56
57 case $HOST in
58 $LOCALSYNCON)
59     udhost=
60     ;;
61 *)
62     udhost="sshdist@$SYNCHOST:"
63     ;;
64 esac
65
66 tempfile=$(mktemp)
67 tempfile2=$(mktemp)
68
69 if [ -e /var/lib/misc/thishost/dns-sshfp ]; then
70   cp /var/lib/misc/thishost/dns-sshfp $tempfile
71 fi
72
73 if [ -e /var/lib/misc/thishost/dns-zone ]; then
74   cp /var/lib/misc/thishost/dns-zone $tempfile2
75 fi
76
77 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" .
78
79 makedb "$HOST/passwd.tdb" -o passwd.db.t
80 if [ -s "$HOST/shadow.tdb" ]
81 then
82     (umask 027 && makedb "$HOST/shadow.tdb" -o shadow.db.t)
83     chown root.shadow shadow.db.t
84     chmod 0640 shadow.db.t
85     mv -f shadow.db.t shadow.db
86 fi
87 makedb "$HOST/group.tdb" -o group.db.t
88 mv -f passwd.db.t passwd.db
89 mv -f group.db.t group.db
90 if [ -e "$HOST/ssh-rsa-shadow" ]; then
91         ln -sf $HOST/ssh-rsa-shadow .
92         ln -sf `pwd -P`/ssh-rsa-shadow /etc/ssh
93 else
94         rm -f ssh-rsa-shadow /etc/ssh/ssh-rsa-shadow
95 fi
96 ln -sf $HOST/ssh_known_hosts .
97 ln -sf `pwd -P`/ssh_known_hosts /etc/ssh
98
99 if [ -e ${HOST}/ssh-keys.tar.gz ]; then
100   export TMPDIR='/tmp/'
101   tempdir=$(mktemp -d)
102   tar -C "$tempdir" -xf ${HOST}/ssh-keys.tar.gz
103   mkdir -p userkeys
104   chmod 755 $tempdir
105   rsync -a --delete-after $tempdir/ userkeys/
106 fi
107
108 if [ -e ${HOST}/web-passwords ]; then
109         chown root:www-data ${HOST}/web-passwords
110         chmod 0640 ${HOST}/web-passwords
111 fi
112
113 if [ -d "/etc/exim4" -a -e "$HOST/bsmtp" ]; then
114         if perl -e 'exit !((stat "/etc/exim4/bsmtp")[9] < time()-3600)'; then
115                 cp "$HOST/bsmtp" /etc/exim4/bsmtp
116         fi
117 fi
118 if [ -d "/etc/postfix" -a -f "$HOST/forward-alias" ]; then
119         sed -e "s/:/@$EMAILAPPEND/" $HOST/forward-alias > /etc/postfix/debian
120         /usr/sbin/postmap hash:/etc/postfix/debian < /etc/postfix/debian || true
121 fi
122
123 rebuild_zones=0
124 if [ -e /var/lib/misc/thishost/dns-sshfp ]; then
125   if ! cmp -s /var/lib/misc/thishost/dns-sshfp "$tempfile"; then
126     rebuild_zones=1
127   fi
128 fi
129
130 if [ -e /var/lib/misc/thishost/dns-zone ]; then
131   if ! cmp -s /var/lib/misc/thishost/dns-zone "$tempfile2"; then
132     rebuild_zones=1
133   fi
134 fi
135
136 if [ "${rebuild_zones}" -gt 0 ]; then
137   sudo -u dnsadm /srv/dns.debian.org/bin/update
138 fi
139
140 if [ -d "/etc/freeradius" -a -e "$HOST/rtc-passwords" ]; then
141         if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.freerad; then
142                 install -o freerad -g freerad -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.freerad
143                 service freeradius reload
144         fi
145 fi
146 if [ -d "/etc/reTurn" -a -e "$HOST/rtc-passwords" ]; then
147         if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.return; then
148                 install -o return -g return -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.return
149                 service resiprocate-turn-server reload
150         fi
151 fi
152 if [ -d "/etc/prosody" -a -e "$HOST/rtc-passwords" ]; then
153         if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.prosody; then
154                 install -o prosody -g prosody -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.prosody
155                 service prosody reload
156         fi
157 fi