File: samba-common.postinst

package info (click to toggle)
samba 2%3A4.5.16%2Bdfsg-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 119,272 kB
  • sloc: ansic: 1,353,805; xml: 120,204; python: 119,437; sh: 36,510; perl: 29,946; asm: 3,281; yacc: 2,332; cpp: 2,225; ada: 1,681; exp: 1,582; makefile: 1,365; pascal: 1,089; cs: 879; lex: 603; awk: 118; csh: 58; sed: 45
file content (108 lines) | stat: -rw-r--r-- 2,708 bytes parent folder | download | duplicates (5)
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
#!/bin/sh
#
#

set -e

# 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"

	# 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 [ -e "$CONFIG" ]; then
	configure_smb_conf "$CONFIG"
fi

mkdir -p "$TEMPDIR"

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"
else
	ucfr samba-common "$CONFIG"
	chmod a+r "$CONFIG"
fi

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

db_stop

#DEBHELPER#

# Clean up the now-empty dir which our conffile was previously in,
# since it wasn't empty at the time dpkg could automatically remove it
# for us.
if dpkg --compare-versions "$2" lt-nl 2:4.1.4+dfsg-2~
then
	rmdir -p --ignore-fail-on-non-empty /etc/dhcp3/dhclient-enter-hooks.d
fi