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"
69 echo " - set the server up to be run at boot time"
70 echo " - start the server"
74 echo "If this is not what you want, press ^C."
75 echo ------------------------------------------------------------------------
79 echo "What directory or directories contain your music files:"
80 echo "(enter one or more directories separated by spaces)"
83 for root in $roots; do
84 if [ ! -d $root ]; then
85 echo "'$root' does not exist"
94 if [ -z "$encoding" ]; then
96 echo "What filesystem encoding should I assume for track names?"
97 echo "(e.g. UTF-8, ISO-8859-1, ...)"
103 echo "What TCP port should DisOrder listen on?"
104 echo "(enter 'none' for none)"
111 echo "'$port' is not a valid port number"
121 echo "What host should DisOrder use as an SMTP server?"
126 echo "What address should mail from DisOrder come from?"
128 case "$mail_sender" in
133 echo "Email address must contain an '@' sign"
139 echo "Proposed DisOrder setup:"
140 echo " Music directory: $roots"
141 if [ $port = none ]; then
142 echo " Do not listen on a TCP port"
144 echo " TCP port to listen on: $port"
146 echo " SMTP Server: $smtp_server"
147 echo " Sender address: $mail_sender"
149 echo "Is this OK? (Enter 'y' or 'n')"
156 echo "OK, didn't change anything."
163 rm -f pkgconfdir/config.new
164 for root in $roots; do
165 echo "collection fs $encoding $root" >> pkgconfdir/config.new
167 for scratch in slap.ogg scratch.ogg; do
168 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
170 echo "user $user" >> pkgconfdir/config.new
171 if [ $port != none ]; then
172 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
174 echo "smtp_server $smtp_server" >> pkgconfdir/config.new
175 echo "mail_sender $mail_sender" >> pkgconfdir/config.new
178 echo "Proposed pkgconfdir/config:"
179 sed < pkgconfdir/config.new 's/^/ /'
181 echo "Is this OK? (Enter 'y' or 'n')"
188 echo "OK, not installing it."
189 rm -f pkgconfdir/config.new
194 echo "Installing pkgconfdir/config"
195 mv pkgconfdir/config.new pkgconfdir/config
197 if [ ! -f pkgconfdir/options.user ]; then
198 echo "Making sure pkgconfdir/options.user exists"
199 touch pkgconfdir/options.user
202 # pick ID1 ID2 ... IDn
203 # Echoes an ID matching none of ID1..IDn
206 n=250 # better not choose 0!
225 # Apple don't seem to believe in creating a user as a discrete operation
226 if dscl / -read /Groups/$group >/dev/null 2>&1; then
227 echo "$group group already exists"
229 echo "Creating $group group"
230 gids=$(dscl / -list /Groups PrimaryGroupID|awk '{print $2}')
232 echo "(picked gid $gid)"
233 dscl / -create /Groups/$group
234 dscl / -create /Groups/$group PrimaryGroupID $gid
235 dscl / -create /Groups/$group Password \*
237 if dscl / -read /Users/$user >/dev/null 2>&1; then
238 echo "$user user already exists"
240 echo "Creating $user user"
241 uids=$(dscl / -list /Users UniqueID|awk '{print $2}')
243 echo "(picked uid $uid)"
244 gid=$(dscl / -read /Groups/$group PrimaryGroupID | awk '{print $2}')
245 dscl / -create /Users/$user
246 dscl / -create /Users/$user UniqueID $uid
247 dscl / -create /Users/$user UserShell /usr/bin/false
248 dscl / -create /Users/$user RealName 'DisOrder server'
249 dscl / -create /Users/$user NFSHomeDirectory pkgstatedir
250 dscl / -create /Users/$user PrimaryGroupID $gid
251 dscl / -create /Users/$user Password \*
255 # FreeBSD has a simple well-documented interface
256 if pw groupshow $group >/dev/null 2>&1; then
257 echo "$group group already exists"
259 echo "Creating $group group"
262 if pw usershow $user >/dev/null 2>&1; then
263 echo "$user user already exists"
265 echo "Creating $user user"
266 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
270 if grep ^$group: /etc/group >/dev/null; then
271 echo "$group group already exists"
273 echo "Creating $group group"
276 if grep ^$user: /etc/passwd >/dev/null; then
277 echo "$user user already exists"
279 echo "Creating $user user"
280 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
285 echo "Making sure that pkgstatedir exists"
287 chown $user:$group pkgstatedir
288 chmod 2755 pkgstatedir
292 echo "Installing the plist into /Library/LaunchDaemons"
293 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
294 echo "Reloading launchd"
295 launchctl load /Library/LaunchDaemons
296 echo "Starting DisOrder server"
297 launchctl start uk.org.greenend.rjk.disorder
298 CGIBIN=/Library/WebServer/CGI-Executables
299 DOCROOT=/Library/WebServer/Documents
303 echo "Installing startup script into /etc/rc.d"
304 install -m 555 examples/disorder.rc /etc/rc.d/disorder
305 echo "Starting DisOrder server"
306 /etc/rc.d/disorder start
307 echo "Identifying web server"
312 echo "Could not find a web server"
319 echo "Yikes! There seems to be more than one web server here."
320 echo "Guessing that you want $1."
331 echo "Looking for init scripts directory"
332 for d in /etc/rc.d /etc; do
333 if [ -d $d/init.d ]; then
338 if [ -z "$RC_D" ]; then
339 echo "Cannot find your init scripts directory"
341 echo "Installing init script into $RC_D/init.d"
342 install -m 755 examples/disorder.init $RC_D/init.d/disorder
343 echo "Linking init script into $RC_D/rc*.d"
345 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
346 rm -f $RC_D/rc$n.d/S99disorder
347 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/S99disorder
350 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
351 rm -f $RC_D/rc$n.d/K01disorder
352 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/K01disorder
354 echo "Starting DisOrder server"
355 $RC_D/init.d/disorder start
357 echo "Looking for web server document root"
358 for d in /var/www/html /var/www; do
364 echo "Looking for cgi-bin directory"
365 for d in /var/www/cgi-bin /usr/lib/cgi-bin; do
375 echo "Sorry, I don't know how to install the server on this platform."
376 echo "You will have to do that by hand."
382 if [ -z "$DOCROOT" ]; then
383 echo "Cannot find your web server's document root"
385 echo "Setting up link to CGI's dependencies in $DOCROOT"
386 rm -f $DOCROOT/disorder
387 ln -s pkgdatadir/static $DOCROOT/disorder
391 if [ -z "$CGIBIN" ]; then
392 echo "Cannot find your web server's cgi-bin directory"
394 echo "Installing CGI in $CGIBIN"
395 install -m 555 server/disorder.cgi $CGIBIN/disorder
398 if $server_running; then
401 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
410 if [ $reg = y ]; then
411 echo "Creating guest user with 'register' right"
414 echo "Creating guest user without 'register' right"
415 disorder setup-guest --no-online-registration