Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / packaging / Debian / debian-woody / samba.postinst
blob7b0bdd92ad5cfcb8ac94035e88b97229d1f6f010
1 #!/bin/sh -e
3 # Post-installation script for the Samba package for Debian GNU/Linux
7 case "$1" in
8 configure)
9 # continue below
12 abort-upgrade|abort-remove|abort-deconfigure)
13 exit 0
17 echo "postinst called with unknown argument \`$1'" >&2
18 exit 0
20 esac
22 # Handle debconf
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.
29 umask 022
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"
46 # or "inetd".
47 RUN_MODE=""
48 EOFMAGICNUMBER1234
51 # --- Begin of FHS migration code ---
53 # Starting with Samba 2.2.3-4 the WINS database, the browse
54 # database and other important run-time files are stored in
55 # FHS-compliant directories. The following code takes care of
56 # moving the files in the old directories (/var/samba/ and
57 # /var/state/samba) to the new FHS-compliant directories.
59 if [ -d /var/samba/ ]; then
60 mv /var/samba/* /var/lib/samba/ 2>/dev/null || true
61 rmdir /var/samba/
64 # Default for anything we don't know about (see next two 'for' loops)
65 # is /var/lib/samba -- guaranteed not to accidentally tromp on any
66 # files the admin thought were safe.
67 if [ -d /var/state/samba ]; then
68 mv /var/state/samba/* /var/lib/samba/ 2>/dev/null || true
69 rmdir /var/state/samba/
71 # It's not FHS, and it's probably our fault this is here,
72 # so delete it if we can.
73 rmdir /var/state/ 2> /dev/null || true
76 # All these files are now placed in their respective FHS-compliant
77 # directories. Separate out the individual files accordingly.
78 for F in browse.dat printing.tdb winbindd_cache.tdb
80 if [ -e /var/lib/samba/"$F" ]; then
81 mv /var/lib/samba/"$F" /var/cache/samba/
83 done
85 for F in brlock.tdb connections.tdb locking.tdb messages.tdb nmbd.pid \
86 sessionid.tdb smbd.pid unexpected.tdb
88 if [ -e /var/lib/samba/"$F" ]; then
89 mv /var/lib/samba/"$F" /var/run/samba/
91 done
93 # Beginning with Samba 2.2.5-1, we also move the domain secrets file
94 # to a more suitable location, since no one really edits this by hand.
95 if [ -e /etc/samba/secrets.tdb -a ! -e /var/lib/samba/secrets.tdb ]
96 then
97 mv /etc/samba/secrets.tdb /var/lib/samba/
100 # If upgrading from a previous 2.999 snapshot, move the passdb.tdb
101 # database into /var/lib.
103 if [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.999+3.0.alpha23-5 \
104 && [ -e /etc/samba/passdb.tdb -a ! -e /var/lib/samba/passdb.tdb ]
105 then
106 mv /etc/samba/passdb.tdb /var/lib/samba/
109 # --- End of FHS migration code ---
111 # If upgrading from a previous 2.999 snapshot, clear the broken
112 # registry.tdb file.
113 if [ -n "$2" ] && dpkg --compare-versions "$2" gt 2.99.cvs.20020713-1 \
114 && dpkg --compare-versions "$2" lt 2.999+3.0cvs20020805-1
115 then
116 rm -f /var/lib/samba/registry.tdb
119 # ------------------------- Debconf questions start ---------------------
121 # Run Samba as daemons or from inetd?
122 db_get samba/run_mode || true
123 RUN_MODE="${RET}"
125 TMPFILE=/etc/default/samba.dpkg-tmp
126 sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
127 < ${INITCONFFILE} >${TMPFILE}
128 chmod a+r ${TMPFILE}
129 mv -f ${TMPFILE} ${INITCONFFILE}
131 # Generate a smbpasswd file?
132 db_get samba/generate_smbpasswd || true
133 GENERATE_SMBPASSWD="${RET}"
135 db_get samba/tdbsam || true
136 PDB_MIGRATE="${RET}"
138 # Done with debconf now.
139 db_stop
141 umask 066
143 # FIXME: disable if ldapsam support is enabled?
144 # FIXME: we don't want to pass these through the smbpasswd backend,
145 # some of the faking can cause us problems!
146 if [ "${GENERATE_SMBPASSWD}" = "true" -a ! -e /var/lib/samba/passdb.tdb -a ! -e /etc/samba/smbpasswd ]; then
147 getent passwd | /usr/sbin/mksmbpasswd > /etc/samba/smbpasswd
148 pdbedit -i smbpasswd -e tdbsam
149 rm /etc/samba/smbpasswd
152 umask 022
154 if [ -n "$2" -a -e /etc/samba/smbpasswd \
155 -a ! -e /var/lib/samba/passdb.tdb -a "$PDB_MIGRATE" = "true" ] \
156 && dpkg --compare-versions "$2" lt 2.99.cvs.20020713-2
157 then
158 umask 066
159 pdbedit -i smbpasswd -e tdbsam
160 rm /etc/samba/smbpasswd
161 umask 022
163 # The database has been moved, now make sure we can still find it.
164 PASSDB=`sed -n -e"s/^[[:space:]]*\[global\]/\[global\]/i
165 /^\[global\]/,/^[[:space:]]*\[/ \
166 s/^[[:space:]]*passdb backend[[:space:]]*=[[:space:]]*//pi" \
167 < /etc/samba/smb.conf \
168 | tail -n 1`
169 if echo "$PASSDB" | egrep -q "(^|[[:space:]])smbpasswd"; then
170 if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
171 PASSDB=`echo $PASSDB | sed -e's/\(^\|[[:space:]]\)smbpasswd/\1tdbsam/'`
174 if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
175 PASSDB="tdbsam $PASSDB"
177 TMPFILE=/etc/samba/smb.conf.dpkg-tmp
178 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
179 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
180 s/^\([[:space:]]*\)passdb backend[[:space:]]*=.*/\1passdb backend = ${PASSDB}/i" \
181 < /etc/samba/smb.conf >${TMPFILE}
182 chmod a+r ${TMPFILE}
183 mv -f ${TMPFILE} /etc/samba/smb.conf
186 # ------------------------- Debconf questions end ---------------------
188 # Handle removal of nmbd from inetd.conf, which is no longer a supported
189 # configuration.
190 if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4; then
191 update-inetd --remove netbios-ns
194 # We want to add these entries to inetd.conf commented out. Otherwise
195 # UDP traffic could make inetd to start nmbd or smbd right during
196 # the configuration stage.
197 if [ -z "$2" ]; then
198 update-inetd --add "#<off># netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/sbin/smbd"
201 if [ "$RUN_MODE" = "daemons" ]; then
202 update-inetd --disable netbios-ssn
203 else
204 update-inetd --enable netbios-ssn
207 # This check is a safety net: the /etc/samba/smbpasswd file must have
208 # permissions 600.
209 if [ -f /etc/samba/smbpasswd ]; then
210 chmod 600 /etc/samba/smbpasswd
213 # Do the same check for /var/backup/smbpasswd.bak, just in case.
214 if [ -f /var/backups/smbpasswd.bak ]; then
215 chmod 600 /var/backups/smbpasswd.bak
218 # Delete old /etc/samba/debian_config file, which is not used anymore
219 # now that we are using debconf.
220 rm -f /etc/samba/debian_config
222 # Move old log files to the new location of Samba's log files
223 mv -f /var/log/nmb* /var/log/samba/ 2> /dev/null || true
224 mv -f /var/log/smb* /var/log/samba/ 2> /dev/null || true
226 #DEBHELPER#
228 exit 0