3 # This file is part of DisOrder
4 # Copyright (C) 2008 Richard Kettlewell
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 while [ $# -gt
0 ]; do
32 scripts/setup [OPTIONS]
35 --root ROOT Add a root (can be used multiple times)
36 --encoding ENCODING Filename encoding
37 --port PORT TCP port to listen on or 'none'
38 --smtp-server HOSTNAME SMTP server
39 --email ADDRESS Origin email address
40 --register y|n Enable/disable online registration
41 --play local|network Choose local or network play
42 --mcast ADDRESS PORT Set multicast address and port for --play network
43 -h, --help Display this message
45 Sets up a basic DisOrder installation. You must have run 'make install'
46 first. Use scripts/teardown to stop the server and deconfigure.
52 echo "DisOrder scripts/setup _version_"
91 echo >&2 "ERROR: unknown option '$opt'"
98 echo ------------------------------------------------------------------------
99 echo "DisOrder setup script"
103 echo "Mac OS X detected"
109 echo "FreeBSD detected"
115 if grep Debian
/etc
/issue
>/dev
/null
2>&1; then
116 echo "You appear to be running Debian - please use .debs instead"
118 elif grep Ubuntu
/etc
/issue
>/dev
/null
2>&1; then
119 echo "You appear to be running Ubuntu - please use .debs instead"
122 echo "Linux detected"
129 echo "WARNING: unknown operating system '$(uname -s)'"
130 echo "This script won't be able to do all setup on this platform"
138 echo "This script will:"
139 echo " - overwrite any existing configuration"
140 echo " - set the server up to be run at boot time"
141 echo " - start the server"
142 echo " - set up the web interface"
144 echo "If this is not what you want, press ^C."
145 echo ------------------------------------------------------------------------
147 if [ -z
"$roots" ]; then
150 echo "What directory or directories contain your music files:"
151 echo "(enter one or more directories separated by spaces)"
154 for root
in $roots; do
155 if [ ! -d
$root ]; then
156 echo "'$root' does not exist"
166 if [ -z
"$encoding" ]; then
168 echo "What filesystem encoding should I assume for track names?"
169 echo "(e.g. UTF-8, ISO-8859-1, ...)"
173 if [ -z
"$port" ]; then
176 echo "What TCP port should DisOrder listen on?"
177 echo "(enter 'none' for none)"
184 echo "'$port' is not a valid port number"
194 if [ -z
"$play" ]; then
197 echo "How do you want to play sound? Enter 'local' to use a local sound"
198 echo "device or 'network' to multicast sound across your network."
205 echo "Enter 'local' or 'network'"
212 if [ "x$play" = xnetwork
]; then
213 if [ -z
"$mcast_address" ]; then
215 echo "Enter destination address for network transmission"
216 echo "(e.g. a multicast address)"
217 read -r mcast_address
219 if [ -z
"$mcast_port" ]; then
222 echo "Enter destination port for network transmission"
229 echo "'$mcast_port' is not a valid port number"
240 if [ -z
"$mail_sender" ]; then
243 echo "What address should mail from DisOrder come from?"
245 case "$mail_sender" in
250 echo "Email address must contain an '@' sign"
256 if [ -z
"$register" ]; then
259 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
270 echo "Proposed DisOrder setup:"
271 echo " Music directory: $roots"
272 if [ $port = none
]; then
273 echo " Do not listen on a TCP port"
275 echo " TCP port to listen on: $port"
277 if [ ! -z
"$smtp_server" ]; then
278 echo " SMTP Server: $smtp_server"
280 echo " Sender address: $mail_sender"
281 echo " Online registration: $register"
282 if [ $play = network
]; then
283 echo " Send sound to: $mcast_address port $mcast_port"
286 echo "Is this OK? (Enter 'y' or 'n')"
293 echo "OK, didn't change anything."
300 rm -f pkgconfdir
/config.new
301 for root
in $roots; do
302 echo "collection fs $encoding $root" >> pkgconfdir
/config.new
304 for scratch
in slap.ogg scratch.ogg
; do
305 echo "scratch pkgdatadir/$scratch" >> pkgconfdir
/config.new
307 echo "user $user" >> pkgconfdir
/config.new
308 if [ $port != none
]; then
309 echo "listen 0.0.0.0 $port" >> pkgconfdir
/config.new
311 if [ $play = network
]; then
312 echo "broadcast $mcast_address $mcast_port" >> pkgconfdir
/config.new
314 if [ ! -z
"$smtp_server" ]; then
315 echo "smtp_server $smtp_server" >> pkgconfdir
/config.new
317 echo "mail_sender $mail_sender" >> pkgconfdir
/config.new
320 echo "Proposed pkgconfdir/config:"
321 sed < pkgconfdir
/config.new
's/^/ /'
323 echo "Is this OK? (Enter 'y' or 'n')"
330 echo "OK, not installing it."
331 rm -f pkgconfdir
/config.new
336 echo "Installing pkgconfdir/config"
337 mv pkgconfdir
/config.new pkgconfdir
/config
339 if [ ! -f pkgconfdir
/options.user
]; then
340 echo "Making sure pkgconfdir/options.user exists"
341 touch pkgconfdir
/options.user
344 # pick ID1 ID2 ... IDn
345 # Echoes an ID matching none of ID1..IDn
348 n
=250 # better not choose 0!
367 # Apple don't seem to believe in creating a user as a discrete operation
368 if dscl .
-read /Groups
/$group >/dev
/null
2>&1; then
369 echo "$group group already exists"
371 echo "Creating $group group"
372 gids
=$
(dscl .
-list
/Groups PrimaryGroupID|
awk '{print $2}')
374 echo "(picked gid $gid)"
375 dscl .
-create
/Groups
/$group
376 dscl .
-create
/Groups
/$group PrimaryGroupID
$gid
377 dscl .
-create
/Groups
/$group Password \
*
379 if dscl .
-read /Users
/$user >/dev
/null
2>&1; then
380 echo "$user user already exists"
382 echo "Creating $user user"
383 uids
=$
(dscl .
-list
/Users UniqueID|
awk '{print $2}')
385 echo "(picked uid $uid)"
386 gid
=$
(dscl .
-read /Groups
/$group PrimaryGroupID |
awk '{print $2}')
387 dscl .
-create
/Users
/$user
388 dscl .
-create
/Users
/$user UniqueID
$uid
389 dscl .
-create
/Users
/$user UserShell
/usr
/bin
/false
390 dscl .
-create
/Users
/$user RealName
'DisOrder server'
391 dscl .
-create
/Users
/$user NFSHomeDirectory pkgstatedir
392 dscl .
-create
/Users
/$user PrimaryGroupID
$gid
393 dscl .
-create
/Users
/$user Password \
*
397 # FreeBSD has a simple well-documented interface
398 if pw groupshow
$group >/dev
/null
2>&1; then
399 echo "$group group already exists"
401 echo "Creating $group group"
404 if pw usershow
$user >/dev
/null
2>&1; then
405 echo "$user user already exists"
407 echo "Creating $user user"
408 pw useradd
$user -w no
-d pkgstatedir
-g
$group -c
'DisOrder user'
412 if grep ^
$group: /etc
/group
>/dev
/null
; then
413 echo "$group group already exists"
415 echo "Creating $group group"
418 if grep ^
$user: /etc
/passwd
>/dev
/null
; then
419 echo "$user user already exists"
421 echo "Creating $user user"
422 useradd
-d pkgstatedir
-g
$group $user -c
'DisOrder user'
427 echo "Making sure that pkgstatedir exists"
429 chown
$user:$group pkgstatedir
430 chmod 2755 pkgstatedir
434 echo "Installing the plist into /Library/LaunchDaemons"
435 cp examples
/uk.org.greenend.rjk.disorder.plist
/Library
/LaunchDaemons
/.
436 echo "Reloading launchd"
437 launchctl load
/Library
/LaunchDaemons
438 echo "Starting DisOrder server"
439 launchctl start uk.org.greenend.rjk.disorder
443 echo "Installing startup script into /etc/rc.d"
444 install -m
555 examples
/disorder.rc
/etc
/rc.d
/disorder
445 echo "Starting DisOrder server"
446 /etc
/rc.d
/disorder start
450 echo "Looking for init scripts directory"
451 for d
in /etc
/rc.d
/etc
; do
452 if [ -d
$d/init.d
]; then
457 if [ -z
"$RC_D" ]; then
458 echo "Cannot find your init scripts directory"
460 echo "Installing init script into $RC_D/init.d"
461 install -m
755 examples
/disorder.init
$RC_D/init.d
/disorder
462 echo "Linking init script into $RC_D/rc*.d"
464 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
465 rm -f
$RC_D/rc
$n.d
/S99disorder
466 ln -s
$RC_D/init.d
/disorder
$RC_D/rc
$n.d
/S99disorder
469 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
470 rm -f
$RC_D/rc
$n.d
/K01disorder
471 ln -s
$RC_D/init.d
/disorder
$RC_D/rc
$n.d
/K01disorder
473 echo "Starting DisOrder server"
474 $RC_D/init.d
/disorder start
480 echo "Sorry, I don't know how to install the server on this platform."
481 echo "You will have to do that by hand."
486 if $server_running; then
489 while ! disorder version
>/dev
/null
2>&1; do
491 echo "Waiting for server startup to complete..."
496 if [ $register = y
]; then
497 echo "Creating guest user with 'register' right"
500 echo "Creating guest user without 'register' right"
501 disorder setup-guest
--no-online-registration