[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: RFC: some new deb package flag: "upgrade-conflicts"

On Thu, Oct 03, 2002 at 06:55:45PM +1000, Anthony Towns wrote:
> On Wed, Oct 02, 2002 at 10:57:09AM -0500, Steve Langasek wrote:
> > [...] For my part, I greedily strip legacy code
> > out of my maintainer scripts when a stable release is finalized -- if you
> > think leaving this stuff around doesn't make maintenance more difficult,
> > I have some scripts to show you... :)

> Would you mind?


Attached is the postinst script from the current Samba package.  It has
not yet been trimmed following woody's release, but I expect it will be
advantageous to do so before too long.

About 60 lines (of a total 232) are used only for supporting upgrades
from potato or from unreleased testing/unstable packages between the
potato and woody releases (Eloy and I *do* take upgradeability
seriously).  That's about a 25% overhead for an unsupported upgrade path,
by my numbers.  Depending on how long the sarge release cycle runs, we
could easily accumulate another 60 lines: potato->woody was a move to
use FHS, woody->sarge will be an upgrade from Samba 2.2->3.0.

So, the file looks a bit cluttered.  If you can suggest a way to make a
shell script do a lot of stuff without looking cluttered (which I believe
is an inherent property of shell scripts), I'm all ears. :)  Otherwise, I
view supporting potato->sarge upgrades as more cumbersome than not
supporting them.  Maybe not prohibitively so -- if Policy says we have to
do it, it can be done -- but given the choice, I think there are more
productive things that I can spend my development time on, especially
when it's so easy to introduce a bug in the script that can render this
little-tested upgrade path completely useless.

Steve Langasek
postmodern programmer
#!/bin/sh -e
# Post-installation script for the Samba package for Debian GNU/Linux
# $Id$

case "$1" in
		# continue below

		exit 0

		echo "postinst called with unknown argument \`$1'" >&2
		exit 0

# Handle debconf
. /usr/share/debconf/confmodule


# We generate several files during the postinst, and we don't want
#	them to be readable only by root.
umask 022

# Generate configuration file if it does not exist, using default values.
[ -r "${INITCONFFILE}" ] || {
	echo Generating ${INITCONFFILE}... >&2
# Defaults for samba initscript
# sourced by /etc/init.d/samba
# installed at /etc/default/samba by the maintainer scripts

# This is a POSIX shell fragment

# How should Samba (nmbd and smbd) run? Possible values are "daemons"
#	or "inetd".

# --- Begin of FHS migration code ---

# Starting with Samba 2.2.3-4 the WINS database, the browse
#	database and other important run-time files are stored in
#	FHS-compliant directories. The following code takes care of
#	moving the files in the old directories (/var/samba/ and
#	/var/state/samba) to the new FHS-compliant directories.

if [ -d /var/samba/ ]; then
	mv /var/samba/* /var/lib/samba/ 2>/dev/null || true
	rmdir /var/samba/

# Default for anything we don't know about (see next two 'for' loops)
#	is /var/lib/samba -- guaranteed not to accidentally tromp on any 
#	files the admin thought were safe.
if [ -d /var/state/samba ]; then
	mv /var/state/samba/* /var/lib/samba/ 2>/dev/null || true
	rmdir /var/state/samba/

	# It's not FHS, and it's probably our fault this is here,
	# so delete it if we can.
	rmdir /var/state/ 2> /dev/null || true

# All these files are now placed in their respective FHS-compliant
#	directories.  Separate out the individual files accordingly.
for F in browse.dat printing.tdb winbindd_cache.tdb
	if [ -e /var/lib/samba/"$F" ]; then
		mv /var/lib/samba/"$F" /var/cache/samba/

for F in brlock.tdb connections.tdb locking.tdb messages.tdb nmbd.pid \
         sessionid.tdb smbd.pid unexpected.tdb 
	if [ -e /var/lib/samba/"$F" ]; then
		mv /var/lib/samba/"$F" /var/run/samba/

# Beginning with Samba 2.2.5-1, we also move the domain secrets file
# to a more suitable location, since no one really edits this by hand.
if [ -e /etc/samba/secrets.tdb -a ! -e /var/lib/samba/secrets.tdb ]
	mv /etc/samba/secrets.tdb /var/lib/samba/

# --- End of FHS migration code ---

# If upgrading from a previous 2.999 snapshot, clear the broken
# registry.tdb file.
if [ -n "$2" ] && dpkg --compare-versions "$2" gt 2.99.cvs.20020713-1 \
   && dpkg --compare-versions "$2" lt 2.999+3.0cvs20020805-1
	rm -f /var/lib/samba/registry.tdb

# ------------------------- Debconf questions start ---------------------

# Run Samba as daemons or from inetd?
db_get samba/run_mode || true

TMPFILE=`mktemp -q /tmp/samba.config.XXXXXX`
sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
chmod a+r ${TMPFILE}

# Generate a smbpasswd file?
db_get samba/generate_smbpasswd || true

db_get samba/tdbsam || true

# Done with debconf now.

umask 066

# FIXME: disable if ldapsam support is enabled?
# FIXME: we don't want to pass these through the smbpasswd backend,
# some of the faking can cause us problems!
if [ "${GENERATE_SMBPASSWD}" = "true" -a ! -e /etc/samba/passdb.tdb -a ! -e /etc/samba/smbpasswd ]; then
	getent passwd | /usr/sbin/mksmbpasswd > /etc/samba/smbpasswd
	pdbedit -i smbpasswd -e tdbsam
	rm /etc/samba/smbpasswd

umask 022

if [ "$1" = "configure" -a -n "$2" -a -e /etc/samba/smbpasswd \
     -a ! -e /etc/samba/passdb.tdb -a "$PDB_MIGRATE" = "true" ] \
   && dpkg --compare-versions "$2" lt 2.99.cvs.20020713-2
	umask 066
	pdbedit -i smbpasswd -e tdbsam
	rm /etc/samba/smbpasswd
	umask 022

	# The database has been moved, now make sure we can still find it.
	PASSDB=`grep -i '^[[:space:]]*passdb backend[[:space:]]*=' /etc/samba/smb.conf \
	 | sed -e's/^[[:space:]]*passdb backend[[:space:]]*=[[:space:]]*//i' \
	 | tail -1`
	if echo "$PASSDB" | egrep -q "(^|[[:space:]])smbpasswd"; then
		if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
			PASSDB=`echo $PASSDB | sed -e's/\(^\|[[:space:]]\)smbpasswd/\1tdbsam/'`
	if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
		PASSDB="tdbsam $PASSDB"
	TMPFILE=`mktemp -q /tmp/smb.conf.XXXXXX`
	sed -e "s/^\([[:space:]]*\)passdb backend[[:space:]]*=.*/\1passdb backend = ${PASSDB}/" \
		< /etc/samba/smb.conf >${TMPFILE}
	chmod a+r ${TMPFILE}
	mv -f ${TMPFILE} /etc/samba/smb.conf

# ------------------------- Debconf questions end ---------------------

# We always run /etc/init.d/samba, even if we run Samba from inetd.
#	The init.d script takes care of handling the conflict of running
#	from inetd or as daemons.
update-rc.d samba defaults 20 19 > /dev/null

# We want to add these entries to inetd.conf commented out. Otherwise
#	UDP traffic could make inetd to start nmbd or smbd right during
#	the configuration stage.
if [ "$1" = "configure" -a -z "$2" ]; then
	update-inetd --add "#<off># netbios-ns	dgram	udp	wait	root 	/usr/sbin/tcpd	/usr/sbin/nmbd -a"
	update-inetd --add "#<off># netbios-ssn	stream	tcp	nowait	root	/usr/sbin/tcpd	/usr/sbin/smbd"

if [ "$RUN_MODE" = "daemons" ]; then
	update-inetd --disable netbios-ns
	update-inetd --disable netbios-ssn
	update-inetd --enable netbios-ns
	update-inetd --enable netbios-ssn

# Start Samba: we don't want to call /etc/init.d/samba if we are
# running from inetd because a nasty help message would be printed out.

# Run the init script if this is a first-time install, or if it's an
# upgrade and Samba was running before, _and_ we're not running from inetd.
if [ \( -z "$2" -o ! -f /tmp/samba-was-not-running \) -a \
		"$RUN_MODE" = "daemons" ]; then
	# Check the script is executable before running it.
	[ -x /etc/init.d/samba ] && /etc/init.d/samba start

# This check is a safety net: the /etc/samba/smbpasswd file must have
#	permissions 600.
if [ -f /etc/samba/smbpasswd ]; then
	chmod 600 /etc/samba/smbpasswd

# Do the same check for /var/backup/smbpasswd.bak, just in case.
if [ -f /var/backups/smbpasswd.bak ]; then
	chmod 600 /var/backups/smbpasswd.bak

# Delete old /etc/samba/debian_config file, which is not used anymore
#	now that we are using debconf.
rm -f /etc/samba/debian_config

# Move old log files to the new location of Samba's log files
mv -f /var/log/nmb* /var/log/samba/ 2> /dev/null || true
mv -f /var/log/smb* /var/log/samba/ 2> /dev/null || true

# Do this last, so we don't accidentally start the daemons if something 
# else in the script fails above.
rm -f /tmp/samba-was-not-running


exit 0

Attachment: pgpIRYQIVoGbD.pgp
Description: PGP signature

Reply to: