• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/samba-3.0.25b/packaging/Debian/debian-unstable/
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/ ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.0.7-4
60then
61	mv /var/samba/* /var/lib/samba/ 2>/dev/null || true
62	rmdir /var/samba/
63fi
64
65# Default for anything we don't know about (see next two 'for' loops)
66#	is /var/lib/samba -- guaranteed not to accidentally tromp on any 
67#	files the admin thought were safe.
68if [ -d /var/state/samba ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.2.3-4
69then
70	mv /var/state/samba/* /var/lib/samba/ 2>/dev/null || true
71	rmdir /var/state/samba/
72
73	# It's not FHS, and it's probably our fault this is here,
74	# so delete it if we can.
75	rmdir /var/state/ 2> /dev/null || true
76fi
77
78# All these files are now placed in their respective FHS-compliant
79#	directories.  Separate out the individual files accordingly.
80for F in browse.dat printing.tdb winbindd_cache.tdb
81do
82	if [ -e /var/lib/samba/"$F" ]; then
83		mv /var/lib/samba/"$F" /var/cache/samba/
84	fi
85done
86
87for F in brlock.tdb connections.tdb locking.tdb messages.tdb nmbd.pid \
88         sessionid.tdb smbd.pid unexpected.tdb 
89do
90	if [ -e /var/lib/samba/"$F" ]; then
91		mv /var/lib/samba/"$F" /var/run/samba/
92	fi
93done
94
95# Beginning with Samba 2.2.5-1, we also move the domain secrets file
96# to a more suitable location, since no one really edits this by hand.
97if [ -e /etc/samba/secrets.tdb -a ! -e /var/lib/samba/secrets.tdb ]
98then
99	mv /etc/samba/secrets.tdb /var/lib/samba/
100fi
101
102# If upgrading from a previous 2.999 snapshot, move the passdb.tdb
103# database into /var/lib.
104
105if [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.999+3.0.alpha23-5 \
106   && [ -e /etc/samba/passdb.tdb -a ! -e /var/lib/samba/passdb.tdb ]
107then
108	mv /etc/samba/passdb.tdb /var/lib/samba/
109fi
110
111# --- End of FHS migration code ---
112
113# If upgrading from a previous 2.999 snapshot, clear the broken
114# registry.tdb file.
115if [ -n "$2" ] && dpkg --compare-versions "$2" gt 2.99.cvs.20020713-1 \
116   && dpkg --compare-versions "$2" lt 2.999+3.0cvs20020805-1
117then
118	rm -f /var/lib/samba/registry.tdb
119fi
120
121# ------------------------- Debconf questions start ---------------------
122
123# Run Samba as daemons or from inetd?
124db_get samba/run_mode || true
125RUN_MODE="${RET}"
126
127TMPFILE=/etc/default/samba.dpkg-tmp
128sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
129        < ${INITCONFFILE} >${TMPFILE}
130chmod a+r ${TMPFILE}
131mv -f ${TMPFILE} ${INITCONFFILE}
132
133# Generate a smbpasswd file?
134db_get samba/generate_smbpasswd || true
135GENERATE_SMBPASSWD="${RET}"
136
137db_get samba/tdbsam || true
138PDB_MIGRATE="${RET}"
139
140# Done with debconf now.
141db_stop
142
143umask 066
144
145# FIXME: disable if ldapsam support is enabled?
146# FIXME: we don't want to pass these through the smbpasswd backend,
147# some of the faking can cause us problems!
148if [ "${GENERATE_SMBPASSWD}" = "true" -a ! -e /var/lib/samba/passdb.tdb -a ! -e /etc/samba/smbpasswd ]; then
149	getent passwd | /usr/sbin/mksmbpasswd > /etc/samba/smbpasswd
150	pdbedit -i smbpasswd -e tdbsam
151	rm /etc/samba/smbpasswd
152fi
153
154umask 022
155
156if [ -n "$2" -a -e /etc/samba/smbpasswd \
157     -a ! -e /var/lib/samba/passdb.tdb -a "$PDB_MIGRATE" = "true" ] \
158   && dpkg --compare-versions "$2" lt 2.99.cvs.20020713-2
159then
160	umask 066
161	pdbedit -i smbpasswd -e tdbsam
162	rm /etc/samba/smbpasswd
163	umask 022
164
165	# The database has been moved, now make sure we can still find it.
166	PASSDB=`sed -n -e"s/^[[:space:]]*\[global\]/\[global\]/i
167			/^\[global\]/,/^[[:space:]]*\[/ \
168				s/^[[:space:]]*passdb backend[[:space:]]*=[[:space:]]*//pi" \
169			< /etc/samba/smb.conf \
170	 | tail -n 1`
171	if echo "$PASSDB" | egrep -q "(^|[[:space:]])smbpasswd"; then
172		if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
173			PASSDB=`echo $PASSDB | sed -e's/\(^\|[[:space:]]\)smbpasswd/\1tdbsam/'`
174		fi
175	fi
176	if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
177		PASSDB="tdbsam $PASSDB"
178	fi
179	TMPFILE=/etc/samba/smb.conf.dpkg-tmp
180	sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
181		/^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
182			s/^\([[:space:]]*\)passdb backend[[:space:]]*=.*/\1passdb backend = ${PASSDB}/i" \
183		< /etc/samba/smb.conf >${TMPFILE}
184	chmod a+r ${TMPFILE}
185	mv -f ${TMPFILE} /etc/samba/smb.conf
186fi
187
188# ------------------------- Debconf questions end ---------------------
189
190# Handle removal of nmbd from inetd.conf, which is no longer a supported
191#	configuration.
192if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4; then
193	update-inetd --remove netbios-ns
194fi
195
196# We want to add these entries to inetd.conf commented out. Otherwise
197#	UDP traffic could make inetd to start nmbd or smbd right during
198#	the configuration stage.
199if [ -z "$2" ]; then
200	update-inetd --add "#<off># netbios-ssn	stream	tcp	nowait	root	/usr/sbin/tcpd	/usr/sbin/smbd"
201fi
202
203if [ "$RUN_MODE" = "daemons" ]; then
204	update-inetd --disable netbios-ssn
205else
206	update-inetd --enable netbios-ssn
207fi
208
209# This check is a safety net: the /etc/samba/smbpasswd file must have
210#	permissions 600.
211if [ -f /etc/samba/smbpasswd ]; then
212	chmod 600 /etc/samba/smbpasswd
213fi
214
215# Do the same check for /var/backup/smbpasswd.bak, just in case.
216if [ -f /var/backups/smbpasswd.bak ]; then
217	chmod 600 /var/backups/smbpasswd.bak
218fi
219
220# Delete old /etc/samba/debian_config file, which is not used anymore
221#	now that we are using debconf.
222rm -f /etc/samba/debian_config
223
224# Move old log files to the new location of Samba's log files
225mv -f /var/log/nmb* /var/log/samba/ 2> /dev/null || true
226mv -f /var/log/smb* /var/log/samba/ 2> /dev/null || true
227
228#DEBHELPER#
229
230exit 0
231