chiark / gitweb /
Partial untested FreeBSD and Linux support for 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
32 # TODO we should use jukebox and create it if necessary; see below
91370169
RK
33 user=daemon
34 group=daemon
35 ;;
dda76819
RK
36FreeBSD )
37 echo "FreeBSD detected"
38 os=FreeBSD
39 user=jukebox
40 group=jukebox
41 ;;
42Linux )
43 if grep Debian /etc/issue >/dev/null 2>&1; then
44 echo "You appear to be running Debian - please use .debs instead"
45 exit 1
46 fi
47 if grep Ubuntu /etc/issue >/dev/null 2>&1; then
48 echo "You appear to be running Ubuntu - please use .debs instead"
49 exit 1
50 fi
51 echo "Linux detected"
52 os=Linux
53 user=jukebox
54 group=jukebox
55 ;;
91370169 56* )
dda76819
RK
57 echo
58 echo "WARNING: unknown operating system '$(uname -s)'"
59 echo "This script won't be able to do all setup on this platform"
91370169
RK
60 os=unknown
61 user=daemon
62 group=daemon
63 ;;
64esac
65
66echo
67echo "This script will:"
68echo " - overwrite any existing configuration"
69case $os in
dda76819 70Mac )
91370169
RK
71 echo " - set the server up to be run at boot time"
72 echo " - start the server"
73 ;;
74esac
75echo
76echo "If this is not what you want, press ^C."
77echo ------------------------------------------------------------------------
78
79while :; do
80 echo
81 echo "What directory or directories contain your music files:"
82 echo "(enter one or more directories separated by spaces)"
83 read -r roots
84 ok=true
85 for root in $roots; do
86 if [ ! -d $root ]; then
87 echo "'$root' does not exist"
88 ok=false
89 fi
90 done
91 if $ok; then
92 break
93 fi
94done
95
96if [ -z "$encoding" ]; then
97 echo
98 echo "What filesystem encoding should I assume for track names?"
99 echo "(e.g. UTF-8, ISO-8859-1, ...)"
100 read -r encoding
101fi
102
103while :; do
104 echo
105 echo "What TCP port should DisOrder listen on?"
106 echo "(enter 'none' for none)"
107 read -r port
108 case $port in
109 none )
110 break
111 ;;
112 [^0-9] )
113 echo "'$port' is not a valid port number"
114 continue
115 ;;
116 * )
117 break
118 ;;
119 esac
120done
121
122echo
123echo "What host should DisOrder use as an SMTP server?"
124read -r smtp_server
125
126echo
127echo "What address should mail from DisOrder come from?"
128read -r mail_sender
129
130echo
131echo "Proposed DisOrder setup:"
132echo " Music directory: $roots"
133if [ $port = none ]; then
134 echo " Do not listen on a TCP port"
135else
136 echo " TCP port to listen on: $port"
137fi
138echo " SMTP Server: $smtp_server"
139echo " Sender address: $mail_sender"
140
141echo "Is this OK? (Enter 'y' or 'n')"
142read -r ok
143case $ok in
144y )
145 ;;
146* )
147 echo
148 echo "OK, didn't change anything."
149 exit 0
150 ;;
151esac
152
153mkdir -p pkgconfdir
154
155rm -f pkgconfdir/config.new
156for root in $roots; do
157 echo "collection fs $encoding $root" >> pkgconfdir/config.new
158done
159for scratch in slap.ogg scratch.ogg; do
160 echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new
161done
162echo "user $user" >> pkgconfdir/config.new
163if [ $port != none ]; then
164 echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
165fi
919c5c40
RK
166echo "smtp_server $smtp_server" >> pkgconfdir/config.new
167echo "mail_sender $mail_sender" >> pkgconfdir/config.new
91370169
RK
168
169echo
170echo "Proposed pkgconfdir/config:"
171sed < pkgconfdir/config.new 's/^/ /'
172echo
173echo "Is this OK? (Enter 'y' or 'n')"
174read -r ok
175case $ok in
176y )
177 ;;
178* )
179 echo
180 echo "OK, not installing it."
181 rm -f pkgconfdir/config.new
182 exit 0
183 ;;
184esac
185echo
186echo "Installing pkgconfdir/config"
187mv pkgconfdir/config.new pkgconfdir/config
188
919c5c40
RK
189if [ ! -f pkgconfdir/options.user ]; then
190 echo "Making sure pkgconfdir/options.user exists"
191 touch pkgconfdir/options.user
192fi
193
dda76819
RK
194case $os in
195Mac )
196 # TODO niutil?
197 ;;
198FreeBSD )
199 if pw groupshow $group >/dev/null 2>&1; then
200 echo "$group group already exists"
201 else
202 echo "Creating $group group"
203 pw groupadd $group
204 fi
205 if pw usershow $user >/dev/null 2>&1; then
206 echo "$user user already exists"
207 else
208 echo "Creating $user user"
209 pw useradd $user -w no -d pkgstatedir -g $group -c 'DisOrder user'
210 fi
211 ;;
212Linux )
213 if grep ^$group: /etc/group >/dev/null; then
214 echo "$group group already exists"
215 else
216 echo "Creating $group group"
217 groupadd $group
218 fi
219 if grep ^$user: /etc/passwd >/dev/null; then
220 echo "$user user already exists"
221 else
222 echo "Creating $user user"
223 useradd -d pkgstatedir -g $group $user -c 'DisOrder user'
224 fi
225 ;;
226esac
227
91370169
RK
228echo "Making sure that pkgstatedir exists"
229mkdir -p pkgstatedir
230chown $user:$group pkgstatedir
231chmod 2755 pkgstatedir
232
233case $os in
dda76819
RK
234Mac )
235 echo "Installing the plist into /Library/LaunchDaemons"
91370169
RK
236 cp server/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/.
237 echo "Reloading launchd"
238 launchctl load /Library/LaunchDaemons
239 echo "Starting DisOrder server"
240 launchctl start uk.org.greenend.rjk.disorder
919c5c40
RK
241 echo "Installing CGI"
242 install -m 555 server/disorder.cgi /Library/WebServer/CGI-Executables/disorder
dda76819
RK
243 echo "Setting up link to CGI;'s dependencies"
244 rm -f /Library/WebServer/Documents/disorder
245 ln -s pkgdatadir/static /Library/WebServer/Documents/disorder
919c5c40
RK
246 echo
247 echo "You must sudo disorder setup-guest [--no-online-registration] next."
91370169
RK
248 ;;
249* )
250 echo "Sorry, I don't know how to install the server on this platform."
251 echo "You will have to do that by hand."
252 exit 1
253 ;;
254esac