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)"
155 for root in $roots; do
156 if [ ! -d $root ]; then
157 echo "'$root' does not exist"
163 if $anyroots && $ok; then
169 if [ -z "$encoding" ]; then
172 echo "What filesystem encoding should I assume for track names?"
173 echo "(e.g. UTF-8, ISO-8859-1, ...)"
175 if [ ! -z "$encoding" ]; then
181 if [ -z "$port" ]; then
184 echo "What TCP port should DisOrder listen on?"
185 echo "(enter 'none' for none)"
192 echo "'$port' is not a valid port number"
202 if [ -z "$play" ]; then
205 echo "How do you want to play sound? Enter 'local' to use a local sound"
206 echo "device or 'network' to multicast sound across your network."
213 echo "Enter 'local' or 'network'"
220 if [ "x$play" = xnetwork ]; then
221 if [ -z "$mcast_address" ]; then
223 echo "Enter destination address for network transmission"
224 echo "(e.g. a multicast address)"
225 read -r mcast_address
227 if [ -z "$mcast_port" ]; then
230 echo "Enter destination port for network transmission"
237 echo "'$mcast_port' is not a valid port number"
248 if [ -z "$mail_sender" ]; then
251 echo "What address should mail from DisOrder come from?"
253 case "$mail_sender" in
258 echo "Email address must contain an '@' sign"
264 if [ -z "$register" ]; then
267 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
278 echo "Proposed DisOrder setup:"
279 echo " Music directory: $roots"
280 if [ "$port" = none ]; then
281 echo " Do not listen on a TCP port"
283 echo " TCP port to listen on: $port"
285 if [ ! -z "$smtp_server" ]; then
286 echo " SMTP Server: $smtp_server"
288 echo " Sender address: $mail_sender"
289 echo " Online registration: $register"
290 if [ $play = network ]; then
291 echo " Send sound to: $mcast_address port $mcast_port"
294 echo "Is this OK? (Enter 'y' or 'n')"
301 echo "OK, didn't change anything."
308 rm -f pkgconfdir/config.new
309 for root in $roots; do
310 echo "collection fs $encoding $root" >> pkgconfdir/config.new
312 for scratch in slap.ogg scratch.ogg; do
313 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
315 echo "user $user" >> pkgconfdir/config.new
316 if [ $port != none ]; then
317 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
319 if [ $play = network ]; then
320 echo "broadcast $mcast_address $mcast_port" >> pkgconfdir/config.new
322 if [ ! -z "$smtp_server" ]; then
323 echo "smtp_server $smtp_server" >> pkgconfdir/config.new
325 echo "mail_sender $mail_sender" >> pkgconfdir/config.new
328 echo "Proposed pkgconfdir/config:"
329 sed < pkgconfdir/config.new 's/^/ /'
331 echo "Is this OK? (Enter 'y' or 'n')"
338 echo "OK, not installing it."
339 rm -f pkgconfdir/config.new
344 echo "Installing pkgconfdir/config"
345 mv pkgconfdir/config.new pkgconfdir/config
347 if [ ! -f pkgconfdir/options.user ]; then
348 echo "Making sure pkgconfdir/options.user exists"
349 touch pkgconfdir/options.user
352 # pick ID1 ID2 ... IDn
353 # Echoes an ID matching none of ID1..IDn
356 n=250 # better not choose 0!
375 # Apple don't seem to believe in creating a user as a discrete operation
376 if dscl . -read /Groups/$group >/dev/null 2>&1; then
377 echo "$group group already exists"
379 echo "Creating $group group"
380 gids=$(dscl . -list /Groups PrimaryGroupID|awk '{print $2}')
382 echo "(picked gid $gid)"
383 dscl . -create /Groups/$group
384 dscl . -create /Groups/$group PrimaryGroupID $gid
385 dscl . -create /Groups/$group Password \*
387 if dscl . -read /Users/$user >/dev/null 2>&1; then
388 echo "$user user already exists"
390 echo "Creating $user user"
391 uids=$(dscl . -list /Users UniqueID|awk '{print $2}')
393 echo "(picked uid $uid)"
394 gid=$(dscl . -read /Groups/$group PrimaryGroupID | awk '{print $2}')
395 dscl . -create /Users/$user
396 dscl . -create /Users/$user UniqueID $uid
397 dscl . -create /Users/$user UserShell /usr/bin/false
398 dscl . -create /Users/$user RealName 'DisOrder server'
399 dscl . -create /Users/$user NFSHomeDirectory pkgstatedir
400 dscl . -create /Users/$user PrimaryGroupID $gid
401 dscl . -create /Users/$user Password \*
405 # FreeBSD has a simple well-documented interface
406 if pw groupshow $group >/dev/null 2>&1; then
407 echo "$group group already exists"
409 echo "Creating $group group"
412 if pw usershow $user >/dev/null 2>&1; then
413 echo "$user user already exists"
415 echo "Creating $user user"
416 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
420 if grep ^$group: /etc/group >/dev/null; then
421 echo "$group group already exists"
423 echo "Creating $group group"
426 if grep ^$user: /etc/passwd >/dev/null; then
427 echo "$user user already exists"
429 echo "Creating $user user"
430 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
435 echo "Making sure that pkgstatedir exists"
437 chown $user:$group pkgstatedir
438 chmod 2755 pkgstatedir
442 echo "Installing the plist into /Library/LaunchDaemons"
443 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
444 echo "Reloading launchd"
445 launchctl load /Library/LaunchDaemons
446 echo "Starting DisOrder server"
447 launchctl start uk.org.greenend.rjk.disorder
451 echo "Installing startup script into /etc/rc.d"
452 install -m 555 examples/disorder.rc /etc/rc.d/disorder
453 echo "Starting DisOrder server"
454 /etc/rc.d/disorder start
458 echo "Looking for init scripts directory"
459 for d in /etc/rc.d /etc; do
460 if [ -d $d/init.d ]; then
465 if [ -z "$RC_D" ]; then
466 echo "Cannot find your init scripts directory"
468 echo "Installing init script into $RC_D/init.d"
469 install -m 755 examples/disorder.init $RC_D/init.d/disorder
470 echo "Linking init script into $RC_D/rc*.d"
472 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
473 rm -f $RC_D/rc$n.d/S99disorder
474 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/S99disorder
477 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
478 rm -f $RC_D/rc$n.d/K01disorder
479 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/K01disorder
481 echo "Starting DisOrder server"
482 $RC_D/init.d/disorder start
488 echo "Sorry, I don't know how to install the server on this platform."
489 echo "You will have to do that by hand."
494 if $server_running; then
497 while ! disorder version >/dev/null 2>&1; do
499 echo "Waiting for server startup to complete..."
504 if [ $register = y ]; then
505 echo "Creating guest user with 'register' right"
508 echo "Creating guest user without 'register' right"
509 disorder setup-guest --no-online-registration