Commit | Line | Data |
---|---|---|
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 | ||
22 | set -e | |
23 | ||
24 | echo | |
25 | echo ------------------------------------------------------------------------ | |
26 | echo "DisOrder setup script" | |
27 | ||
28 | case $(uname -s) in | |
29 | Darwin ) | |
30 | os=mac | |
31 | user=daemon | |
32 | group=daemon | |
33 | ;; | |
34 | * ) | |
35 | os=unknown | |
36 | user=daemon | |
37 | group=daemon | |
38 | ;; | |
39 | esac | |
40 | ||
41 | echo | |
42 | echo "This script will:" | |
43 | echo " - overwrite any existing configuration" | |
44 | case $os in | |
45 | mac ) | |
46 | echo " - set the server up to be run at boot time" | |
47 | echo " - start the server" | |
48 | ;; | |
49 | esac | |
50 | echo | |
51 | echo "If this is not what you want, press ^C." | |
52 | echo ------------------------------------------------------------------------ | |
53 | ||
54 | while :; do | |
55 | echo | |
56 | echo "What directory or directories contain your music files:" | |
57 | echo "(enter one or more directories separated by spaces)" | |
58 | read -r roots | |
59 | ok=true | |
60 | for root in $roots; do | |
61 | if [ ! -d $root ]; then | |
62 | echo "'$root' does not exist" | |
63 | ok=false | |
64 | fi | |
65 | done | |
66 | if $ok; then | |
67 | break | |
68 | fi | |
69 | done | |
70 | ||
71 | if [ -z "$encoding" ]; then | |
72 | echo | |
73 | echo "What filesystem encoding should I assume for track names?" | |
74 | echo "(e.g. UTF-8, ISO-8859-1, ...)" | |
75 | read -r encoding | |
76 | fi | |
77 | ||
78 | while :; do | |
79 | echo | |
80 | echo "What TCP port should DisOrder listen on?" | |
81 | echo "(enter 'none' for none)" | |
82 | read -r port | |
83 | case $port in | |
84 | none ) | |
85 | break | |
86 | ;; | |
87 | [^0-9] ) | |
88 | echo "'$port' is not a valid port number" | |
89 | continue | |
90 | ;; | |
91 | * ) | |
92 | break | |
93 | ;; | |
94 | esac | |
95 | done | |
96 | ||
97 | echo | |
98 | echo "What host should DisOrder use as an SMTP server?" | |
99 | read -r smtp_server | |
100 | ||
101 | echo | |
102 | echo "What address should mail from DisOrder come from?" | |
103 | read -r mail_sender | |
104 | ||
105 | echo | |
106 | echo "Proposed DisOrder setup:" | |
107 | echo " Music directory: $roots" | |
108 | if [ $port = none ]; then | |
109 | echo " Do not listen on a TCP port" | |
110 | else | |
111 | echo " TCP port to listen on: $port" | |
112 | fi | |
113 | echo " SMTP Server: $smtp_server" | |
114 | echo " Sender address: $mail_sender" | |
115 | ||
116 | echo "Is this OK? (Enter 'y' or 'n')" | |
117 | read -r ok | |
118 | case $ok in | |
119 | y ) | |
120 | ;; | |
121 | * ) | |
122 | echo | |
123 | echo "OK, didn't change anything." | |
124 | exit 0 | |
125 | ;; | |
126 | esac | |
127 | ||
128 | mkdir -p pkgconfdir | |
129 | ||
130 | rm -f pkgconfdir/config.new | |
131 | for root in $roots; do | |
132 | echo "collection fs $encoding $root" >> pkgconfdir/config.new | |
133 | done | |
134 | for scratch in slap.ogg scratch.ogg; do | |
135 | echo "scratch pkgdatadir/$scratch" >> pkgconfdir/config.new | |
136 | done | |
137 | echo "user $user" >> pkgconfdir/config.new | |
138 | if [ $port != none ]; then | |
139 | echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new | |
140 | fi | |
141 | ||
142 | echo | |
143 | echo "Proposed pkgconfdir/config:" | |
144 | sed < pkgconfdir/config.new 's/^/ /' | |
145 | echo | |
146 | echo "Is this OK? (Enter 'y' or 'n')" | |
147 | read -r ok | |
148 | case $ok in | |
149 | y ) | |
150 | ;; | |
151 | * ) | |
152 | echo | |
153 | echo "OK, not installing it." | |
154 | rm -f pkgconfdir/config.new | |
155 | exit 0 | |
156 | ;; | |
157 | esac | |
158 | echo | |
159 | echo "Installing pkgconfdir/config" | |
160 | mv pkgconfdir/config.new pkgconfdir/config | |
161 | ||
162 | echo "Making sure that pkgstatedir exists" | |
163 | mkdir -p pkgstatedir | |
164 | chown $user:$group pkgstatedir | |
165 | chmod 2755 pkgstatedir | |
166 | ||
167 | case $os in | |
168 | mac ) | |
169 | echo "Installing the plist into /Library/LaunchDaemons/" | |
170 | cp server/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/. | |
171 | echo "Reloading launchd" | |
172 | launchctl load /Library/LaunchDaemons | |
173 | echo "Starting DisOrder server" | |
174 | launchctl start uk.org.greenend.rjk.disorder | |
175 | ;; | |
176 | * ) | |
177 | echo "Sorry, I don't know how to install the server on this platform." | |
178 | echo "You will have to do that by hand." | |
179 | exit 1 | |
180 | ;; | |
181 | esac |