1#!/bin/sh 2# 3# 4 5set -e 6 7# Do debconf stuff here 8. /usr/share/debconf/confmodule 9 10# We need a default smb.conf file. If one doesn't exist we put in place 11# one that has some basic defaults. 12if [ ! -e /etc/samba/smb.conf ]; then 13 cp -a /usr/share/samba/smb.conf /etc/samba/ 14fi 15 16# Static tempfile location, dpkg-style 17TMPFILE=/etc/samba/smb.conf.dpkg-tmp 18 19# ------------------------- Debconf questions start --------------------- 20 21# Is the user configuring with debconf, or he/she prefers swat/manual 22# config? 23db_get samba-common/do_debconf || true 24if [ "${RET}" = "true" ]; then 25 # Get workgroup name 26 db_get samba-common/workgroup || true 27 WORKGROUP="${RET}" 28 29 # Oh my GOD, this is ugly. Why would anyone put these 30 # characters in a workgroup name? Why, Lord, why??? 31 WORKGROUP=`echo $WORKGROUP | \ 32 sed -e's/\\\\/\\\\\\\\/g 33 s#/#\\\\/#g 34 s/&/\\\&/g 35 s/\\\$/\\\\\\\$/g'` 36 37 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i 38 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \ 39 s/^\([[:space:]]*\)workgroup[[:space:]]*=.*/\1workgroup = ${WORKGROUP}/i" \ 40 < /etc/samba/smb.conf >${TMPFILE} 41 mv -f ${TMPFILE} /etc/samba/smb.conf 42 43 # Encrypt passwords? 44 db_get samba-common/encrypt_passwords || true 45 ENCRYPT_PASSWORDS="${RET}" 46 47 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i 48 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \ 49 s/^\([[:space:]]*\)encrypt passwords[[:space:]]*=.*/\1encrypt passwords = ${ENCRYPT_PASSWORDS}/i" \ 50 < /etc/samba/smb.conf >${TMPFILE} 51 mv -f ${TMPFILE} /etc/samba/smb.conf 52 53 # Install DHCP support 54 db_get samba-common/dhcp && DHCPVAL="$RET" 55 db_fget samba-common/dhcp applied || true 56 if [ "$DHCPVAL" = true ] && [ "$RET" != true ] && \ 57 ! grep -q dhcp.conf /etc/samba/smb.conf 58 then 59 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i 60 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ { 61 /wins server[[:space:]]*=/a \\ 62\\ 63# If we receive WINS server info from DHCP, override the options above. \\ 64 include = /etc/samba/dhcp.conf 65}" < /etc/samba/smb.conf > ${TMPFILE} 66 mv -f ${TMPFILE} /etc/samba/smb.conf 67 elif [ "$RET" != true ] && grep -q dhcp.conf /etc/samba/smb.conf 68 then 69 : 70 # FIXME: here we /delete/ the lines? 71 fi 72 # Once we get here, the config has been applied, whatever 73 # it is. 74 if [ "$RET" != true ]; then 75 db_fset samba-common/dhcp applied true 76 fi 77 78 # Update charset settings? 79 if ! grep -q "^[[:space:]]*unix charset[[:space:]]*=" /etc/samba/smb.conf 80 then 81 db_get samba-common/character_set || true 82 UNIXCHARSET="${RET}" 83 if [ -n "$UNIXCHARSET" ] 84 then 85 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i 86 s/^\([[:space:]]*\)character set/\1character set/i 87 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ { 88 /^[[:space:]]*character set[[:space:]]*=/c \\ 89 unix charset = $UNIXCHARSET 90 }" < /etc/samba/smb.conf > ${TMPFILE} 91 mv -f ${TMPFILE} /etc/samba/smb.conf 92 fi 93 fi 94 95 if grep -qi "^[[:space:]]*passdb backend[[:space:]]*=.*unixsam" /etc/samba/smb.conf 96 then 97 sed -e 's/^\([[:space:]]*\)passdb backend/\1passdb backend/i 98 /^[[:space:]]*passdb backend/ { 99 s/unixsam/guest/i 100 }' < /etc/samba/smb.conf > ${TMPFILE} 101 mv -f ${TMPFILE} /etc/samba/smb.conf 102 fi 103 104 if ! grep -q "^[[:space:]]*dos charset[[:space:]]*=" /etc/samba/smb.conf 105 then 106 db_get samba-common/codepage || true 107 DOSCHARSET="${RET}" 108 if [ -n "$DOSCHARSET" ] 109 then 110 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i 111 s/^\([[:space:]]*\)client code page/\1client code page/i 112 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ { 113 /^[[:space:]]*client code page[[:space:]]*=/c \\ 114 dos charset = $DOSCHARSET 115}" < /etc/samba/smb.conf > ${TMPFILE} 116 mv -f ${TMPFILE} /etc/samba/smb.conf 117 fi 118 fi 119 120 if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4 \ 121 && ! grep -q "^[[:space:]]*panic action[[:space:]]*=" /etc/samba/smb.conf 122 then 123 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i 124 /^[[:space:]]*\[global\]/a \\ 125\\ 126# Do something sensible when Samba crashes: mail the admin a backtrace\\ 127 panic action = /usr/share/samba/panic-action %d" < /etc/samba/smb.conf > ${TMPFILE} 128 mv -f ${TMPFILE} /etc/samba/smb.conf 129 fi 130 131fi 132 133chmod a+r /etc/samba/smb.conf 134 135# ------------------------- Debconf questions end --------------------- 136 137db_stop 138 139#DEBHELPER# 140