chiark / gitweb /
Finish off Mac support in scripts/setup.
[disorder] / scripts / setup.in
CommitLineData
91370169
RK
1#! /bin/bash
2#
3# This file is part of DisOrder
4# Copyright (C) 2008 Richard Kettlewell
5#
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.
10#
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.
15#
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
19# USA
20#
21
22set -e
23
24echo
25echo ------------------------------------------------------------------------
26echo "DisOrder setup script"
27
28case $(uname -s) in
29Darwin )
dda76819
RK
30 echo "Mac OS X detected"
31 os=Mac
d255d211
RK
32 user=jukebox
33 group=jukebox
91370169 34 ;;
dda76819
RK
35FreeBSD )
36 echo "FreeBSD detected"
37 os=FreeBSD
38 user=jukebox
39 group=jukebox
40 ;;
41Linux )
42 if grep Debian /etc/issue >/dev/null 2>&1; then
43 echo "You appear to be running Debian - please use .debs instead"
44 exit 1
45 fi
46 if grep Ubuntu /etc/issue >/dev/null 2>&1; then
47 echo "You appear to be running Ubuntu - please use .debs instead"
48 exit 1
49 fi
50 echo "Linux detected"
51 os=Linux
52 user=jukebox
53 group=jukebox
54 ;;
91370169 55* )
dda76819
RK
56 echo
57 echo "WARNING: unknown operating system '$(uname -s)'"
58 echo "This script won't be able to do all setup on this platform"
91370169
RK
59 os=unknown
60 user=daemon
61 group=daemon
62 ;;
63esac
64
65echo
66echo "This script will:"
67echo " - overwrite any existing configuration"
68case $os in
dda76819 69Mac )
91370169
RK
70 echo " - set the server up to be run at boot time"
71 echo " - start the server"
72 ;;
73esac
74echo
75echo "If this is not what you want, press ^C."
76echo ------------------------------------------------------------------------
77
78while :; do
79 echo
80 echo "What directory or directories contain your music files:"
81 echo "(enter one or more directories separated by spaces)"
82 read -r roots
83 ok=true
84 for root in $roots; do
85 if [ ! -d $root ]; then
86 echo "'$root' does not exist"
87 ok=false
88 fi
89 done
90 if $ok; then
91 break
92 fi
93done
94
95if [ -z "$encoding" ]; then
96 echo
97 echo "What filesystem encoding should I assume for track names?"
98 echo "(e.g. UTF-8, ISO-8859-1, ...)"
99 read -r encoding
100fi
101
102while :; do
103 echo
104 echo "What TCP port should DisOrder listen on?"
105 echo "(enter 'none' for none)"
106 read -r port
107 case $port in
108 none )
109 break
110 ;;
111 [^0-9] )
112 echo "'$port' is not a valid port number"
113 continue
114 ;;
115 * )
116 break
117 ;;
118 esac
119done
120
121echo
122echo "What host should DisOrder use as an SMTP server?"
123read -r smtp_server
124
125echo
126echo "What address should mail from DisOrder come from?"
127read -r mail_sender
128
129echo
130echo "Proposed DisOrder setup:"
131echo " Music directory: $roots"
132if [ $port = none ]; then
133 echo " Do not listen on a TCP port"
134else
135 echo " TCP port to listen on: $port"
136fi
137echo " SMTP Server: $smtp_server"
138echo " Sender address: $mail_sender"
139
140echo "Is this OK? (Enter 'y' or 'n')"
141read -r ok
142case $ok in
143y )
144 ;;
145* )
146 echo
147 echo "OK, didn't change anything."
148 exit 0
149 ;;
150esac
151
152mkdir -p pkgconfdir
153
154rm -f pkgconfdir/config.new
155for root in $roots; do
156 echo "collection fs $encoding $root" >> pkgconfdir/config.new
157done
158for scratch in slap.ogg scratch.ogg; do
159 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
160done
161echo "user $user" >> pkgconfdir/config.new
162if [ $port != none ]; then
163 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
164fi
919c5c40
RK
165echo "smtp_server $smtp_server" >> pkgconfdir/config.new
166echo "mail_sender $mail_sender" >> pkgconfdir/config.new
91370169
RK
167
168echo
169echo "Proposed pkgconfdir/config:"
170sed < pkgconfdir/config.new 's/^/ /'
171echo
172echo "Is this OK? (Enter 'y' or 'n')"
173read -r ok
174case $ok in
175y )
176 ;;
177* )
178 echo
179 echo "OK, not installing it."
180 rm -f pkgconfdir/config.new
181 exit 0
182 ;;
183esac
184echo
185echo "Installing pkgconfdir/config"
186mv pkgconfdir/config.new pkgconfdir/config
187
919c5c40
RK
188if [ ! -f pkgconfdir/options.user ]; then
189 echo "Making sure pkgconfdir/options.user exists"
190 touch pkgconfdir/options.user
191fi
192
d255d211
RK
193# pick ID1 ID2 ... IDn
194# Echoes an ID matching none of ID1..IDn
195pick() {
196 local n
197 n=250 # better not choose 0!
198 while :; do
199 ok=true
200 for k in "$@"; do
201 if [ $n = $k ]; then
202 ok=false
203 break
204 fi
205 done
206 if $ok; then
207 echo $n
208 return
209 fi
210 n=$((1+$n))
211 done
212}
213
dda76819
RK
214case $os in
215Mac )
d255d211
RK
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"
219 else
220 echo "Creating $group group"
221 gids=$(dscl / -list /Groups PrimaryGroupID|awk '{print $2}')
222 gid=$(pick $gids)
223 echo "(picked gid $gid)"
224 dscl / -create /Groups/$group
225 dscl / -create /Groups/$group PrimaryGroupID $gid
226 dscl / -create /Groups/$group Password \*
227 fi
228 if dscl / -read /Users/$user >/dev/null 2>&1; then
229 echo "$user user already exists"
230 else
231 echo "Creating $user user"
232 uids=$(dscl / -list /Users UniqueID|awk '{print $2}')
233 uid=$(pick $uids)
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 \*
243 fi
dda76819
RK
244 ;;
245FreeBSD )
d255d211 246 # FreeBSD has a simple well-documented interface
dda76819
RK
247 if pw groupshow $group >/dev/null 2>&1; then
248 echo "$group group already exists"
249 else
250 echo "Creating $group group"
251 pw groupadd $group
252 fi
253 if pw usershow $user >/dev/null 2>&1; then
254 echo "$user user already exists"
255 else
256 echo "Creating $user user"
257 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
258 fi
259 ;;
260Linux )
261 if grep ^$group: /etc/group >/dev/null; then
262 echo "$group group already exists"
263 else
264 echo "Creating $group group"
265 groupadd $group
266 fi
267 if grep ^$user: /etc/passwd >/dev/null; then
268 echo "$user user already exists"
269 else
270 echo "Creating $user user"
271 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
272 fi
273 ;;
274esac
275
91370169
RK
276echo "Making sure that pkgstatedir exists"
277mkdir -p pkgstatedir
278chown $user:$group pkgstatedir
279chmod 2755 pkgstatedir
280
281case $os in
dda76819
RK
282Mac )
283 echo "Installing the plist into /Library/LaunchDaemons"
244348f8 284 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
91370169
RK
285 echo "Reloading launchd"
286 launchctl load /Library/LaunchDaemons
287 echo "Starting DisOrder server"
288 launchctl start uk.org.greenend.rjk.disorder
919c5c40
RK
289 echo "Installing CGI"
290 install -m 555 server/disorder.cgi /Library/WebServer/CGI-Executables/disorder
06638b8d 291 echo "Setting up link to CGI's dependencies"
dda76819
RK
292 rm -f /Library/WebServer/Documents/disorder
293 ln -s pkgdatadir/static /Library/WebServer/Documents/disorder
919c5c40
RK
294 echo
295 echo "You must sudo disorder setup-guest [--no-online-registration] next."
91370169 296 ;;
06638b8d
RK
297FreeBSD )
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"
303 set /usr/local/www/*
304 case $# in
305 0 )
306 echo
307 echo "Could not find a web server"
308 exit 1
309 ;;
310 1 )
311 ;;
312 * )
313 echo
314 echo "Yikes! There seems to be more than one web server here."
315 echo "Guessing that you want $1."
316 echo
317 ;;
318 esac
319 web=$1
320 echo "Found $web"
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
326 echo
327 echo "You must sudo disorder setup-guest [--no-online-registration] next."
328 ;;
91370169
RK
329* )
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."
332 exit 1
333 ;;
334esac