~ubuntu-branches/ubuntu/jaunty/samba/jaunty-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
#
#

set -e

if [ "$1" = "configure" ]
then
	update-alternatives --install /usr/bin/nmblookup nmblookup /usr/bin/nmblookup.samba3 0 \
		--slave /usr/share/man/man1/nmblookup.1.gz nmblookup.1.gz /usr/share/man/man1/nmblookup.samba3.1.gz
	update-alternatives --install /usr/bin/net net /usr/bin/net.samba3 10 \
		--slave /usr/share/man/man8/net.8.gz net.8.gz /usr/share/man/man8/net.samba3.8.gz
	update-alternatives --install /usr/bin/testparm testparm /usr/bin/testparm.samba3 10 \
		--slave /usr/share/man/man1/testparm.1.gz testparm.1.gz /usr/share/man/man1/testparm.samba3.1.gz
	for N in valid.dat upcase.dat lowcase.dat
	do
		update-alternatives --install /usr/share/samba/$N $N /usr/share/samba/$N.samba3 0
	done
	update-alternatives --install /usr/share/samba/panic-action samba-panic-action /usr/share/samba/panic-action.samba3 0
fi

# Do debconf stuff here
. /usr/share/debconf/confmodule

TEMPDIR=/var/run/samba/upgrades
NEWFILE=$TEMPDIR/smb.conf
CONFIG=/etc/samba/smb.conf

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

configure_smb_conf() {
	local CONFIG
	CONFIG="$1"

	# Is the user configuring with debconf, or he/she prefers
	# swat/manual config?
	db_get samba-common/do_debconf || true
	if [ "${RET}" != "true" ]; then
		return 0
	fi

	# Get workgroup name
	db_get samba-common/workgroup || true
	WORKGROUP="${RET}"

	# Oh my GOD, this is ugly.  Why would anyone put these
	# characters in a workgroup name?  Why, Lord, why???
	WORKGROUP=`echo $WORKGROUP | \
	           sed -e's/\\\\/\\\\\\\\/g
	                  s#/#\\\\/#g
	                  s/&/\\\&/g
	                  s/\\\$/\\\\\\\$/g'`

	sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
		/^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
			s/^\([[:space:]]*\)workgroup[[:space:]]*=.*/\1workgroup = ${WORKGROUP}/i" \
		"$CONFIG"

	# Encrypt passwords?
	db_get samba-common/encrypt_passwords || true
	ENCRYPT_PASSWORDS="${RET}"

	sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
		/^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
		        s/^\([[:space:]]*\)encrypt passwords[[:space:]]*=.*/\1encrypt passwords = ${ENCRYPT_PASSWORDS}/i" \
		"$CONFIG"

	# Install DHCP support
	db_get samba-common/dhcp
	if [ "$RET" = true ] && \
	   ! grep -q dhcp.conf "$CONFIG"
	then
		sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
			/^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ {
				/wins server[[:space:]]*=/a \\
\\
# If we receive WINS server info from DHCP, override the options above. \\
   include = /etc/samba/dhcp.conf
}" "$CONFIG"
	elif [ "$RET" != true ]; then
		sed -i -e '
		/^#[[:space:]]*If we receive WINS server info from DHCP, override the options above/d
		/^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/,/[^[:space:]]/ {
			/^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/d
			/^[[:space:]]*$/d
		}' "$CONFIG"
	fi

	if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.23b-2 \
	   && grep -qi "^[[:space:]]*passdb backend[[:space:]]*=.*guest" "$CONFIG"
	then
		sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
			/^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
			        s/^\([[:space:]]*passdb backend[[:space:]]*=[^,]*\),\?[[:space:]]*guest[[:space:]]*$/\1/i" \
			"$CONFIG"
	fi
}


if [ -e "$CONFIG" ]; then
	configure_smb_conf "$CONFIG"
fi

mkdir -p "$TEMPDIR"

if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.28-3; then
	if dpkg --compare-versions "$2" lt 3.0.26a-1 && [ "$2" != "${2%ubuntu*}" ]
	then
		base=dapper
	elif [ "$2" != "${2%ubuntu*}" ]
	then
		base=gutsy
	else
		base=etch
	fi

	TEMPLATE=/usr/share/samba/smb.conf.${base}

	cp "$TEMPLATE" "$NEWFILE"
	configure_smb_conf "$NEWFILE"

	if [ -e "$CONFIG" ]; then
		sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
			1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
		' "$CONFIG" >> "$NEWFILE"
	fi

	ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
fi

cp /usr/share/samba/smb.conf "$NEWFILE"
configure_smb_conf "$NEWFILE"

if [ -e "$CONFIG" ]; then
	sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
		1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
	' "$CONFIG" >> "$NEWFILE"
fi

ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"

if [ ! -e "$CONFIG" ]; then
	echo "Install/upgrade will fail. To recover, please try:"
	echo "  sudo cp /usr/share/samba/smb.conf $CONFIG"
	echo "  sudo dpkg --configure -a"
	exit 1
else
	ucfr samba-common "$CONFIG"
	chmod a+r "$CONFIG"
fi

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

db_stop

#DEBHELPER#