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
"$smtp_server" ]; then
242 echo "What host should DisOrder use as an SMTP server?"
246 if [ -z
"$mail_sender" ]; then
249 echo "What address should mail from DisOrder come from?"
251 case "$mail_sender" in
256 echo "Email address must contain an '@' sign"
262 if [ -z
"$register" ]; then
265 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
276 echo "Proposed DisOrder setup:"
277 echo " Music directory: $roots"
278 if [ $port = none
]; then
279 echo " Do not listen on a TCP port"
281 echo " TCP port to listen on: $port"
283 echo " SMTP Server: $smtp_server"
284 echo " Sender address: $mail_sender"
285 echo " Online registration: $register"
286 if [ $play = network
]; then
287 echo " Send sound to: $mcast_address port $mcast_port"
290 echo "Is this OK? (Enter 'y' or 'n')"
297 echo "OK, didn't change anything."
304 rm -f pkgconfdir
/config.new
305 for root
in $roots; do
306 echo "collection fs $encoding $root" >> pkgconfdir
/config.new
308 for scratch
in slap.ogg scratch.ogg
; do
309 echo "scratch pkgdatadir/$scratch" >> pkgconfdir
/config.new
311 echo "user $user" >> pkgconfdir
/config.new
312 if [ $port != none
]; then
313 echo "listen 0.0.0.0 $port" >> pkgconfdir
/config.new
315 if [ $play = network
]; then
316 echo "broadcast $mcast_address $mcast_port" >> pkgconfdir
/config.new
318 echo "smtp_server $smtp_server" >> pkgconfdir
/config.new
319 echo "mail_sender $mail_sender" >> pkgconfdir
/config.new
322 echo "Proposed pkgconfdir/config:"
323 sed < pkgconfdir
/config.new
's/^/ /'
325 echo "Is this OK? (Enter 'y' or 'n')"
332 echo "OK, not installing it."
333 rm -f pkgconfdir
/config.new
338 echo "Installing pkgconfdir/config"
339 mv pkgconfdir
/config.new pkgconfdir
/config
341 if [ ! -f pkgconfdir
/options.user
]; then
342 echo "Making sure pkgconfdir/options.user exists"
343 touch pkgconfdir
/options.user
346 # pick ID1 ID2 ... IDn
347 # Echoes an ID matching none of ID1..IDn
350 n
=250 # better not choose 0!
369 # Apple don't seem to believe in creating a user as a discrete operation
370 if dscl .
-read /Groups
/$group >/dev
/null
2>&1; then
371 echo "$group group already exists"
373 echo "Creating $group group"
374 gids
=$
(dscl .
-list
/Groups PrimaryGroupID|
awk '{print $2}')
376 echo "(picked gid $gid)"
377 dscl .
-create
/Groups
/$group
378 dscl .
-create
/Groups
/$group PrimaryGroupID
$gid
379 dscl .
-create
/Groups
/$group Password \
*
381 if dscl .
-read /Users
/$user >/dev
/null
2>&1; then
382 echo "$user user already exists"
384 echo "Creating $user user"
385 uids
=$
(dscl .
-list
/Users UniqueID|
awk '{print $2}')
387 echo "(picked uid $uid)"
388 gid
=$
(dscl .
-read /Groups
/$group PrimaryGroupID |
awk '{print $2}')
389 dscl .
-create
/Users
/$user
390 dscl .
-create
/Users
/$user UniqueID
$uid
391 dscl .
-create
/Users
/$user UserShell
/usr
/bin
/false
392 dscl .
-create
/Users
/$user RealName
'DisOrder server'
393 dscl .
-create
/Users
/$user NFSHomeDirectory pkgstatedir
394 dscl .
-create
/Users
/$user PrimaryGroupID
$gid
395 dscl .
-create
/Users
/$user Password \
*
399 # FreeBSD has a simple well-documented interface
400 if pw groupshow
$group >/dev
/null
2>&1; then
401 echo "$group group already exists"
403 echo "Creating $group group"
406 if pw usershow
$user >/dev
/null
2>&1; then
407 echo "$user user already exists"
409 echo "Creating $user user"
410 pw useradd
$user -w no
-d pkgstatedir
-g
$group -c
'DisOrder user'
414 if grep ^
$group: /etc
/group
>/dev
/null
; then
415 echo "$group group already exists"
417 echo "Creating $group group"
420 if grep ^
$user: /etc
/passwd
>/dev
/null
; then
421 echo "$user user already exists"
423 echo "Creating $user user"
424 useradd
-d pkgstatedir
-g
$group $user -c
'DisOrder user'
429 echo "Making sure that pkgstatedir exists"
431 chown
$user:$group pkgstatedir
432 chmod 2755 pkgstatedir
436 echo "Installing the plist into /Library/LaunchDaemons"
437 cp examples
/uk.org.greenend.rjk.disorder.plist
/Library
/LaunchDaemons
/.
438 echo "Reloading launchd"
439 launchctl load
/Library
/LaunchDaemons
440 echo "Starting DisOrder server"
441 launchctl start uk.org.greenend.rjk.disorder
442 CGIBIN
=/Library
/WebServer
/CGI-Executables
443 DOCROOT
=/Library
/WebServer
/Documents
447 echo "Installing startup script into /etc/rc.d"
448 install -m
555 examples
/disorder.rc
/etc
/rc.d
/disorder
449 echo "Starting DisOrder server"
450 /etc
/rc.d
/disorder start
451 echo "Identifying web server"
456 echo "Could not find a web server"
463 echo "Yikes! There seems to be more than one web server here."
464 echo "Guessing that you want $1."
475 echo "Looking for init scripts directory"
476 for d
in /etc
/rc.d
/etc
; do
477 if [ -d
$d/init.d
]; then
482 if [ -z
"$RC_D" ]; then
483 echo "Cannot find your init scripts directory"
485 echo "Installing init script into $RC_D/init.d"
486 install -m
755 examples
/disorder.init
$RC_D/init.d
/disorder
487 echo "Linking init script into $RC_D/rc*.d"
489 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
490 rm -f
$RC_D/rc
$n.d
/S99disorder
491 ln -s
$RC_D/init.d
/disorder
$RC_D/rc
$n.d
/S99disorder
494 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
495 rm -f
$RC_D/rc
$n.d
/K01disorder
496 ln -s
$RC_D/init.d
/disorder
$RC_D/rc
$n.d
/K01disorder
498 echo "Starting DisOrder server"
499 $RC_D/init.d
/disorder start
501 echo "Looking for web server document root"
502 for d
in /var
/www
/html
/var
/www
; do
508 echo "Looking for cgi-bin directory"
509 for d
in /var
/www
/cgi-bin
/usr
/lib
/cgi-bin
; do
519 echo "Sorry, I don't know how to install the server on this platform."
520 echo "You will have to do that by hand."
526 if [ -z
"$DOCROOT" ]; then
527 echo "Cannot find your web server's document root"
529 echo "Setting up link to CGI's dependencies in $DOCROOT"
530 rm -f
$DOCROOT/disorder
531 ln -s pkgdatadir
/static
$DOCROOT/disorder
535 if [ -z
"$CGIBIN" ]; then
536 echo "Cannot find your web server's cgi-bin directory"
538 echo "Installing CGI in $CGIBIN"
539 install -m
555 server
/disorder.cgi
$CGIBIN/disorder
542 if $server_running; then
545 while ! disorder version
>/dev
/null
2>&1; do
547 echo "Waiting for server startup to complete..."
552 if [ $register = y
]; then
553 echo "Creating guest user with 'register' right"
556 echo "Creating guest user without 'register' right"
557 disorder setup-guest
--no-online-registration