• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/samba-3.0.13/packaging/Debian/debian-stable/
1#!/bin/sh -e
2#
3# Post-installation script for the Samba package for Debian GNU/Linux
4#
5#
6
7case "$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	;;
20esac
21
22# Handle debconf
23. /usr/share/debconf/confmodule
24
25INITCONFFILE=/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.
29umask 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".
47RUN_MODE=""
48EOFMAGICNUMBER1234
49}
50
51# --- Begin of FHS migration code ---
52
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.
58
59if [ -d /var/samba/ ]; then
60	mv /var/samba/* /var/lib/samba/ 2>/dev/null || true
61	rmdir /var/samba/
62fi
63
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.
67if [ -d /var/state/samba ]; then
68	mv /var/state/samba/* /var/lib/samba/ 2>/dev/null || true
69	rmdir /var/state/samba/
70
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
74fi
75
76# All these files are now placed in their respective FHS-compliant
77#	directories.  Separate out the individual files accordingly.
78for F in browse.dat printing.tdb winbindd_cache.tdb
79do
80	if [ -e /var/lib/samba/"$F" ]; then
81		mv /var/lib/samba/"$F" /var/cache/samba/
82	fi
83done
84
85for F in brlock.tdb connections.tdb locking.tdb messages.tdb nmbd.pid \
86         sessionid.tdb smbd.pid unexpected.tdb 
87do
88	if [ -e /var/lib/samba/"$F" ]; then
89		mv /var/lib/samba/"$F" /var/run/samba/
90	fi
91done
92
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.
95if [ -e /etc/samba/secrets.tdb -a ! -e /var/lib/samba/secrets.tdb ]
96then
97	mv /etc/samba/secrets.tdb /var/lib/samba/
98fi
99
100# If upgrading from a previous 2.999 snapshot, move the passdb.tdb
101# database into /var/lib.
102
103if [ -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 ]
105then
106	mv /etc/samba/passdb.tdb /var/lib/samba/
107fi
108
109# --- End of FHS migration code ---
110
111# If upgrading from a previous 2.999 snapshot, clear the broken
112# registry.tdb file.
113if [ -n "$2" ] && dpkg --compare-versions "$2" gt 2.99.cvs.20020713-1 \
114   && dpkg --compare-versions "$2" lt 2.999+3.0cvs20020805-1
115then
116	rm -f /var/lib/samba/registry.tdb
117fi
118
119# ------------------------- Debconf questions start ---------------------
120
121# Run Samba as daemons or from inetd?
122db_get samba/run_mode || true
123RUN_MODE="${RET}"
124
125TMPFILE=/etc/default/samba.dpkg-tmp
126sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
127        < ${INITCONFFILE} >${TMPFILE}
128chmod a+r ${TMPFILE}
129mv -f ${TMPFILE} ${INITCONFFILE}
130
131# Generate a smbpasswd file?
132db_get samba/generate_smbpasswd || true
133GENERATE_SMBPASSWD="${RET}"
134
135db_get samba/tdbsam || true
136PDB_MIGRATE="${RET}"
137
138# Done with debconf now.
139db_stop
140
141umask 066
142
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!
146if [ "${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
150fi
151
152umask 022
153
154if [ -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
157then
158	umask 066
159	pdbedit -i smbpasswd -e tdbsam
160	rm /etc/samba/smbpasswd
161	umask 022
162
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/'`
172		fi
173	fi
174	if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
175		PASSDB="tdbsam $PASSDB"
176	fi
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
184fi
185
186# ------------------------- Debconf questions end ---------------------
187
188# Handle removal of nmbd from inetd.conf, which is no longer a supported
189#	configuration.
190if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4; then
191	update-inetd --remove netbios-ns
192fi
193
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.
197if [ -z "$2" ]; then
198	update-inetd --add "#<off># netbios-ssn	stream	tcp	nowait	root	/usr/sbin/tcpd	/usr/sbin/smbd"
199fi
200
201if [ "$RUN_MODE" = "daemons" ]; then
202	update-inetd --disable netbios-ssn
203else
204	update-inetd --enable netbios-ssn
205fi
206
207# This check is a safety net: the /etc/samba/smbpasswd file must have
208#	permissions 600.
209if [ -f /etc/samba/smbpasswd ]; then
210	chmod 600 /etc/samba/smbpasswd
211fi
212
213# Do the same check for /var/backup/smbpasswd.bak, just in case.
214if [ -f /var/backups/smbpasswd.bak ]; then
215	chmod 600 /var/backups/smbpasswd.bak
216fi
217
218# Delete old /etc/samba/debian_config file, which is not used anymore
219#	now that we are using debconf.
220rm -f /etc/samba/debian_config
221
222# Move old log files to the new location of Samba's log files
223mv -f /var/log/nmb* /var/log/samba/ 2> /dev/null || true
224mv -f /var/log/smb* /var/log/samba/ 2> /dev/null || true
225
226#DEBHELPER#
227
228exit 0
229