syncing RCS tag removal from 3.0 release tree
[ira/wip.git] / packaging / Debian / debian / samba-common.postinst
1 #!/bin/sh
2 #
3 #
4
5 set -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.
12 if [ ! -e /etc/samba/smb.conf ]; then
13         cp -a /usr/share/samba/smb.conf /etc/samba/
14 fi
15
16 # Static tempfile location, dpkg-style
17 TMPFILE=/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?
23 db_get samba-common/do_debconf || true
24 if [ "${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                 DISPLAYCHARSET="${RET}"
83                 if [ -n "$DISPLAYCHARSET" ]
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    display charset = $DISPLAYCHARSET\\
90    unix charset = $DISPLAYCHARSET
91                                 }" < /etc/samba/smb.conf > ${TMPFILE}
92                         mv -f ${TMPFILE} /etc/samba/smb.conf
93                 fi
94         fi
95
96         if grep -qi "^[[:space:]]*passdb backend[[:space:]]*=.*unixsam" /etc/samba/smb.conf
97         then
98                 sed -e 's/^\([[:space:]]*\)passdb backend/\1passdb backend/i
99                         /^[[:space:]]*passdb backend/ {
100                                 s/unixsam/guest/i
101                         }' < /etc/samba/smb.conf > ${TMPFILE}
102                 mv -f ${TMPFILE} /etc/samba/smb.conf
103         fi
104
105         if ! grep -q "^[[:space:]]*dos charset[[:space:]]*=" /etc/samba/smb.conf
106         then
107                 db_get samba-common/codepage || true
108                 DOSCHARSET="${RET}"
109                 if [ -n "$DOSCHARSET" ]
110                 then
111                         sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
112                                 s/^\([[:space:]]*\)client code page/\1client code page/i
113                                 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ {
114                                         /^[[:space:]]*client code page[[:space:]]*=/c \\
115    dos charset = $DOSCHARSET
116 }" < /etc/samba/smb.conf > ${TMPFILE}
117                         mv -f ${TMPFILE} /etc/samba/smb.conf
118                 fi
119         fi
120
121         if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4 \
122            && ! grep -q "^[[:space:]]*panic action[[:space:]]*=" /etc/samba/smb.conf
123         then
124                 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
125                         /^[[:space:]]*\[global\]/a \\
126 \\
127 # Do something sensible when Samba crashes: mail the admin a backtrace\\
128    panic action = /usr/share/samba/panic-action %d" < /etc/samba/smb.conf > ${TMPFILE}
129                 mv -f ${TMPFILE} /etc/samba/smb.conf
130         fi
131
132 fi
133
134 chmod a+r /etc/samba/smb.conf
135
136 # ------------------------- Debconf questions end ---------------------
137
138 db_stop
139
140 #DEBHELPER#