3 # Post-installation script for the Samba package for Debian GNU/Linux
12 abort-upgrade|abort-remove|abort-deconfigure)
17 echo "postinst called with unknown argument \`$1'" >&2
23 . /usr/share/debconf/confmodule
25 INITCONFFILE=/etc/default/samba
27 # We generate several files during the postinst, and we don't want
28 # them to be readable only by root.
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
42 # This is a POSIX shell fragment
45 # How should Samba (smbd) run? Possible values are "daemons"
51 # ------------------------- Debconf questions start ---------------------
53 # Run Samba as daemons or from inetd?
54 db_get samba/run_mode || true
57 TMPFILE=/etc/default/samba.dpkg-tmp
58 sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
59 < ${INITCONFFILE} >${TMPFILE}
61 mv -f ${TMPFILE} ${INITCONFFILE}
63 # Generate a smbpasswd file?
64 db_get samba/generate_smbpasswd || true
65 GENERATE_SMBPASSWD="${RET}"
67 db_get samba/tdbsam || true
70 # Done with debconf now.
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
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
91 pdbedit -i smbpasswd -e tdbsam
92 rm /etc/samba/smbpasswd
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 \
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/'`
106 if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
107 PASSDB="tdbsam $PASSDB"
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}
115 mv -f ${TMPFILE} /etc/samba/smb.conf
118 # ------------------------- Debconf questions end ---------------------
120 # Handle removal of nmbd from inetd.conf, which is no longer a supported
122 if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4; then
123 update-inetd --remove netbios-ns
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.
130 update-inetd --add "#<off># netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/sbin/smbd"
133 if [ "$RUN_MODE" = "daemons" ]; then
134 update-inetd --disable netbios-ssn
136 update-inetd --enable netbios-ssn
139 # This check is a safety net: the /etc/samba/smbpasswd file must have
141 if [ -f /etc/samba/smbpasswd ]; then
142 chmod 600 /etc/samba/smbpasswd
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
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
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