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
25 echo ------------------------------------------------------------------------
26 echo "DisOrder setup script"
30 echo "Mac OS X detected"
36 echo "FreeBSD detected"
42 if grep Debian
/etc
/issue
>/dev
/null
2>&1; then
43 echo "You appear to be running Debian - please use .debs instead"
45 elif grep Ubuntu
/etc
/issue
>/dev
/null
2>&1; then
46 echo "You appear to be running Ubuntu - please use .debs instead"
56 echo "WARNING: unknown operating system '$(uname -s)'"
57 echo "This script won't be able to do all setup on this platform"
65 echo "This script will:"
66 echo " - overwrite any existing configuration"
67 echo " - set the server up to be run at boot time"
68 echo " - start the server"
69 echo " - set up the web interface"
71 echo "If this is not what you want, press ^C."
72 echo ------------------------------------------------------------------------
76 echo "What directory or directories contain your music files:"
77 echo "(enter one or more directories separated by spaces)"
80 for root
in $roots; do
81 if [ ! -d
$root ]; then
82 echo "'$root' does not exist"
91 if [ -z
"$encoding" ]; then
93 echo "What filesystem encoding should I assume for track names?"
94 echo "(e.g. UTF-8, ISO-8859-1, ...)"
100 echo "What TCP port should DisOrder listen on?"
101 echo "(enter 'none' for none)"
108 echo "'$port' is not a valid port number"
118 echo "What host should DisOrder use as an SMTP server?"
123 echo "What address should mail from DisOrder come from?"
125 case "$mail_sender" in
130 echo "Email address must contain an '@' sign"
136 echo "Proposed DisOrder setup:"
137 echo " Music directory: $roots"
138 if [ $port = none
]; then
139 echo " Do not listen on a TCP port"
141 echo " TCP port to listen on: $port"
143 echo " SMTP Server: $smtp_server"
144 echo " Sender address: $mail_sender"
146 echo "Is this OK? (Enter 'y' or 'n')"
153 echo "OK, didn't change anything."
160 rm -f pkgconfdir
/config.new
161 for root
in $roots; do
162 echo "collection fs $encoding $root" >> pkgconfdir
/config.new
164 for scratch
in slap.ogg scratch.ogg
; do
165 echo "scratch pkgdatadir/$scratch" >> pkgconfdir
/config.new
167 echo "user $user" >> pkgconfdir
/config.new
168 if [ $port != none
]; then
169 echo "listen 0.0.0.0 $port" >> pkgconfdir
/config.new
171 echo "smtp_server $smtp_server" >> pkgconfdir
/config.new
172 echo "mail_sender $mail_sender" >> pkgconfdir
/config.new
175 echo "Proposed pkgconfdir/config:"
176 sed < pkgconfdir
/config.new
's/^/ /'
178 echo "Is this OK? (Enter 'y' or 'n')"
185 echo "OK, not installing it."
186 rm -f pkgconfdir
/config.new
191 echo "Installing pkgconfdir/config"
192 mv pkgconfdir
/config.new pkgconfdir
/config
194 if [ ! -f pkgconfdir
/options.user
]; then
195 echo "Making sure pkgconfdir/options.user exists"
196 touch pkgconfdir
/options.user
199 # pick ID1 ID2 ... IDn
200 # Echoes an ID matching none of ID1..IDn
203 n
=250 # better not choose 0!
222 # Apple don't seem to believe in creating a user as a discrete operation
223 if dscl .
-read /Groups
/$group >/dev
/null
2>&1; then
224 echo "$group group already exists"
226 echo "Creating $group group"
227 gids
=$
(dscl .
-list
/Groups PrimaryGroupID|
awk '{print $2}')
229 echo "(picked gid $gid)"
230 dscl .
-create
/Groups
/$group
231 dscl .
-create
/Groups
/$group PrimaryGroupID
$gid
232 dscl .
-create
/Groups
/$group Password \
*
234 if dscl .
-read /Users
/$user >/dev
/null
2>&1; then
235 echo "$user user already exists"
237 echo "Creating $user user"
238 uids
=$
(dscl .
-list
/Users UniqueID|
awk '{print $2}')
240 echo "(picked uid $uid)"
241 gid
=$
(dscl .
-read /Groups
/$group PrimaryGroupID |
awk '{print $2}')
242 dscl .
-create
/Users
/$user
243 dscl .
-create
/Users
/$user UniqueID
$uid
244 dscl .
-create
/Users
/$user UserShell
/usr
/bin
/false
245 dscl .
-create
/Users
/$user RealName
'DisOrder server'
246 dscl .
-create
/Users
/$user NFSHomeDirectory pkgstatedir
247 dscl .
-create
/Users
/$user PrimaryGroupID
$gid
248 dscl .
-create
/Users
/$user Password \
*
252 # FreeBSD has a simple well-documented interface
253 if pw groupshow
$group >/dev
/null
2>&1; then
254 echo "$group group already exists"
256 echo "Creating $group group"
259 if pw usershow
$user >/dev
/null
2>&1; then
260 echo "$user user already exists"
262 echo "Creating $user user"
263 pw useradd
$user -w no
-d pkgstatedir
-g
$group -c
'DisOrder user'
267 if grep ^
$group: /etc
/group
>/dev
/null
; then
268 echo "$group group already exists"
270 echo "Creating $group group"
273 if grep ^
$user: /etc
/passwd
>/dev
/null
; then
274 echo "$user user already exists"
276 echo "Creating $user user"
277 useradd
-d pkgstatedir
-g
$group $user -c
'DisOrder user'
282 echo "Making sure that pkgstatedir exists"
284 chown
$user:$group pkgstatedir
285 chmod 2755 pkgstatedir
289 echo "Installing the plist into /Library/LaunchDaemons"
290 cp examples
/uk.org.greenend.rjk.disorder.plist
/Library
/LaunchDaemons
/.
291 echo "Reloading launchd"
292 launchctl load
/Library
/LaunchDaemons
293 echo "Starting DisOrder server"
294 launchctl start uk.org.greenend.rjk.disorder
295 CGIBIN
=/Library
/WebServer
/CGI-Executables
296 DOCROOT
=/Library
/WebServer
/Documents
300 echo "Installing startup script into /etc/rc.d"
301 install -m
555 examples
/disorder.rc
/etc
/rc.d
/disorder
302 echo "Starting DisOrder server"
303 /etc
/rc.d
/disorder start
304 echo "Identifying web server"
309 echo "Could not find a web server"
316 echo "Yikes! There seems to be more than one web server here."
317 echo "Guessing that you want $1."
328 echo "Looking for init scripts directory"
329 for d
in /etc
/rc.d
/etc
; do
330 if [ -d
$d/init.d
]; then
335 if [ -z
"$RC_D" ]; then
336 echo "Cannot find your init scripts directory"
338 echo "Installing init script into $RC_D/init.d"
339 install -m
755 examples
/disorder.init
$RC_D/init.d
/disorder
340 echo "Linking init script into $RC_D/rc*.d"
342 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
343 rm -f
$RC_D/rc
$n.d
/S99disorder
344 ln -s
$RC_D/init.d
/disorder
$RC_D/rc
$n.d
/S99disorder
347 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
348 rm -f
$RC_D/rc
$n.d
/K01disorder
349 ln -s
$RC_D/init.d
/disorder
$RC_D/rc
$n.d
/K01disorder
351 echo "Starting DisOrder server"
352 $RC_D/init.d
/disorder start
354 echo "Looking for web server document root"
355 for d
in /var
/www
/html
/var
/www
; do
361 echo "Looking for cgi-bin directory"
362 for d
in /var
/www
/cgi-bin
/usr
/lib
/cgi-bin
; do
372 echo "Sorry, I don't know how to install the server on this platform."
373 echo "You will have to do that by hand."
379 if [ -z
"$DOCROOT" ]; then
380 echo "Cannot find your web server's document root"
382 echo "Setting up link to CGI's dependencies in $DOCROOT"
383 rm -f
$DOCROOT/disorder
384 ln -s pkgdatadir
/static
$DOCROOT/disorder
388 if [ -z
"$CGIBIN" ]; then
389 echo "Cannot find your web server's cgi-bin directory"
391 echo "Installing CGI in $CGIBIN"
392 install -m
555 server
/disorder.cgi
$CGIBIN/disorder
395 if $server_running; then
398 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
408 while ! disorder version
>/dev
/null
2>&1; do
410 echo "Waiting for server startup to complete..."
415 if [ $reg = y
]; then
416 echo "Creating guest user with 'register' right"
419 echo "Creating guest user without 'register' right"
420 disorder setup-guest
--no-online-registration