chiark / gitweb /
plugins/tracklength-gstreamer.c: Rewrite to use `GstDiscoverer'.
[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#
e7eb3a27 6# This program is free software: you can redistribute it and/or modify
91370169 7# it under the terms of the GNU General Public License as published by
e7eb3a27 8# the Free Software Foundation, either version 3 of the License, or
91370169 9# (at your option) any later version.
e7eb3a27
RK
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
91370169 16# You should have received a copy of the GNU General Public License
e7eb3a27 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
91370169
RK
18#
19
20set -e
21
3b8ce6f6
RK
22while [ $# -gt 0 ]; do
23 opt="$1"
24 shift
25 case "$opt" in
26 -h | --help )
27 cat <<EOF
a64fa2a9 28
3b8ce6f6
RK
29Usage:
30 scripts/setup [OPTIONS]
31
32Options:
33 --root ROOT Add a root (can be used multiple times)
34 --encoding ENCODING Filename encoding
35 --port PORT TCP port to listen on or 'none'
36 --smtp-server HOSTNAME SMTP server
37 --email ADDRESS Origin email address
38 --register y|n Enable/disable online registration
a64fa2a9
RK
39 --play local|network Choose local or network play
40 --mcast ADDRESS PORT Set multicast address and port for --play network
3b8ce6f6 41 -h, --help Display this message
a64fa2a9
RK
42
43Sets up a basic DisOrder installation. You must have run 'make install'
44first. Use scripts/teardown to stop the server and deconfigure.
45
3b8ce6f6
RK
46EOF
47 exit 0
48 ;;
a64fa2a9
RK
49 --version | -V )
50 echo "DisOrder scripts/setup _version_"
51 exit 0
52 ;;
3b8ce6f6
RK
53 --root )
54 roots="$roots $1"
55 shift
56 ;;
57 --encoding )
58 encoding="$1"
59 shift
60 ;;
61 --port )
62 port="$1"
63 shift
64 ;;
65 --smtp-server )
66 smtp_server="$1"
67 shift
68 ;;
69 --email )
70 mail_sender="$1"
71 shift
72 ;;
73 --register )
74 register="$1"
75 shift
76 ;;
a64fa2a9
RK
77 --play )
78 play="$1"
79 shift
80 ;;
81 --mcast )
82 play=network
83 mcast_address="$1"
84 shift
85 mcast_port="$1"
86 shift
87 ;;
3b8ce6f6
RK
88 * )
89 echo >&2 "ERROR: unknown option '$opt'"
90 exit 1
91 ;;
92 esac
93done
94
91370169
RK
95echo
96echo ------------------------------------------------------------------------
97echo "DisOrder setup script"
98
99case $(uname -s) in
100Darwin )
dda76819
RK
101 echo "Mac OS X detected"
102 os=Mac
d255d211
RK
103 user=jukebox
104 group=jukebox
91370169 105 ;;
dda76819
RK
106FreeBSD )
107 echo "FreeBSD detected"
108 os=FreeBSD
109 user=jukebox
110 group=jukebox
111 ;;
112Linux )
113 if grep Debian /etc/issue >/dev/null 2>&1; then
114 echo "You appear to be running Debian - please use .debs instead"
ce195bb5
RK
115 echo
116 elif grep Ubuntu /etc/issue >/dev/null 2>&1; then
dda76819 117 echo "You appear to be running Ubuntu - please use .debs instead"
ce195bb5 118 echo
dda76819
RK
119 fi
120 echo "Linux detected"
121 os=Linux
122 user=jukebox
123 group=jukebox
124 ;;
91370169 125* )
dda76819
RK
126 echo
127 echo "WARNING: unknown operating system '$(uname -s)'"
128 echo "This script won't be able to do all setup on this platform"
91370169
RK
129 os=unknown
130 user=daemon
131 group=daemon
132 ;;
133esac
134
135echo
136echo "This script will:"
137echo " - overwrite any existing configuration"
1a8b03f3
RK
138echo " - set the server up to be run at boot time"
139echo " - start the server"
140echo " - set up the web interface"
91370169
RK
141echo
142echo "If this is not what you want, press ^C."
143echo ------------------------------------------------------------------------
144
3b8ce6f6
RK
145if [ -z "$roots" ]; then
146 while :; do
147 echo
148 echo "What directory or directories contain your music files:"
149 echo "(enter one or more directories separated by spaces)"
150 read -r roots
151 ok=true
36a36b67 152 anyroots=false
3b8ce6f6
RK
153 for root in $roots; do
154 if [ ! -d $root ]; then
155 echo "'$root' does not exist"
156 ok=false
36a36b67
RK
157 else
158 anyroots=true
3b8ce6f6
RK
159 fi
160 done
36a36b67 161 if $anyroots && $ok; then
3b8ce6f6 162 break
91370169
RK
163 fi
164 done
3b8ce6f6 165fi
91370169
RK
166
167if [ -z "$encoding" ]; then
36a36b67
RK
168 while :; do
169 echo
170 echo "What filesystem encoding should I assume for track names?"
171 echo "(e.g. UTF-8, ISO-8859-1, ...)"
172 read -r encoding
173 if [ ! -z "$encoding" ]; then
174 break
175 fi
176 done
91370169
RK
177fi
178
3b8ce6f6
RK
179if [ -z "$port" ]; then
180 while :; do
181 echo
182 echo "What TCP port should DisOrder listen on?"
183 echo "(enter 'none' for none)"
184 read -r port
185 case $port in
186 none )
187 break
188 ;;
36a36b67 189 [^0-9] | "" )
3b8ce6f6
RK
190 echo "'$port' is not a valid port number"
191 continue
192 ;;
193 * )
194 break
195 ;;
196 esac
197 done
198fi
199
a64fa2a9
RK
200if [ -z "$play" ]; then
201 while :; do
202 echo
203 echo "How do you want to play sound? Enter 'local' to use a local sound"
204 echo "device or 'network' to multicast sound across your network."
205 read -r play
206 case $play in
207 'local' | network )
208 break
209 ;;
210 * )
211 echo "Enter 'local' or 'network'"
212 continue
213 ;;
214 esac
215 done
216fi
217
218if [ "x$play" = xnetwork ]; then
219 if [ -z "$mcast_address" ]; then
220 echo
221 echo "Enter destination address for network transmission"
222 echo "(e.g. a multicast address)"
223 read -r mcast_address
224 fi
225 if [ -z "$mcast_port" ]; then
226 while :; do
227 echo
228 echo "Enter destination port for network transmission"
229 read -r mcast_port
230 case $mcast_port in
231 none )
232 break
233 ;;
36a36b67 234 [^0-9] | "" )
a64fa2a9
RK
235 echo "'$mcast_port' is not a valid port number"
236 continue
237 ;;
238 * )
239 break
240 ;;
241 esac
242 done
243 fi
244fi
245
3b8ce6f6
RK
246if [ -z "$mail_sender" ]; then
247 while :; do
248 echo
249 echo "What address should mail from DisOrder come from?"
250 read -r mail_sender
251 case "$mail_sender" in
252 *@* )
253 break
254 ;;
255 * )
256 echo "Email address must contain an '@' sign"
257 ;;
258 esac
259 done
260fi
ce195bb5 261
3b8ce6f6
RK
262if [ -z "$register" ]; then
263 while :; do
264 echo
265 echo "Do you want to enable online registration? (Enter 'y' or 'n')"
266 read -r register
6f52f7c5 267 case $register in
3b8ce6f6
RK
268 y | n )
269 break
270 ;;
271 esac
272 done
273fi
91370169
RK
274
275echo
276echo "Proposed DisOrder setup:"
277echo " Music directory: $roots"
36a36b67 278if [ "$port" = none ]; then
91370169
RK
279 echo " Do not listen on a TCP port"
280else
281 echo " TCP port to listen on: $port"
282fi
6f52f7c5
RK
283if [ ! -z "$smtp_server" ]; then
284 echo " SMTP Server: $smtp_server"
285fi
91370169 286echo " Sender address: $mail_sender"
3b8ce6f6 287echo " Online registration: $register"
a64fa2a9
RK
288if [ $play = network ]; then
289 echo " Send sound to: $mcast_address port $mcast_port"
290fi
91370169
RK
291
292echo "Is this OK? (Enter 'y' or 'n')"
293read -r ok
294case $ok in
295y )
296 ;;
297* )
298 echo
299 echo "OK, didn't change anything."
300 exit 0
301 ;;
302esac
303
304mkdir -p pkgconfdir
305
306rm -f pkgconfdir/config.new
307for root in $roots; do
308 echo "collection fs $encoding $root" >> pkgconfdir/config.new
309done
310for scratch in slap.ogg scratch.ogg; do
311 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
312done
313echo "user $user" >> pkgconfdir/config.new
314if [ $port != none ]; then
315 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
a64fa2a9
RK
316fi
317if [ $play = network ]; then
318 echo "broadcast $mcast_address $mcast_port" >> pkgconfdir/config.new
91370169 319fi
6f52f7c5
RK
320if [ ! -z "$smtp_server" ]; then
321 echo "smtp_server $smtp_server" >> pkgconfdir/config.new
322fi
919c5c40 323echo "mail_sender $mail_sender" >> pkgconfdir/config.new
91370169
RK
324
325echo
326echo "Proposed pkgconfdir/config:"
327sed < pkgconfdir/config.new 's/^/ /'
328echo
329echo "Is this OK? (Enter 'y' or 'n')"
330read -r ok
331case $ok in
332y )
333 ;;
334* )
335 echo
336 echo "OK, not installing it."
337 rm -f pkgconfdir/config.new
338 exit 0
339 ;;
340esac
341echo
342echo "Installing pkgconfdir/config"
343mv pkgconfdir/config.new pkgconfdir/config
344
919c5c40
RK
345if [ ! -f pkgconfdir/options.user ]; then
346 echo "Making sure pkgconfdir/options.user exists"
347 touch pkgconfdir/options.user
348fi
349
d255d211
RK
350# pick ID1 ID2 ... IDn
351# Echoes an ID matching none of ID1..IDn
352pick() {
353 local n
354 n=250 # better not choose 0!
355 while :; do
356 ok=true
357 for k in "$@"; do
358 if [ $n = $k ]; then
359 ok=false
360 break
361 fi
362 done
363 if $ok; then
364 echo $n
365 return
366 fi
367 n=$((1+$n))
368 done
369}
370
dda76819
RK
371case $os in
372Mac )
d255d211 373 # Apple don't seem to believe in creating a user as a discrete operation
d7b0c55c 374 if dscl . -read /Groups/$group >/dev/null 2>&1; then
d255d211
RK
375 echo "$group group already exists"
376 else
377 echo "Creating $group group"
d7b0c55c 378 gids=$(dscl . -list /Groups PrimaryGroupID|awk '{print $2}')
d255d211
RK
379 gid=$(pick $gids)
380 echo "(picked gid $gid)"
d7b0c55c
RK
381 dscl . -create /Groups/$group
382 dscl . -create /Groups/$group PrimaryGroupID $gid
383 dscl . -create /Groups/$group Password \*
d255d211 384 fi
d7b0c55c 385 if dscl . -read /Users/$user >/dev/null 2>&1; then
d255d211
RK
386 echo "$user user already exists"
387 else
388 echo "Creating $user user"
d7b0c55c 389 uids=$(dscl . -list /Users UniqueID|awk '{print $2}')
d255d211
RK
390 uid=$(pick $uids)
391 echo "(picked uid $uid)"
d7b0c55c
RK
392 gid=$(dscl . -read /Groups/$group PrimaryGroupID | awk '{print $2}')
393 dscl . -create /Users/$user
394 dscl . -create /Users/$user UniqueID $uid
395 dscl . -create /Users/$user UserShell /usr/bin/false
396 dscl . -create /Users/$user RealName 'DisOrder server'
397 dscl . -create /Users/$user NFSHomeDirectory pkgstatedir
398 dscl . -create /Users/$user PrimaryGroupID $gid
399 dscl . -create /Users/$user Password \*
d255d211 400 fi
dda76819
RK
401 ;;
402FreeBSD )
d255d211 403 # FreeBSD has a simple well-documented interface
dda76819
RK
404 if pw groupshow $group >/dev/null 2>&1; then
405 echo "$group group already exists"
406 else
407 echo "Creating $group group"
408 pw groupadd $group
409 fi
410 if pw usershow $user >/dev/null 2>&1; then
411 echo "$user user already exists"
412 else
413 echo "Creating $user user"
414 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
415 fi
416 ;;
417Linux )
418 if grep ^$group: /etc/group >/dev/null; then
419 echo "$group group already exists"
420 else
421 echo "Creating $group group"
422 groupadd $group
423 fi
424 if grep ^$user: /etc/passwd >/dev/null; then
425 echo "$user user already exists"
426 else
427 echo "Creating $user user"
428 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
429 fi
430 ;;
431esac
432
91370169
RK
433echo "Making sure that pkgstatedir exists"
434mkdir -p pkgstatedir
435chown $user:$group pkgstatedir
436chmod 2755 pkgstatedir
437
438case $os in
dda76819
RK
439Mac )
440 echo "Installing the plist into /Library/LaunchDaemons"
244348f8 441 cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
91370169
RK
442 echo "Reloading launchd"
443 launchctl load /Library/LaunchDaemons
444 echo "Starting DisOrder server"
445 launchctl start uk.org.greenend.rjk.disorder
64ac73bb 446 server_running=true
91370169 447 ;;
06638b8d
RK
448FreeBSD )
449 echo "Installing startup script into /etc/rc.d"
450 install -m 555 examples/disorder.rc /etc/rc.d/disorder
451 echo "Starting DisOrder server"
452 /etc/rc.d/disorder start
ce195bb5
RK
453 server_running=true
454 ;;
455Linux )
456 echo "Looking for init scripts directory"
457 for d in /etc/rc.d /etc; do
458 if [ -d $d/init.d ]; then
459 RC_D=$d
460 break
461 fi
462 done
463 if [ -z "$RC_D" ]; then
464 echo "Cannot find your init scripts directory"
465 else
466 echo "Installing init script into $RC_D/init.d"
467 install -m 755 examples/disorder.init $RC_D/init.d/disorder
468 echo "Linking init script into $RC_D/rc*.d"
469 for n in 2 3 4 5; do
470 echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder"
471 rm -f $RC_D/rc$n.d/S99disorder
472 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/S99disorder
473 done
474 for n in 0 1 6; do
475 echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder"
476 rm -f $RC_D/rc$n.d/K01disorder
477 ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/K01disorder
478 done
479 echo "Starting DisOrder server"
480 $RC_D/init.d/disorder start
481 fi
ce195bb5 482 server_running=true
06638b8d 483 ;;
91370169 484* )
ce195bb5 485 echo
91370169
RK
486 echo "Sorry, I don't know how to install the server on this platform."
487 echo "You will have to do that by hand."
ce195bb5 488 server_running=false
91370169
RK
489 ;;
490esac
ce195bb5 491
ce195bb5 492if $server_running; then
1a8b03f3 493 first=true
4f70fa29 494 sleep 5
1a8b03f3
RK
495 while ! disorder version >/dev/null 2>&1; do
496 if $first; then
497 echo "Waiting for server startup to complete..."
498 first=false
499 fi
500 sleep 1
501 done
3b8ce6f6 502 if [ $register = y ]; then
ce195bb5
RK
503 echo "Creating guest user with 'register' right"
504 disorder setup-guest
505 else
506 echo "Creating guest user without 'register' right"
507 disorder setup-guest --no-online-registration
508 fi
509fi
510
511echo
512echo Done