1 |
#!/usr/bin/python |
---|
2 |
# |
---|
3 |
|
---|
4 |
# |
---|
5 |
# Copyright (C) 2008 Pieter Palmers |
---|
6 |
# |
---|
7 |
# This program is free software: you can redistribute it and/or modify |
---|
8 |
# it under the terms of the GNU General Public License as published by |
---|
9 |
# the Free Software Foundation, version 3 of the License. |
---|
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 |
# |
---|
16 |
# You should have received a copy of the GNU General Public License |
---|
17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 |
# |
---|
19 |
|
---|
20 |
# |
---|
21 |
# A script to install FFADO in a 'sandbox', i.e. without changing the |
---|
22 |
# system installation. |
---|
23 |
# |
---|
24 |
import os |
---|
25 |
|
---|
26 |
FFADOSBI_VERSION = '0.1' |
---|
27 |
LATEST_FFADO_RELEASE_URL = 'http://www.ffado.org/files/libffado-2.0-beta6.tar.gz' |
---|
28 |
LATEST_FFADO_RELEASE_UNPACK_DIR = 'libffado-2.0-beta6' |
---|
29 |
LATEST_JACK1_RELEASE_URL = 'http://jackaudio.org/downloads/jack-audio-connection-kit-0.109.2.tar.gz' |
---|
30 |
LATEST_JACK1_RELEASE_UNPACK_DIR = 'jack-audio-connection-kit-0.109.2' |
---|
31 |
|
---|
32 |
def ask_for_dir(descr): |
---|
33 |
ret_dir = None |
---|
34 |
while True: |
---|
35 |
ret_dir = raw_input("Please specify a %s directory: " % descr) |
---|
36 |
|
---|
37 |
if not os.path.exists(ret_dir): |
---|
38 |
try: |
---|
39 |
os.makedirs(ret_dir) |
---|
40 |
except: |
---|
41 |
yesno = raw_input("Could not create the %s directory. Try again? [yes/no] " % descr) |
---|
42 |
if yesno[0] != 'y': |
---|
43 |
return None |
---|
44 |
else: |
---|
45 |
continue |
---|
46 |
break |
---|
47 |
else: |
---|
48 |
yesno = raw_input("WARNING: the %s directory already exists. Do you want to overwrite it? [yes/no] " % descr) |
---|
49 |
if yesno[0] != 'y': |
---|
50 |
yesno = raw_input("Try again? [yes/no] ") |
---|
51 |
if yesno[0] != 'y': |
---|
52 |
return None |
---|
53 |
else: |
---|
54 |
continue |
---|
55 |
else: |
---|
56 |
os.system('rm -Rf "%s"' % ret_dir) |
---|
57 |
os.makedirs(ret_dir) |
---|
58 |
break |
---|
59 |
return ret_dir |
---|
60 |
|
---|
61 |
def fetch_source(build_dir, source_descriptor, target): |
---|
62 |
if source_descriptor[1] == 'svn': |
---|
63 |
print " checking out SVN repository: %s" % source_descriptor[2] |
---|
64 |
cwd = os.getcwd() |
---|
65 |
os.chdir(build_dir) |
---|
66 |
os.system('svn co "%s" "%s"' % (source_descriptor[2], target)) |
---|
67 |
os.chdir(cwd) |
---|
68 |
return True |
---|
69 |
elif source_descriptor[1] == 'tar.gz': |
---|
70 |
print " downloading tarball: %s" % source_descriptor[2] |
---|
71 |
import urllib |
---|
72 |
tmp_file = '%s/tmp.tar.gz' % build_dir |
---|
73 |
urllib.urlretrieve(source_descriptor[2], tmp_file) |
---|
74 |
cwd = os.getcwd() |
---|
75 |
os.chdir(build_dir) |
---|
76 |
print " extracting tarball..." |
---|
77 |
os.system('tar -zxf "%s"' % tmp_file) |
---|
78 |
if source_descriptor[3]: |
---|
79 |
os.system('mv "%s" "%s"' % (source_descriptor[3], target)) |
---|
80 |
os.chdir(cwd) |
---|
81 |
return True |
---|
82 |
else: |
---|
83 |
print "bad source type" |
---|
84 |
return False |
---|
85 |
|
---|
86 |
welcome_msg = """ |
---|
87 |
FFADO sandbox install utility """ + FFADOSBI_VERSION + """ |
---|
88 |
================================= |
---|
89 |
(C) 2008 Pieter Palmers |
---|
90 |
|
---|
91 |
This utility will automatically build and install a sandbox |
---|
92 |
environment that can be used to evaluate FFADO. The required |
---|
93 |
FFADO and/or jack packages are downloaded. |
---|
94 |
|
---|
95 |
NOTE: The build dependencies are not automatically installed. |
---|
96 |
Please consult http://subversion.ffado.org/wiki/Dependencies |
---|
97 |
for more information. The subversion tool has to be installed. |
---|
98 |
|
---|
99 |
NOTE: This tool assumes that an internet connection is available |
---|
100 |
while it runs. Once everything is built, no connection is |
---|
101 |
required. |
---|
102 |
|
---|
103 |
You can exit the tool at any time using CTRL-C. |
---|
104 |
|
---|
105 |
""" |
---|
106 |
|
---|
107 |
print welcome_msg |
---|
108 |
|
---|
109 |
# get the paths to be used |
---|
110 |
if 'HOME' in os.environ.keys(): |
---|
111 |
suggestion = "%s/ffadosandbox" % os.environ['HOME'] |
---|
112 |
else: |
---|
113 |
suggestion = "/home/myuser/ffadosandbox" |
---|
114 |
|
---|
115 |
sandbox_dir_msg = """ |
---|
116 |
SANDBOX DIRECTORY |
---|
117 |
================= |
---|
118 |
|
---|
119 |
The sandbox directory is the directory where all built files are |
---|
120 |
installed into. It should be writable by your user, and will |
---|
121 |
contain the evaluation binaries if this tool is successful. If |
---|
122 |
it doesn't exist, it will be created. |
---|
123 |
|
---|
124 |
Once you are finished with evaluating FFADO you can simply remove |
---|
125 |
this directory and things are as if nothing happened. |
---|
126 |
|
---|
127 |
Suggestion: %s |
---|
128 |
|
---|
129 |
NOTE: if you specify a system directory here, the tool will install |
---|
130 |
system-wide (if run as root). This is not recommended, but can be |
---|
131 |
useful for automated installs. Uninstall will be a lot harder though. |
---|
132 |
""" % suggestion |
---|
133 |
|
---|
134 |
if 'HOME' in os.environ.keys(): |
---|
135 |
suggestion = "%s/ffadobuild" % os.environ['HOME'] |
---|
136 |
else: |
---|
137 |
suggestion = "/home/myuser/ffadobuild" |
---|
138 |
|
---|
139 |
build_dir_msg = """ |
---|
140 |
BUILD DIRECTORY |
---|
141 |
=============== |
---|
142 |
|
---|
143 |
The build directory is where all temporary files are stored while |
---|
144 |
building FFADO and jack. It should be writable by your user. If |
---|
145 |
it doesn't exist, it will be created. |
---|
146 |
|
---|
147 |
The build directory can be removed as soon as this tool has finished. |
---|
148 |
It is not automatically removed. |
---|
149 |
|
---|
150 |
Suggestion: %s |
---|
151 |
""" % suggestion |
---|
152 |
|
---|
153 |
print sandbox_dir_msg |
---|
154 |
sandbox_dir = ask_for_dir('sandbox') |
---|
155 |
if sandbox_dir == None: |
---|
156 |
print "Cannot proceed without valid sandbox directory." |
---|
157 |
exit(-1) |
---|
158 |
print(" using %s as sandbox directory" % sandbox_dir) |
---|
159 |
|
---|
160 |
|
---|
161 |
print build_dir_msg |
---|
162 |
build_dir = ask_for_dir('build') |
---|
163 |
if build_dir == None: |
---|
164 |
print "Cannot proceed without valid build directory." |
---|
165 |
exit(-1) |
---|
166 |
print(" using %s as build directory" % build_dir) |
---|
167 |
|
---|
168 |
# figure out what version of FFADO to build |
---|
169 |
# Note: format: |
---|
170 |
# ['title', type=svn or tar.gz, url, (optional) dir that contains target] |
---|
171 |
|
---|
172 |
ffado_versions = {} |
---|
173 |
ffado_versions[0] = ['SVN trunk', 'svn', 'http://subversion.ffado.org/ffado/trunk/libffado', None] |
---|
174 |
ffado_versions[1] = ['libffado-2.0 (recommended)', 'svn', 'http://subversion.ffado.org/ffado/branches/libffado-2.0', None] |
---|
175 |
ffado_versions[2] = ['latest release', 'tar.gz', LATEST_FFADO_RELEASE_URL, LATEST_FFADO_RELEASE_UNPACK_DIR] |
---|
176 |
|
---|
177 |
ffado_versions_msg = """ |
---|
178 |
Available FFADO versions: |
---|
179 |
""" |
---|
180 |
for key in sorted(ffado_versions.keys()): |
---|
181 |
ffado_versions_msg += " %2s: %s\n" % (key, ffado_versions[key][0]) |
---|
182 |
|
---|
183 |
print ffado_versions_msg |
---|
184 |
while True: |
---|
185 |
ffado_version = raw_input("Please select a FFADO version: ") |
---|
186 |
try: |
---|
187 |
ffado_version_int = eval(ffado_version) |
---|
188 |
if ffado_version_int not in [0, 1, 2]: |
---|
189 |
raise |
---|
190 |
except: |
---|
191 |
yesno = raw_input("Invalid FFADO version specified. Try again? [yes/no] ") |
---|
192 |
if yesno[0] != 'y': |
---|
193 |
print "Cannot proceed without valid FFADO version." |
---|
194 |
exit(-1) |
---|
195 |
else: |
---|
196 |
continue |
---|
197 |
break |
---|
198 |
|
---|
199 |
use_ffado_version = ffado_versions[ffado_version_int] |
---|
200 |
|
---|
201 |
# figure out what version of jack to build |
---|
202 |
jack_versions = {} |
---|
203 |
jack_versions[0] = ['jack1 SVN trunk', 'svn', 'http://subversion.jackaudio.org/jack/trunk/jack', None] |
---|
204 |
# note: latest release is no good. |
---|
205 |
#jack_versions[1] = ['jack1 latest release', 'tar.gz', LATEST_JACK1_RELEASE_URL, LATEST_JACK_RELEASE_UNPACK_DIR] |
---|
206 |
|
---|
207 |
jack_versions_msg = """ |
---|
208 |
Available jack versions: |
---|
209 |
""" |
---|
210 |
for key in sorted(jack_versions.keys()): |
---|
211 |
jack_versions_msg += " %2s: %s\n" % (key, jack_versions[key][0]) |
---|
212 |
|
---|
213 |
print jack_versions_msg |
---|
214 |
while True: |
---|
215 |
jack_version = raw_input("Please select a jack version: ") |
---|
216 |
try: |
---|
217 |
jack_version_int = eval(jack_version) |
---|
218 |
if jack_version_int not in [0, 1, 2]: |
---|
219 |
raise |
---|
220 |
except: |
---|
221 |
yesno = raw_input("Invalid jack version specified. Try again? [yes/no] ") |
---|
222 |
if yesno[0] != 'y': |
---|
223 |
print "Cannot proceed without valid jack version." |
---|
224 |
exit(-1) |
---|
225 |
else: |
---|
226 |
continue |
---|
227 |
break |
---|
228 |
|
---|
229 |
use_jack_version = jack_versions[jack_version_int] |
---|
230 |
|
---|
231 |
# print a summary |
---|
232 |
print """ |
---|
233 |
SUMMARY |
---|
234 |
======= |
---|
235 |
Sandbox directory : %s |
---|
236 |
Build directory : %s |
---|
237 |
FFADO version : %s |
---|
238 |
Jack version : %s |
---|
239 |
|
---|
240 |
""" % (sandbox_dir, build_dir, use_ffado_version[0], use_jack_version[0]) |
---|
241 |
|
---|
242 |
# get the ffado source |
---|
243 |
print "Fetching FFADO source..." |
---|
244 |
|
---|
245 |
if not fetch_source(build_dir, use_ffado_version, 'libffado'): |
---|
246 |
print "Could not fetch FFADO source" |
---|
247 |
exit(-1) |
---|
248 |
print " got FFADO source" |
---|
249 |
|
---|
250 |
print "Fetching jack source..." |
---|
251 |
|
---|
252 |
if not fetch_source(build_dir, use_jack_version, 'jack'): |
---|
253 |
print "Could not fetch jack source" |
---|
254 |
exit(-1) |
---|
255 |
print " got jack source" |
---|
256 |
|
---|
257 |
cwd = os.getcwd() |
---|
258 |
# configure FFADO |
---|
259 |
os.chdir("%s/libffado/" % build_dir) |
---|
260 |
os.system('scons PREFIX="%s"' % sandbox_dir) |
---|
261 |
|
---|
262 |
# install FFADO |
---|
263 |
os.system('scons install') |
---|
264 |
|
---|
265 |
# configure JACK |
---|
266 |
os.chdir("%s/jack/" % build_dir) |
---|
267 |
if use_jack_version[1] == 'svn': |
---|
268 |
os.system('./autogen.sh') |
---|
269 |
os.system('./configure --prefix="%s"' % sandbox_dir) |
---|
270 |
|
---|
271 |
# build and install jack |
---|
272 |
os.system('make') |
---|
273 |
os.system('make install') |
---|
274 |
|
---|
275 |
# write the bashrc file |
---|
276 |
sandbox_bashrc = """ |
---|
277 |
#!/bin/bash |
---|
278 |
# |
---|
279 |
|
---|
280 |
LD_LIBRARY_PATH="%s/lib:$LD_LIBRARY_PATH" |
---|
281 |
PKG_CONFIG_PATH="%s/lib/pkgconfig:$PKG_CONFIG_PATH" |
---|
282 |
PATH="%s/bin:$PATH" |
---|
283 |
|
---|
284 |
export LD_LIBRARY_PATH |
---|
285 |
export PKG_CONFIG_PATH |
---|
286 |
export PATH |
---|
287 |
""" % (sandbox_dir, sandbox_dir, sandbox_dir) |
---|
288 |
|
---|
289 |
sandbox_rc_file = "%s/ffado.rc" % sandbox_dir |
---|
290 |
|
---|
291 |
fid = open(sandbox_rc_file, "w") |
---|
292 |
fid.write(sandbox_bashrc) |
---|
293 |
fid.close() |
---|
294 |
|
---|
295 |
os.chdir(cwd) |
---|
296 |
|
---|
297 |
print """ |
---|
298 |
FFADO and jack are installed into %s. If you want to use the |
---|
299 |
versions in the sandbox, you have to alter your environment |
---|
300 |
such that it uses them instead of the system versions. |
---|
301 |
|
---|
302 |
If you use the bash shell (or compatible) you can use the following |
---|
303 |
rc script: %s. The procedure to use the sandboxed ffado+jack would be: |
---|
304 |
|
---|
305 |
$ source %s |
---|
306 |
$ jackd -R -d firewire |
---|
307 |
|
---|
308 |
If you don't use the bash shell, you have to alter your environment |
---|
309 |
manually. Look at the %s script for inspiration. |
---|
310 |
|
---|
311 |
Note that you have to source the settings script for every terminal |
---|
312 |
you open. If you want a client application to use the sandboxed jack |
---|
313 |
you have to source the settings. |
---|
314 |
|
---|
315 |
E.g.: |
---|
316 |
terminal 1: |
---|
317 |
$ source %s |
---|
318 |
$ jackd -R -d firewire |
---|
319 |
terminal 2: |
---|
320 |
$ source %s |
---|
321 |
$ ardour2 |
---|
322 |
terminal 3: |
---|
323 |
$ source %s |
---|
324 |
$ qjackctl & |
---|
325 |
$ hydrogen |
---|
326 |
|
---|
327 |
If you want to use the sandboxed version as default, you have to ensure |
---|
328 |
that the default environment is changed. This can be done e.g. by adding |
---|
329 |
the settings script to ~/.bashrc. |
---|
330 |
|
---|
331 |
The build directory %s can now be deleted. To uninstall this sandbox, delete |
---|
332 |
the %s directory. |
---|
333 |
""" % (sandbox_dir, sandbox_rc_file, sandbox_rc_file, \ |
---|
334 |
sandbox_rc_file, sandbox_rc_file, sandbox_rc_file, \ |
---|
335 |
sandbox_rc_file, build_dir, sandbox_dir) |
---|