Initial import
[samba] / debian / samba.postinst
1 #!/bin/sh -e
2 #
3 # Post-installation script for the Samba package for Debian GNU/Linux
4 #
5 #
6
7 case "$1" in
8         configure)
9                 # continue below
10         ;;
11
12         abort-upgrade|abort-remove|abort-deconfigure)
13                 exit 0
14         ;;
15
16         *)
17                 echo "postinst called with unknown argument \`$1'" >&2
18                 exit 0
19         ;;
20 esac
21
22 # Handle debconf
23 . /usr/share/debconf/confmodule
24
25 INITCONFFILE=/etc/default/samba
26
27 # We generate several files during the postinst, and we don't want
28 #       them to be readable only by root.
29 umask 022
30
31
32 # Generate configuration file if it does not exist, using default values.
33 [ -r "${INITCONFFILE}" ] || {
34         echo Generating ${INITCONFFILE}... >&2
35         cat >${INITCONFFILE} <<'EOFMAGICNUMBER1234'
36 # Defaults for samba initscript
37 # sourced by /etc/init.d/samba
38 # installed at /etc/default/samba by the maintainer scripts
39 #
40
41 #
42 # This is a POSIX shell fragment
43 #
44
45 # How should Samba (smbd) run? Possible values are "daemons"
46 #       or "inetd".
47 RUN_MODE=""
48 EOFMAGICNUMBER1234
49 }
50
51 # ------------------------- Debconf questions start ---------------------
52
53 # Run Samba as daemons or from inetd?
54 db_get samba/run_mode || true
55 RUN_MODE="${RET}"
56
57 TMPFILE=/etc/default/samba.dpkg-tmp
58 sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
59         < ${INITCONFFILE} >${TMPFILE}
60 chmod a+r ${TMPFILE}
61 mv -f ${TMPFILE} ${INITCONFFILE}
62
63 # Generate a smbpasswd file?
64 db_get samba/generate_smbpasswd || true
65 GENERATE_SMBPASSWD="${RET}"
66
67 db_get samba/tdbsam || true
68 PDB_MIGRATE="${RET}"
69
70 # Done with debconf now.
71 db_stop
72
73 umask 066
74
75 # FIXME: disable if ldapsam support is enabled?
76 # FIXME: we don't want to pass these through the smbpasswd backend,
77 # some of the faking can cause us problems!
78 if [ "${GENERATE_SMBPASSWD}" = "true" -a ! -e /var/lib/samba/passdb.tdb -a ! -e /etc/samba/smbpasswd ]; then
79         getent passwd | /usr/sbin/mksmbpasswd > /etc/samba/smbpasswd
80         pdbedit -i smbpasswd -e tdbsam
81         rm /etc/samba/smbpasswd
82 fi
83
84 umask 022
85
86 if [ -n "$2" -a -e /etc/samba/smbpasswd \
87      -a ! -e /var/lib/samba/passdb.tdb -a "$PDB_MIGRATE" = "true" ] \
88    && dpkg --compare-versions "$2" lt 2.99.cvs.20020713-2
89 then
90         umask 066
91         pdbedit -i smbpasswd -e tdbsam
92         rm /etc/samba/smbpasswd
93         umask 022
94
95         # The database has been moved, now make sure we can still find it.
96         PASSDB=`sed -n -e"s/^[[:space:]]*\[global\]/\[global\]/
97                         /^\[global\]/,/^[[:space:]]*\[/ \
98                                 s/^[[:space:]]*passdb backend[[:space:]]*=[[:space:]]*//p" \
99                         < /etc/samba/smb.conf \
100          | tail -n 1`
101         if echo "$PASSDB" | egrep -q "(^|[[:space:]])smbpasswd"; then
102                 if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
103                         PASSDB=`echo $PASSDB | sed -e's/\(^\|[[:space:]]\)smbpasswd/\1tdbsam/'`
104                 fi
105         fi
106         if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
107                 PASSDB="tdbsam $PASSDB"
108         fi
109         TMPFILE=/etc/samba/smb.conf.dpkg-tmp
110         sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/
111                 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
112                         s/^\([[:space:]]*\)passdb backend[[:space:]]*=.*/\1passdb backend = ${PASSDB}/" \
113                 < /etc/samba/smb.conf >${TMPFILE}
114         chmod a+r ${TMPFILE}
115         mv -f ${TMPFILE} /etc/samba/smb.conf
116 fi
117
118 # ------------------------- Debconf questions end ---------------------
119
120 # Handle removal of nmbd from inetd.conf, which is no longer a supported
121 #       configuration.
122 if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4; then
123         update-inetd --remove netbios-ns
124 fi
125
126 # We want to add these entries to inetd.conf commented out. Otherwise
127 #       UDP traffic could make inetd to start nmbd or smbd right during
128 #       the configuration stage.
129 if [ -z "$2" ]; then
130         update-inetd --add "#<off># netbios-ssn stream  tcp     nowait  root    /usr/sbin/tcpd  /usr/sbin/smbd"
131 fi
132
133 if [ "$RUN_MODE" = "daemons" ]; then
134         update-inetd --disable netbios-ssn
135 else
136         update-inetd --enable netbios-ssn
137 fi
138
139 # This check is a safety net: the /etc/samba/smbpasswd file must have
140 #       permissions 600.
141 if [ -f /etc/samba/smbpasswd ]; then
142         chmod 600 /etc/samba/smbpasswd
143 fi
144
145 # Do the same check for /var/backup/smbpasswd.bak, just in case.
146 if [ -f /var/backups/smbpasswd.bak ]; then
147         chmod 600 /var/backups/smbpasswd.bak
148 fi
149
150 # Delete old /etc/samba/debian_config file, which is not used anymore
151 #       now that we are using debconf.
152 rm -f /etc/samba/debian_config
153
154 # Move old log files to the new location of Samba's log files
155 mv -f /var/log/nmb* /var/log/samba/ 2> /dev/null || true
156 mv -f /var/log/smb* /var/log/samba/ 2> /dev/null || true
157
158 #DEBHELPER#
159
160 exit 0