summaryrefslogtreecommitdiff
path: root/packaging/Debian/debian/sambaconfig
blob: 0d35a51967074a91fd457582342251b9f34e2a6b (plain)
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
#!/bin/sh
#
#	Written by Eloy A. Paris <peloy@debian.org> for Debian GNU/Linux.
#

PATH="/usr/sbin:/usr/bin:/sbin:/bin"
DEBIAN_CONFIG=/etc/samba/debian_config

NMBDPID=/var/state/samba/nmbd.pid
SMBDPID=/var/state/samba/smbd.pid

if [ ! -f $DEBIAN_CONFIG ]; then
	echo "The file $DEBIAN_CONFIG does not exist! There is something wrong"
	echo "with the installation of Samba on this system. Please re-install"
	echo "Samba."
	exit 1
fi

# Read current Samba configuration
. $DEBIAN_CONFIG

reload=1

while [ $# -gt 0 ]
do
	case "$1" in
		--run-from-inetd)
			run_from_inetd=1
			shift
		;;

		--run-as-daemons)
			run_from_inetd=0
			shift
		;;
		--no-reload)
			reload=0
			shift
		;;

		*)
			echo "Usage: $0 [--run-from-inetd|--run-as-daemons] [no-reload]" >&2
			exit 1
		;;
	esac
done

# Make sure there are no Samba daemons (nmbd or smbd) running
#

if [ "$run_mode" = "from_inetd" ]; then
	# Samba is running from inetd - need to disable inetd before
	#	killing the daemons.
	update-inetd --disable netbios-ssn
	update-inetd --disable netbios-ns
	start-stop-daemon --stop --oknodo --user root --name nmbd --quiet --pidfile $NMBDPID
	start-stop-daemon --stop --oknodo --user root --name smbd --quiet --pidfile $SMBDPID
else
	# Samba is running as daemons
	/etc/init.d/samba stop
fi

if [ "x$run_from_inetd" = "x" ]
then
	echo "Run Samba as daemons or from inetd?"
	echo -n "Press 'D' for to run as daemons or 'I' to run from inetd: [I] "

	read mode
	test -n "$mode" || mode="I"

	case "$mode" in
		[Dd]*)
			run_from_inetd=0
		;;

		*)
			run_from_inetd=1
		;;
	esac
fi

if [ "$run_from_inetd" = 1 ]; then
	echo "Samba will run from inetd. Run sambaconfig to reconfigure."
	echo ""
	update-inetd --enable netbios-ssn
	update-inetd --enable netbios-ns
	run_mode="from_inetd"
else
	echo "Samba will run as daemons. Run sambaconfig to reconfigure."
	echo ""
	update-inetd --disable netbios-ssn
	update-inetd --disable netbios-ns
	run_mode="as_daemons"
fi

# Rebuild Debian configuration file (only thing that could have
#	changed so far is the variable called "run_mode".

# Start the Samba daemons (take care of whether the user used the --no-reload
#	option and how Samba is running: from inetd or as daemons)
echo "config_version=$config_version" > $DEBIAN_CONFIG
echo "run_mode=$run_mode" >> $DEBIAN_CONFIG
echo "smbpasswd_created=$smbpasswd_created" >> $DEBIAN_CONFIG

if [ "$reload" = 0 ]; then
	echo "Samba will not start (--no-reload parameter provided). Please note"
	echo "that if you configured Samba to run from inetd, the Samba daemons"
	echo "will start automatically when there is traffic in the NetBIOS ports"
elif [ "$run_from_inetd" = 1 ]; then
	echo "The --no-reload parameter was not provided so I assume you want"
	echo "to have the Samba daemons started. Since you are running from inetd"
	echo "the Samba daemosn will start automatically when there is traffic"
	echo "in the NetBIOS ports."
else
	echo -n "The --no-reload parameter was not provided, start Samba now? [Y/n] "
	read yn
	test -n "$yn" || yn="Y"

	case "$yn" in
		[Nn]*)
			echo "Not started; to start later, do: /etc/init.d/samba start"
			echo -n "Press [ENTER] "
			read line
		;;

		*)
			/etc/init.d/samba start
		;;
	esac
fi