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
31 scripts/setup [OPTIONS]
34 --root ROOT Add a root (can be used multiple times)
35 --encoding ENCODING Filename encoding
36 --port PORT TCP port to listen on or 'none'
37 --smtp-server HOSTNAME SMTP server
38 --email ADDRESS Origin email address
39 --register y|n Enable/disable online registration
40 -h, --help Display this message
69 echo >&2 "ERROR: unknown option '$opt'"
76 echo ------------------------------------------------------------------------
77 echo "DisOrder setup script"
81 echo "Mac OS X detected"
87 echo "FreeBSD detected"
93 if grep Debian /etc/issue >/dev/null 2>&1; then
94 echo "You appear to be running Debian - please use .debs instead"
96 elif grep Ubuntu /etc/issue >/dev/null 2>&1; then
97 echo "You appear to be running Ubuntu - please use .debs instead"
100 echo "Linux detected"
107 echo "WARNING: unknown operating system '$(uname -s)'"
108 echo "This script won't be able to do all setup on this platform"
116 echo "This script will:"
117 echo " - overwrite any existing configuration"
118 echo " - set the server up to be run at boot time"
119 echo " - start the server"
120 echo " - set up the web interface"
122 echo "If this is not what you want, press ^C."
123 echo ------------------------------------------------------------------------
125 if [ -z "$roots" ]; then
128 echo "What directory or directories contain your music files:"
129 echo "(enter one or more directories separated by spaces)"
132 for root in $roots; do
133 if [ ! -d $root ]; then
134 echo "'$root' does not exist"
144 if [ -z "$encoding" ]; then
146 echo "What filesystem encoding should I assume for track names?"
147 echo "(e.g. UTF-8, ISO-8859-1, ...)"
151 if [ -z "$port" ]; then
154 echo "What TCP port should DisOrder listen on?"
155 echo "(enter 'none' for none)"
162 echo "'$port' is not a valid port number"
172 if [ -z "$smtp_server" ]; then
174 echo "What host should DisOrder use as an SMTP server?"
178 if [ -z "$mail_sender" ]; then
181 echo "What address should mail from DisOrder come from?"
183 case "$mail_sender" in
188 echo "Email address must contain an '@' sign"
194 if [ -z "$register" ]; then
197 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
208 echo "Proposed DisOrder setup:"
209 echo " Music directory: $roots"
210 if [ $port = none ]; then
211 echo " Do not listen on a TCP port"
213 echo " TCP port to listen on: $port"
215 echo " SMTP Server: $smtp_server"
216 echo " Sender address: $mail_sender"
217 echo " Online registration: $register"
219 echo "Is this OK? (Enter 'y' or 'n')"
226 echo "OK, didn't change anything."
233 rm -f pkgconfdir/config.new
234 for root in $roots; do
235 echo "collection fs $encoding $root" >> pkgconfdir/config.new
237 for scratch in slap.ogg scratch.ogg; do
238 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
240 echo "user $user" >> pkgconfdir/config.new
241 if [ $port != none ]; then
242 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
244 echo "smtp_server $smtp_server" >> pkgconfdir/config.new
245 echo "mail_sender $mail_sender" >> pkgconfdir/config.new
248 echo "Proposed pkgconfdir/config:"
249 sed < pkgconfdir/config.new 's/^/ /'
251 echo "Is this OK? (Enter 'y' or 'n')"
258 echo "OK, not installing it."
259 rm -f pkgconfdir/config.new
264 echo "Installing pkgconfdir/config"
265 mv pkgconfdir/config.new pkgconfdir/config
267 if [ ! -f pkgconfdir/options.user ]; then
268 echo "Making sure pkgconfdir/options.user exists"
269 touch pkgconfdir/options.user
272 # pick ID1 ID2 ... IDn
273 # Echoes an ID matching none of ID1..IDn
276 n=250 # better not choose 0!
295 # Apple don't seem to believe in creating a user as a discrete operation
296 if dscl . -read /Groups/$group >/dev/null 2>&1; then
297 echo "$group group already exists"
299 echo "Creating $group group"
300 gids=$(dscl . -list /Groups PrimaryGroupID|awk '{print $2}')
302 echo "(picked gid $gid)"
303 dscl . -create /Groups/$group
304 dscl . -create /Groups/$group PrimaryGroupID $gid
305 dscl . -create /Groups/$group Password \*
307 if dscl . -read /Users/$user >/dev/null 2>&1; then
308 echo "$user user already exists"
310 echo "Creating $user user"
311 uids=$(dscl . -list /Users UniqueID|awk '{print $2}')
313 echo "(picked uid $uid)"
314 gid=$(dscl . -read /Groups/$group PrimaryGroupID | awk '{print $2}')
315 dscl . -create /Users/$user
316 dscl . -create /Users/$user UniqueID $uid
317 dscl . -create /Users/$user UserShell /usr/bin/false
318 dscl . -create /Users/$user RealName 'DisOrder server'
319 dscl . -create /Users/$user NFSHomeDirectory pkgstatedir
320 dscl . -create /Users/$user PrimaryGroupID $gid
321 dscl . -create /Users/$user Password \*
325 # FreeBSD has a simple well-documented interface
326 if pw groupshow $group >/dev/null 2>&1; then
327 echo "$group group already exists"
329 echo "Creating $group group"
332 if pw usershow $user >/dev/null 2>&1; then
333 echo "$user user already exists"
335 echo "Creating $user user"
336 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
340 if grep ^$group: /etc/group >/dev/null; then
341 echo "$group group already exists"
343 echo "Creating $group group"
346 if grep ^$user: /etc/passwd >/dev/null; then
347 echo "$user user already exists"
349 echo "Creating $user user"
350 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
355 echo "Making sure that pkgstatedir exists"
357 chown $user:$group pkgstatedir
358 chmod 2755 pkgstatedir
362 echo "Installing the plist into /Library/LaunchDaemons"
363 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
364 echo "Reloading launchd"
365 launchctl load /Library/LaunchDaemons
366 echo "Starting DisOrder server"
367 launchctl start uk.org.greenend.rjk.disorder
368 CGIBIN=/Library/WebServer/CGI-Executables
369 DOCROOT=/Library/WebServer/Documents
373 echo "Installing startup script into /etc/rc.d"
374 install -m 555 examples/disorder.rc /etc/rc.d/disorder
375 echo "Starting DisOrder server"
376 /etc/rc.d/disorder start
377 echo "Identifying web server"
382 echo "Could not find a web server"
389 echo "Yikes! There seems to be more than one web server here."
390 echo "Guessing that you want $1."
401 echo "Looking for init scripts directory"
402 for d in /etc/rc.d /etc; do
403 if [ -d $d/init.d ]; then
408 if [ -z "$RC_D" ]; then
409 echo "Cannot find your init scripts directory"
411 echo "Installing init script into $RC_D/init.d"
412 install -m 755 examples/disorder.init $RC_D/init.d/disorder
413 echo "Linking init script into $RC_D/rc*.d"
415 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
416 rm -f $RC_D/rc$n.d/S99disorder
417 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/S99disorder
420 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
421 rm -f $RC_D/rc$n.d/K01disorder
422 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/K01disorder
424 echo "Starting DisOrder server"
425 $RC_D/init.d/disorder start
427 echo "Looking for web server document root"
428 for d in /var/www/html /var/www; do
434 echo "Looking for cgi-bin directory"
435 for d in /var/www/cgi-bin /usr/lib/cgi-bin; do
445 echo "Sorry, I don't know how to install the server on this platform."
446 echo "You will have to do that by hand."
452 if [ -z "$DOCROOT" ]; then
453 echo "Cannot find your web server's document root"
455 echo "Setting up link to CGI's dependencies in $DOCROOT"
456 rm -f $DOCROOT/disorder
457 ln -s pkgdatadir/static $DOCROOT/disorder
461 if [ -z "$CGIBIN" ]; then
462 echo "Cannot find your web server's cgi-bin directory"
464 echo "Installing CGI in $CGIBIN"
465 install -m 555 server/disorder.cgi $CGIBIN/disorder
468 if $server_running; then
471 while ! disorder version >/dev/null 2>&1; do
473 echo "Waiting for server startup to complete..."
478 if [ $register = y ]; then
479 echo "Creating guest user with 'register' right"
482 echo "Creating guest user without 'register' right"
483 disorder setup-guest --no-online-registration