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"
46 if grep Ubuntu /etc/issue >/dev/null 2>&1; then
47 echo "You appear to be running Ubuntu - please use .debs instead"
57 echo "WARNING: unknown operating system '$(uname -s)'"
58 echo "This script won't be able to do all setup on this platform"
66 echo "This script will:"
67 echo " - overwrite any existing configuration"
70 echo " - set the server up to be run at boot time"
71 echo " - start the server"
75 echo "If this is not what you want, press ^C."
76 echo ------------------------------------------------------------------------
80 echo "What directory or directories contain your music files:"
81 echo "(enter one or more directories separated by spaces)"
84 for root in $roots; do
85 if [ ! -d $root ]; then
86 echo "'$root' does not exist"
95 if [ -z "$encoding" ]; then
97 echo "What filesystem encoding should I assume for track names?"
98 echo "(e.g. UTF-8, ISO-8859-1, ...)"
104 echo "What TCP port should DisOrder listen on?"
105 echo "(enter 'none' for none)"
112 echo "'$port' is not a valid port number"
122 echo "What host should DisOrder use as an SMTP server?"
126 echo "What address should mail from DisOrder come from?"
130 echo "Proposed DisOrder setup:"
131 echo " Music directory: $roots"
132 if [ $port = none ]; then
133 echo " Do not listen on a TCP port"
135 echo " TCP port to listen on: $port"
137 echo " SMTP Server: $smtp_server"
138 echo " Sender address: $mail_sender"
140 echo "Is this OK? (Enter 'y' or 'n')"
147 echo "OK, didn't change anything."
154 rm -f pkgconfdir/config.new
155 for root in $roots; do
156 echo "collection fs $encoding $root" >> pkgconfdir/config.new
158 for scratch in slap.ogg scratch.ogg; do
159 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
161 echo "user $user" >> pkgconfdir/config.new
162 if [ $port != none ]; then
163 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
165 echo "smtp_server $smtp_server" >> pkgconfdir/config.new
166 echo "mail_sender $mail_sender" >> pkgconfdir/config.new
169 echo "Proposed pkgconfdir/config:"
170 sed < pkgconfdir/config.new 's/^/ /'
172 echo "Is this OK? (Enter 'y' or 'n')"
179 echo "OK, not installing it."
180 rm -f pkgconfdir/config.new
185 echo "Installing pkgconfdir/config"
186 mv pkgconfdir/config.new pkgconfdir/config
188 if [ ! -f pkgconfdir/options.user ]; then
189 echo "Making sure pkgconfdir/options.user exists"
190 touch pkgconfdir/options.user
193 # pick ID1 ID2 ... IDn
194 # Echoes an ID matching none of ID1..IDn
197 n=250 # better not choose 0!
216 # Apple don't seem to believe in creating a user as a discrete operation
217 if dscl / -read /Groups/$group >/dev/null 2>&1; then
218 echo "$group group already exists"
220 echo "Creating $group group"
221 gids=$(dscl / -list /Groups PrimaryGroupID|awk '{print $2}')
223 echo "(picked gid $gid)"
224 dscl / -create /Groups/$group
225 dscl / -create /Groups/$group PrimaryGroupID $gid
226 dscl / -create /Groups/$group Password \*
228 if dscl / -read /Users/$user >/dev/null 2>&1; then
229 echo "$user user already exists"
231 echo "Creating $user user"
232 uids=$(dscl / -list /Users UniqueID|awk '{print $2}')
234 echo "(picked uid $uid)"
235 gid=$(dscl / -read /Groups/$group PrimaryGroupID | awk '{print $2}')
236 dscl / -create /Users/$user
237 dscl / -create /Users/$user UniqueID $uid
238 dscl / -create /Users/$user UserShell /usr/bin/false
239 dscl / -create /Users/$user RealName 'DisOrder server'
240 dscl / -create /Users/$user NFSHomeDirectory pkgstatedir
241 dscl / -create /Users/$user PrimaryGroupID $gid
242 dscl / -create /Users/$user Password \*
246 # FreeBSD has a simple well-documented interface
247 if pw groupshow $group >/dev/null 2>&1; then
248 echo "$group group already exists"
250 echo "Creating $group group"
253 if pw usershow $user >/dev/null 2>&1; then
254 echo "$user user already exists"
256 echo "Creating $user user"
257 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
261 if grep ^$group: /etc/group >/dev/null; then
262 echo "$group group already exists"
264 echo "Creating $group group"
267 if grep ^$user: /etc/passwd >/dev/null; then
268 echo "$user user already exists"
270 echo "Creating $user user"
271 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
276 echo "Making sure that pkgstatedir exists"
278 chown $user:$group pkgstatedir
279 chmod 2755 pkgstatedir
283 echo "Installing the plist into /Library/LaunchDaemons"
284 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
285 echo "Reloading launchd"
286 launchctl load /Library/LaunchDaemons
287 echo "Starting DisOrder server"
288 launchctl start uk.org.greenend.rjk.disorder
289 echo "Installing CGI"
290 install -m 555 server/disorder.cgi /Library/WebServer/CGI-Executables/disorder
291 echo "Setting up link to CGI's dependencies"
292 rm -f /Library/WebServer/Documents/disorder
293 ln -s pkgdatadir/static /Library/WebServer/Documents/disorder
295 echo "You must sudo disorder setup-guest [--no-online-registration] next."
298 echo "Installing startup script into /etc/rc.d"
299 install -m 555 examples/disorder.rc /etc/rc.d/disorder
300 echo "Starting DisOrder server"
301 /etc/rc.d/disorder start
302 echo "Identifying web server"
307 echo "Could not find a web server"
314 echo "Yikes! There seems to be more than one web server here."
315 echo "Guessing that you want $1."
321 echo "Installing CGI"
322 install -m 555 server/disorder.cgi $web/cgi-bin/disorder
323 echo "Setting up link to CGI's dependencies"
324 rm -f $web/data/disorder
325 ln -s pkgdatadir/static $web/data/disorder
327 echo "You must sudo disorder setup-guest [--no-online-registration] next."
330 echo "Sorry, I don't know how to install the server on this platform."
331 echo "You will have to do that by hand."