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>
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.
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.
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.
25 # Without effect on the commandline
26 if [ -z "$TERM" -o "$TERM" = "dumb" ]
29 sleep $(( $RANDOM % 120 ))
46 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
49 SYNCHOST=`ud-config synchost`;
50 LOCALSYNCON=`ud-config localsyncon`;
51 EMAILAPPEND=`ud-config emailappend`;
53 cd /var/lib/misc || cd /var/state/glibc/ || cd /var/db/
54 lockfile -r 1 -l 3600 lock
62 udhost="sshdist@$SYNCHOST:"
69 if [ -e /var/lib/misc/thishost/dns-sshfp ]; then
70 cp /var/lib/misc/thishost/dns-sshfp $tempfile
73 if [ -e /var/lib/misc/thishost/dns-zone ]; then
74 cp /var/lib/misc/thishost/dns-zone $tempfile2
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" .
79 makedb "$HOST/passwd.tdb" -o passwd.db.t
80 if [ -s "$HOST/shadow.tdb" ]
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
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
94 rm -f ssh-rsa-shadow /etc/ssh/ssh-rsa-shadow
96 ln -sf $HOST/ssh_known_hosts .
97 ln -sf `pwd -P`/ssh_known_hosts /etc/ssh
99 if [ -e ${HOST}/ssh-keys.tar.gz ]; then
100 export TMPDIR='/tmp/'
102 tar -C "$tempdir" -xf ${HOST}/ssh-keys.tar.gz
105 rsync -a --delete-after $tempdir/ userkeys/
108 if [ -e ${HOST}/web-passwords ]; then
109 chown root:www-data ${HOST}/web-passwords
110 chmod 0640 ${HOST}/web-passwords
114 if [ -x /usr/bin/dchroot ]; then
115 CHROOTS=`dchroot --listpaths`
116 elif [ -x /usr/bin/dchroot-dsa ]; then
117 CHROOTS=$(dchroot-dsa -i | grep Location | awk '{print $2}')
119 if [ -n "$CHROOTS" ]; then
120 for c in $CHROOTS; do
121 if [ "$c" = "/" ] || [ "$c" = "" ]; then
122 echo "$0 WTF: \$c is '' or '/' here." 2>&1
125 if [ -x "$c/usr/bin/makedb" ]
127 mkdir -p "$c/var/lib/misc/$HOST"
129 # remove extra stuff from earlier times and so
130 find "$c/var/lib/misc/$HOST" -mindepth 1 \
131 ! -name group.tdb -a \
132 ! -name passwd.tdb -a \
133 ! -name ssh_known_hosts \
134 -print0 | xargs --no-run-if-empty -0 rm -f
135 rsync -a ${verbose} $HOST/group.tdb $HOST/passwd.tdb $HOST/ssh_known_hosts "$c/var/lib/misc/$HOST"
137 # clean up from the times we supposedly did shadow stuff in chroots
138 rm -f "$c/var/lib/misc/shadow.db"
140 # from failed makedb runs earlier.
141 rm -f "$c/var/lib/misc/passwd.db.t" \
142 "$c/var/lib/misc/group.db.t"
143 # build passwd information
144 chroot "$c" makedb "/var/lib/misc/$HOST/passwd.tdb" -o /var/lib/misc/passwd.db.t
145 chroot "$c" makedb "/var/lib/misc/$HOST/group.tdb" -o /var/lib/misc/group.db.t
146 mv -f "$c/var/lib/misc/passwd.db.t" "$c/var/lib/misc/passwd.db"
147 mv -f "$c/var/lib/misc/group.db.t" "$c/var/lib/misc/group.db"
149 ln -sf "$HOST/ssh_known_hosts" "$c/var/lib/misc/"
150 if [ -d "$c/etc/ssh" ]; then
151 ln -sf ../../var/lib/misc/ssh_known_hosts "$c/etc/ssh"
152 elif [ -L "$c/etc/ssh" ] && [ "`readlink \"$c/etc/ssh\"`" = "../../var/lib/misc/ssh_known_hosts" ]; then
153 # clean up past mistakes
160 if [ -d "/etc/exim4" -a -e "$HOST/bsmtp" ]; then
161 if perl -e 'exit !((stat "/etc/exim4/bsmtp")[9] < time()-3600)'; then
162 cp "$HOST/bsmtp" /etc/exim4/bsmtp
165 if [ -d "/etc/postfix" -a -f "$HOST/forward-alias" ]; then
166 sed -e "s/:/@$EMAILAPPEND/" $HOST/forward-alias > /etc/postfix/debian
167 /usr/sbin/postmap hash:/etc/postfix/debian < /etc/postfix/debian || true
171 if [ -e /var/lib/misc/thishost/dns-sshfp ]; then
172 if ! cmp -s /var/lib/misc/thishost/dns-sshfp "$tempfile"; then
177 if [ -e /var/lib/misc/thishost/dns-zone ]; then
178 if ! cmp -s /var/lib/misc/thishost/dns-zone "$tempfile2"; then
183 if [ "${rebuild_zones}" -gt 0 ]; then
184 sudo -u dnsadm /srv/dns.debian.org/bin/update
187 if [ -d "/etc/freeradius" -a -e "$HOST/rtc-passwords" ]; then
188 if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.freerad; then
189 install -o freerad -g freerad -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.freerad
190 service freeradius reload
193 if [ -d "/etc/reTurn" -a -e "$HOST/rtc-passwords" ]; then
194 if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.return; then
195 install -o return -g return -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.return
196 service resiprocate-turn-server reload
199 if [ -d "/etc/prosody" -a -e "$HOST/rtc-passwords" ]; then
200 if ! cmp -s "$HOST/rtc-passwords" /var/local/rtc-passwords.prosody; then
201 install -o prosody -g prosody -m 400 "$HOST/rtc-passwords" /var/local/rtc-passwords.prosody
202 service prosody reload