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