-#!/bin/sh -e
-
-exit 0
+#!/bin/sh
+#
+# Post-installation script for the Samba package for Debian GNU/Linux
+#
+#
+set -e
+# Handle debconf
. /usr/share/debconf/confmodule
-if [ "$1" = "configure" ]; then
- db_get samba4/server-role || true
- SERVER_ROLE="$RET"
- db_get samba-common/workgroup || true
- DOMAIN="$RET"
- db_get samba4/realm || true
- REALM="$RET"
- # FIXME: Urgh.. ideally samba-tool would be able to update this:
- # Update realm setting and server role setting
- if [ -f "/etc/samba/smb.conf" ]; then
- /usr/share/samba/setoption.py "realm" "${REALM}"
- /usr/share/samba/setoption.py "server role" "${SERVER_ROLE}"
- fi
+INITCONFFILE=/etc/default/samba
+
+# 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
+ cat >${INITCONFFILE} <<'EOFMAGICNUMBER1234'
+# 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 (smbd) run? Possible values are "daemons"
+# or "inetd".
+RUN_MODE=""
+EOFMAGICNUMBER1234
+}
+
+# ------------------------- Debconf questions start ---------------------
+
+# Run Samba as daemons or from inetd?
+db_get samba/run_mode || true
+RUN_MODE="${RET}"
+
+TMPFILE=/etc/default/samba.dpkg-tmp
+sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
+ < ${INITCONFFILE} >${TMPFILE}
+chmod a+r ${TMPFILE}
+mv -f ${TMPFILE} ${INITCONFFILE}
+
+# Done with debconf now.
+db_stop
+
+umask 022
+
+# ------------------------- Debconf questions end ---------------------
+
+# 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 [ -z "$2" ]; then
+ update-inetd --add "#<off># netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/sbin/smbd"
+fi
+
+if [ "$RUN_MODE" = "daemons" ]; then
+ update-inetd --disable netbios-ssn
+else
+ update-inetd --enable netbios-ssn
+fi
- # See if we're upgrading from Samba 3
- if [ ! -z "$2" ]; then
- # Upgrade from previous Samba 4 installation
- if [ -f /etc/samba/smb.conf ]; then
- samba-tool dbcheck
- fi
+# add the sambashare group
+if ! getent group sambashare > /dev/null 2>&1
+then
+ addgroup --system sambashare
+ # Only on Ubuntu, use the "admin" group as a template for the
+ # initial users for this group; Debian has no equivalent group,
+ # so leaving the sambashare group empty is the more secure default
+ if [ -x "`which lsb_release 2>/dev/null`" ] \
+ && [ "`lsb_release -s -i`" = "Ubuntu" ]
+ then
+ OLDIFS="$IFS"
+ IFS=","
+ for USER in `getent group admin | cut -f4 -d:`; do
+ adduser "$USER" sambashare \
+ || ! getent passwd "$USER" >/dev/null
+ done
+ IFS="$OLDIFS"
fi
fi
-#DEBHELPER#
+if [ ! -e /var/lib/samba/usershares ]
+then
+ install -d -m 1770 -g sambashare /var/lib/samba/usershares
+fi
-db_stop
+update-alternatives --install /usr/bin/smbstatus smbstatus /usr/bin/smbstatus.samba3 10 \
+ --slave /usr/share/man/man1/smbstatus.1.gz smbstatus.1.gz /usr/share/man/man1/smbstatus.samba3.1.gz
+
+#DEBHELPER#
exit 0