Import from samosa: Various changes from James
[mirror/userdir-ldap.git] / ud-replicate
1 #! /bin/sh
2 # The rsync source host needs to be customized..
3 set -e
4
5 # Without effect on the commandline
6 if [ -z "$PS1" -o "$TERM" ]
7 then
8     exec > /dev/null 2>&1
9     verbose=-v
10 fi
11
12 HOST=`hostname -f`
13 cd /tmp/
14 cd /var/lib/misc || cd /var/state/glibc/ || cd /var/db/
15 lockfile -r 1 -l 3600 lock
16 trap "rm -f lock" exit
17 case $HOST in
18 *samosa*)
19     udhost=;;
20 *)
21     udhost="sshdist@samosa:";;
22 esac
23 rsync ${verbose} -e ssh -rp "${udhost}/var/cache/userdir-ldap/hosts/$HOST" .
24 makedb "$HOST/passwd.tdb" -o passwd.db.t
25 (umask 027 && makedb "$HOST/shadow.tdb" -o shadow.db.t)
26 chown root.shadow shadow.db.t; chmod 0640 shadow.db.t
27 makedb "$HOST/group.tdb" -o group.db.t
28 mv -f passwd.db.t passwd.db
29 mv -f shadow.db.t shadow.db
30 mv -f group.db.t group.db
31 #if [ -x /usr/bin/dchroot ]; then
32 #       CHROOTS=`dchroot --listpaths`
33 #       for c in $CHROOTS; do
34 #               if [ -e "$c/var/lib/misc/$HOST" ]; then
35 #                       chroot "$c" makedb "/var/lib/misc/$HOST/passwd.tdb" -o /var/lib/misc/passwd.db.t
36 #                       (umask 027 && chroot "$c" makedb "/var/lib/misc/$HOST/shadow.tdb" -o /var/lib/misc/shadow.db.t)
37 #                       chown root.shadow "$c/var/lib/misc/shadow.db.t"
38 #                       chmod 0640 "$c/var/lib/misc/shadow.db.t"
39 #                       chroot "$c" makedb "/var/lib/misc/$HOST/group.tdb" -o /var/lib/misc/group.db.t
40 #                       mv -f "$c/var/lib/misc/passwd.db.t" "$c/var/lib/misc/passwd.db"
41 #                       mv -f "$c/var/lib/misc/shadow.db.t" "$c/var/lib/misc/shadow.db"
42 #                       mv -f "$c/var/lib/misc/group.db.t" "$c/var/lib/misc/group.db"
43 #               fi
44 #       done
45 #fi
46 ln -sf "$HOST/ssh-rsa-shadow" .
47 ln -sf "$HOST/ssh_known_hosts" .
48 if [ -d "/etc/exim" -a -e "$HOST/bsmtp" ]; then
49         if perl -e 'exit !((stat "/etc/exim/bsmtp")[9] < time()-3600)'; then
50                 cp "$HOST/bsmtp" /etc/exim/bsmtp
51         fi
52 fi
53 if [ -d "/etc/postfix" -a -f "$HOST/forward-alias" ]; then
54         sed -e 's/:/@debian.org/' $HOST/forward-alias > /etc/postfix/debian
55         /usr/sbin/postmap hash:/etc/postfix/debian < /etc/postfix/debian || true
56 fi