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 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU 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, see <http://www.gnu.org/licenses/>.
22 while [ $# -gt 0 ]; do
30 scripts/setup [OPTIONS]
33 --root ROOT Add a root (can be used multiple times)
34 --encoding ENCODING Filename encoding
35 --port PORT TCP port to listen on or 'none'
36 --smtp-server HOSTNAME SMTP server
37 --email ADDRESS Origin email address
38 --register y|n Enable/disable online registration
39 --play local|network Choose local or network play
40 --mcast ADDRESS PORT Set multicast address and port for --play network
41 -h, --help Display this message
43 Sets up a basic DisOrder installation. You must have run 'make install'
44 first. Use scripts/teardown to stop the server and deconfigure.
50 echo "DisOrder scripts/setup _version_"
89 echo >&2 "ERROR: unknown option '$opt'"
96 echo ------------------------------------------------------------------------
97 echo "DisOrder setup script"
101 echo "Mac OS X detected"
107 echo "FreeBSD detected"
113 if grep Debian /etc/issue >/dev/null 2>&1; then
114 echo "You appear to be running Debian - please use .debs instead"
116 elif grep Ubuntu /etc/issue >/dev/null 2>&1; then
117 echo "You appear to be running Ubuntu - please use .debs instead"
120 echo "Linux detected"
127 echo "WARNING: unknown operating system '$(uname -s)'"
128 echo "This script won't be able to do all setup on this platform"
136 echo "This script will:"
137 echo " - overwrite any existing configuration"
138 echo " - set the server up to be run at boot time"
139 echo " - start the server"
140 echo " - set up the web interface"
142 echo "If this is not what you want, press ^C."
143 echo ------------------------------------------------------------------------
145 if [ -z "$roots" ]; then
148 echo "What directory or directories contain your music files:"
149 echo "(enter one or more directories separated by spaces)"
153 for root in $roots; do
154 if [ ! -d $root ]; then
155 echo "'$root' does not exist"
161 if $anyroots && $ok; then
167 if [ -z "$encoding" ]; then
170 echo "What filesystem encoding should I assume for track names?"
171 echo "(e.g. UTF-8, ISO-8859-1, ...)"
173 if [ ! -z "$encoding" ]; then
179 if [ -z "$port" ]; then
182 echo "What TCP port should DisOrder listen on?"
183 echo "(enter 'none' for none)"
190 echo "'$port' is not a valid port number"
200 if [ -z "$play" ]; then
203 echo "How do you want to play sound? Enter 'local' to use a local sound"
204 echo "device or 'network' to multicast sound across your network."
211 echo "Enter 'local' or 'network'"
218 if [ "x$play" = xnetwork ]; then
219 if [ -z "$mcast_address" ]; then
221 echo "Enter destination address for network transmission"
222 echo "(e.g. a multicast address)"
223 read -r mcast_address
225 if [ -z "$mcast_port" ]; then
228 echo "Enter destination port for network transmission"
235 echo "'$mcast_port' is not a valid port number"
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 if [ ! -z "$smtp_server" ]; then
284 echo " SMTP Server: $smtp_server"
286 echo " Sender address: $mail_sender"
287 echo " Online registration: $register"
288 if [ $play = network ]; then
289 echo " Send sound to: $mcast_address port $mcast_port"
292 echo "Is this OK? (Enter 'y' or 'n')"
299 echo "OK, didn't change anything."
306 rm -f pkgconfdir/config.new
307 for root in $roots; do
308 echo "collection fs $encoding $root" >> pkgconfdir/config.new
310 for scratch in slap.ogg scratch.ogg; do
311 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
313 echo "user $user" >> pkgconfdir/config.new
314 if [ $port != none ]; then
315 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
317 if [ $play = network ]; then
318 echo "broadcast $mcast_address $mcast_port" >> pkgconfdir/config.new
320 if [ ! -z "$smtp_server" ]; then
321 echo "smtp_server $smtp_server" >> pkgconfdir/config.new
323 echo "mail_sender $mail_sender" >> pkgconfdir/config.new
326 echo "Proposed pkgconfdir/config:"
327 sed < pkgconfdir/config.new 's/^/ /'
329 echo "Is this OK? (Enter 'y' or 'n')"
336 echo "OK, not installing it."
337 rm -f pkgconfdir/config.new
342 echo "Installing pkgconfdir/config"
343 mv pkgconfdir/config.new pkgconfdir/config
345 if [ ! -f pkgconfdir/options.user ]; then
346 echo "Making sure pkgconfdir/options.user exists"
347 touch pkgconfdir/options.user
350 # pick ID1 ID2 ... IDn
351 # Echoes an ID matching none of ID1..IDn
354 n=250 # better not choose 0!
373 # Apple don't seem to believe in creating a user as a discrete operation
374 if dscl . -read /Groups/$group >/dev/null 2>&1; then
375 echo "$group group already exists"
377 echo "Creating $group group"
378 gids=$(dscl . -list /Groups PrimaryGroupID|awk '{print $2}')
380 echo "(picked gid $gid)"
381 dscl . -create /Groups/$group
382 dscl . -create /Groups/$group PrimaryGroupID $gid
383 dscl . -create /Groups/$group Password \*
385 if dscl . -read /Users/$user >/dev/null 2>&1; then
386 echo "$user user already exists"
388 echo "Creating $user user"
389 uids=$(dscl . -list /Users UniqueID|awk '{print $2}')
391 echo "(picked uid $uid)"
392 gid=$(dscl . -read /Groups/$group PrimaryGroupID | awk '{print $2}')
393 dscl . -create /Users/$user
394 dscl . -create /Users/$user UniqueID $uid
395 dscl . -create /Users/$user UserShell /usr/bin/false
396 dscl . -create /Users/$user RealName 'DisOrder server'
397 dscl . -create /Users/$user NFSHomeDirectory pkgstatedir
398 dscl . -create /Users/$user PrimaryGroupID $gid
399 dscl . -create /Users/$user Password \*
403 # FreeBSD has a simple well-documented interface
404 if pw groupshow $group >/dev/null 2>&1; then
405 echo "$group group already exists"
407 echo "Creating $group group"
410 if pw usershow $user >/dev/null 2>&1; then
411 echo "$user user already exists"
413 echo "Creating $user user"
414 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
418 if grep ^$group: /etc/group >/dev/null; then
419 echo "$group group already exists"
421 echo "Creating $group group"
424 if grep ^$user: /etc/passwd >/dev/null; then
425 echo "$user user already exists"
427 echo "Creating $user user"
428 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
433 echo "Making sure that pkgstatedir exists"
435 chown $user:$group pkgstatedir
436 chmod 2755 pkgstatedir
440 echo "Installing the plist into /Library/LaunchDaemons"
441 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
442 echo "Reloading launchd"
443 launchctl load /Library/LaunchDaemons
444 echo "Starting DisOrder server"
445 launchctl start uk.org.greenend.rjk.disorder
449 echo "Installing startup script into /etc/rc.d"
450 install -m 555 examples/disorder.rc /etc/rc.d/disorder
451 echo "Starting DisOrder server"
452 /etc/rc.d/disorder start
456 echo "Looking for init scripts directory"
457 for d in /etc/rc.d /etc; do
458 if [ -d $d/init.d ]; then
463 if [ -z "$RC_D" ]; then
464 echo "Cannot find your init scripts directory"
466 echo "Installing init script into $RC_D/init.d"
467 install -m 755 examples/disorder.init $RC_D/init.d/disorder
468 echo "Linking init script into $RC_D/rc*.d"
470 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
471 rm -f $RC_D/rc$n.d/S99disorder
472 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/S99disorder
475 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
476 rm -f $RC_D/rc$n.d/K01disorder
477 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/K01disorder
479 echo "Starting DisOrder server"
480 $RC_D/init.d/disorder start
486 echo "Sorry, I don't know how to install the server on this platform."
487 echo "You will have to do that by hand."
492 if $server_running; then
495 while ! disorder version >/dev/null 2>&1; do
497 echo "Waiting for server startup to complete..."
502 if [ $register = y ]; then
503 echo "Creating guest user with 'register' right"
506 echo "Creating guest user without 'register' right"
507 disorder setup-guest --no-online-registration