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 |
|
---|
25 |
import os |
---|
26 |
|
---|
27 |
FFADOSBI_VERSION = '0.1' |
---|
28 |
LATEST_FFADO_RELEASE_URL = 'http://www.ffado.org/files/libffado-2.0-beta7.tar.gz' |
---|
29 |
LATEST_FFADO_RELEASE_UNPACK_DIR = 'libffado-2.0-beta7' |
---|
30 |
LATEST_JACK1_RELEASE_URL = 'http://jackaudio.org/downloads/jack-audio-connection-kit-0.109.2.tar.gz' |
---|
31 |
LATEST_JACK1_RELEASE_UNPACK_DIR = 'jack-audio-connection-kit-0.109.2' |
---|
32 |
|
---|
33 |
def ask_for_dir(descr, suggestion): |
---|
34 |
ret_dir = None |
---|
35 |
while True: |
---|
36 |
ret_dir = raw_input("Please specify a %s directory [%s]: " % (descr, suggestion)) |
---|
37 |
if ret_dir == "": |
---|
38 |
ret_dir = suggestion |
---|
39 |
|
---|
40 |
if not os.path.exists(ret_dir): |
---|
41 |
try: |
---|
42 |
os.makedirs(ret_dir) |
---|
43 |
except: |
---|
44 |
yesno = raw_input("Could not create the %s directory. Try again? [yes/no] " % descr) |
---|
45 |
if yesno == "" or yesno[0] != 'y': |
---|
46 |
return None |
---|
47 |
else: |
---|
48 |
continue |
---|
49 |
break |
---|
50 |
else: |
---|
51 |
yesno = raw_input("WARNING: the %s directory at %s already exists. Do you want to overwrite it? [yes/no] " % (descr, ret_dir)) |
---|
52 |
if yesno == "" or yesno[0] != 'y': |
---|
53 |
yesno = raw_input("Specify new %s directory? [yes/no] " % descr) |
---|
54 |
if yesno == "" or yesno[0] != 'y': |
---|
55 |
return None |
---|
56 |
else: |
---|
57 |
continue |
---|
58 |
else: |
---|
59 |
yesno = raw_input("WARNING: about to remove the old %s directory at %s. Proceed? [yes/no] " % (descr, ret_dir)) |
---|
60 |
if yesno == "" or yesno[0] != 'y': |
---|
61 |
yesno = raw_input("Specify new %s directory? [yes/no] " % descr) |
---|
62 |
if yesno == "" or yesno[0] != 'y': |
---|
63 |
return None |
---|
64 |
else: |
---|
65 |
continue |
---|
66 |
else: |
---|
67 |
os.system('rm -Rf "%s"' % ret_dir) |
---|
68 |
os.makedirs(ret_dir) |
---|
69 |
break |
---|
70 |
return ret_dir |
---|
71 |
|
---|
72 |
def fetch_source(build_dir, source_descriptor, target): |
---|
73 |
logfile = "%s/%s.log" % (build_dir, target) |
---|
74 |
os.system('echo "" > %s' % logfile) |
---|
75 |
|
---|
76 |
if source_descriptor[1] == 'svn': |
---|
77 |
print( " Checking out SVN repository: %s" % source_descriptor[2] ) |
---|
78 |
cwd = os.getcwd() |
---|
79 |
os.chdir(build_dir) |
---|
80 |
retval = os.system('svn co "%s" "%s" >> %s' % (source_descriptor[2], target, logfile)) |
---|
81 |
os.chdir(cwd) |
---|
82 |
if retval: |
---|
83 |
print( " Failed to checkout the SVN repository. Inspect %s for details. (is subversion installed?)" % logfile ) |
---|
84 |
return False |
---|
85 |
return True |
---|
86 |
elif source_descriptor[1] == 'tar.gz': |
---|
87 |
print( " Downloading tarball: %s" % source_descriptor[2] ) |
---|
88 |
import urllib |
---|
89 |
tmp_file = '%s/tmp.tar.gz' % build_dir |
---|
90 |
try: |
---|
91 |
urllib.urlretrieve(source_descriptor[2], tmp_file) |
---|
92 |
except: |
---|
93 |
print( " Could not retrieve source tarball." ) |
---|
94 |
return False |
---|
95 |
cwd = os.getcwd() |
---|
96 |
os.chdir(build_dir) |
---|
97 |
print( " extracting tarball..." ) |
---|
98 |
retval = os.system('tar -zxf "%s" > %s' % (tmp_file, logfile)) |
---|
99 |
if retval: |
---|
100 |
print( " Failed to extract the source tarball. Inspect %s for details." % logfile ) |
---|
101 |
os.chdir(cwd) |
---|
102 |
return False |
---|
103 |
if source_descriptor[3]: |
---|
104 |
retval = os.system('mv "%s" "%s"' % (source_descriptor[3], target)) |
---|
105 |
if retval: |
---|
106 |
print( " Failed to move the extracted tarball" ) |
---|
107 |
os.chdir(cwd) |
---|
108 |
return False |
---|
109 |
os.chdir(cwd) |
---|
110 |
return True |
---|
111 |
else: |
---|
112 |
print( "bad source type" ) |
---|
113 |
return False |
---|
114 |
|
---|
115 |
|
---|
116 |
welcome_msg = """ |
---|
117 |
FFADO sandbox install utility """ + FFADOSBI_VERSION + """ |
---|
118 |
================================= |
---|
119 |
(C) 2008 Pieter Palmers |
---|
120 |
|
---|
121 |
This utility will automatically build and install a sandbox |
---|
122 |
environment that can be used to evaluate FFADO. The required |
---|
123 |
FFADO and/or jack packages are downloaded. |
---|
124 |
|
---|
125 |
NOTE: The build dependencies are not automatically installed. |
---|
126 |
Please consult http://subversion.ffado.org/wiki/Dependencies |
---|
127 |
for more information. The subversion tool has to be installed. |
---|
128 |
|
---|
129 |
NOTE: This tool assumes that an internet connection is available |
---|
130 |
while it runs. Once everything is built, no connection is |
---|
131 |
required. |
---|
132 |
|
---|
133 |
You can exit the tool at any time using CTRL-C. |
---|
134 |
|
---|
135 |
""" |
---|
136 |
|
---|
137 |
print( welcome_msg ) |
---|
138 |
|
---|
139 |
# get the paths to be used |
---|
140 |
if 'HOME' in os.environ.keys(): |
---|
141 |
suggestion_sandbox = "%s/ffadosandbox" % os.environ['HOME'] |
---|
142 |
else: |
---|
143 |
suggestion_sandbox = "/home/myuser/ffadosandbox" |
---|
144 |
|
---|
145 |
sandbox_dir_msg = """ |
---|
146 |
SANDBOX DIRECTORY |
---|
147 |
================= |
---|
148 |
|
---|
149 |
The sandbox directory is the directory where all built files are |
---|
150 |
installed into. It should be writable by your user, and will |
---|
151 |
contain the evaluation binaries if this tool is successful. If |
---|
152 |
it doesn't exist, it will be created. |
---|
153 |
|
---|
154 |
Once you are finished with evaluating FFADO you can simply remove |
---|
155 |
this directory and things are as if nothing happened. |
---|
156 |
|
---|
157 |
Suggestion: %s |
---|
158 |
|
---|
159 |
NOTE: if you specify a system directory here, the tool will install |
---|
160 |
system-wide (if run as root). This is not recommended, but can be |
---|
161 |
useful for automated installs. Uninstall will be a lot harder though. |
---|
162 |
""" % suggestion_sandbox |
---|
163 |
|
---|
164 |
if 'HOME' in os.environ.keys(): |
---|
165 |
suggestion_build = "%s/ffadobuild" % os.environ['HOME'] |
---|
166 |
else: |
---|
167 |
suggestion_build = "/home/myuser/ffadobuild" |
---|
168 |
|
---|
169 |
build_dir_msg = """ |
---|
170 |
BUILD DIRECTORY |
---|
171 |
=============== |
---|
172 |
|
---|
173 |
The build directory is where all temporary files are stored while |
---|
174 |
building FFADO and jack. It should be writable by your user. If |
---|
175 |
it doesn't exist, it will be created. |
---|
176 |
|
---|
177 |
The build directory can be removed as soon as this tool has finished. |
---|
178 |
It is not automatically removed. |
---|
179 |
|
---|
180 |
Suggestion: %s |
---|
181 |
""" % suggestion_build |
---|
182 |
|
---|
183 |
print( sandbox_dir_msg ) |
---|
184 |
sandbox_dir = ask_for_dir('sandbox', suggestion_sandbox) |
---|
185 |
if sandbox_dir == None: |
---|
186 |
print( "Cannot proceed without valid sandbox directory." ) |
---|
187 |
exit(-1) |
---|
188 |
print(" using %s as sandbox directory" % sandbox_dir) |
---|
189 |
|
---|
190 |
|
---|
191 |
print( build_dir_msg ) |
---|
192 |
build_dir = ask_for_dir('build', suggestion_build) |
---|
193 |
if build_dir == None: |
---|
194 |
print( "Cannot proceed without valid build directory." ) |
---|
195 |
exit(-1) |
---|
196 |
print(" using %s as build directory" % build_dir) |
---|
197 |
|
---|
198 |
# figure out what version of FFADO to build |
---|
199 |
# Note: format: |
---|
200 |
# ['title', type=svn or tar.gz, url, (optional) dir that contains target] |
---|
201 |
|
---|
202 |
ffado_versions = {} |
---|
203 |
ffado_versions[0] = ['SVN trunk', 'svn', 'http://subversion.ffado.org/ffado/trunk/libffado', None] |
---|
204 |
ffado_versions[1] = ['SVN libffado-2.0 (recommended)', 'svn', 'http://subversion.ffado.org/ffado/branches/libffado-2.0', None] |
---|
205 |
ffado_versions[2] = ['latest release', 'tar.gz', LATEST_FFADO_RELEASE_URL, LATEST_FFADO_RELEASE_UNPACK_DIR] |
---|
206 |
|
---|
207 |
ffado_versions_msg = """ |
---|
208 |
Available FFADO versions: |
---|
209 |
""" |
---|
210 |
for key in sorted(ffado_versions.keys()): |
---|
211 |
ffado_versions_msg += " %2s: %s\n" % (key, ffado_versions[key][0]) |
---|
212 |
|
---|
213 |
print( ffado_versions_msg ) |
---|
214 |
while True: |
---|
215 |
ffado_version = raw_input("Please select a FFADO version: ") |
---|
216 |
try: |
---|
217 |
ffado_version_int = eval(ffado_version) |
---|
218 |
if ffado_version_int not in [0, 1, 2]: |
---|
219 |
raise |
---|
220 |
except: |
---|
221 |
yesno = raw_input("Invalid FFADO version specified. Try again? [yes/no] ") |
---|
222 |
if yesno == "" or yesno[0] != 'y': |
---|
223 |
print( "Cannot proceed without valid FFADO version." ) |
---|
224 |
exit(-1) |
---|
225 |
else: |
---|
226 |
continue |
---|
227 |
break |
---|
228 |
|
---|
229 |
use_ffado_version = ffado_versions[ffado_version_int] |
---|
230 |
|
---|
231 |
# figure out what version of jack to build |
---|
232 |
jack_versions = {} |
---|
233 |
jack_versions[0] = ['jack1 SVN trunk', 'svn', 'http://subversion.jackaudio.org/jack/trunk/jack', None] |
---|
234 |
# note: latest release is no good. |
---|
235 |
#jack_versions[1] = ['jack1 latest release', 'tar.gz', LATEST_JACK1_RELEASE_URL, LATEST_JACK_RELEASE_UNPACK_DIR] |
---|
236 |
|
---|
237 |
jack_versions_msg = """ |
---|
238 |
Available jack versions: |
---|
239 |
""" |
---|
240 |
for key in sorted(jack_versions.keys()): |
---|
241 |
jack_versions_msg += " %2s: %s\n" % (key, jack_versions[key][0]) |
---|
242 |
|
---|
243 |
print( jack_versions_msg ) |
---|
244 |
while True: |
---|
245 |
jack_version = raw_input("Please select a jack version: ") |
---|
246 |
try: |
---|
247 |
jack_version_int = eval(jack_version) |
---|
248 |
if jack_version_int not in [0, 1, 2]: |
---|
249 |
raise |
---|
250 |
except: |
---|
251 |
yesno = raw_input("Invalid jack version specified. Try again? [yes/no] ") |
---|
252 |
if yesno == "" or yesno[0] != 'y': |
---|
253 |
print( "Cannot proceed without valid jack version." ) |
---|
254 |
exit(-1) |
---|
255 |
else: |
---|
256 |
continue |
---|
257 |
break |
---|
258 |
|
---|
259 |
use_jack_version = jack_versions[jack_version_int] |
---|
260 |
|
---|
261 |
# print( a summary ) |
---|
262 |
print( """ ) |
---|
263 |
SUMMARY |
---|
264 |
======= |
---|
265 |
Sandbox directory : %s |
---|
266 |
Build directory : %s |
---|
267 |
FFADO version : %s |
---|
268 |
Jack version : %s |
---|
269 |
|
---|
270 |
""" % (sandbox_dir, build_dir, use_ffado_version[0], use_jack_version[0]) |
---|
271 |
|
---|
272 |
# get the ffado source |
---|
273 |
print( "Fetching FFADO source..." ) |
---|
274 |
|
---|
275 |
if not fetch_source(build_dir, use_ffado_version, 'libffado'): |
---|
276 |
print( "Could not fetch FFADO source" ) |
---|
277 |
exit(-1) |
---|
278 |
print( " Successfully fetched FFADO source" ) |
---|
279 |
|
---|
280 |
print( "Fetching jack source..." ) |
---|
281 |
|
---|
282 |
if not fetch_source(build_dir, use_jack_version, 'jack'): |
---|
283 |
print( "Could not fetch jack source" ) |
---|
284 |
exit(-1) |
---|
285 |
print( " Successfully fetched jack source" ) |
---|
286 |
|
---|
287 |
cwd = os.getcwd() |
---|
288 |
|
---|
289 |
ffado_log = "%s/ffadobuild.log" % build_dir |
---|
290 |
ffado_scons_options = "-j2" # TODO: interactive config of the build |
---|
291 |
os.system('echo "" > %s' % ffado_log) |
---|
292 |
|
---|
293 |
# configure FFADO |
---|
294 |
os.chdir("%s/libffado/" % build_dir) |
---|
295 |
print( "Building FFADO..." ) |
---|
296 |
print( " Compiling..." ) |
---|
297 |
retval = os.system('scons PREFIX="%s" %s >> %s' % (sandbox_dir, ffado_scons_options, ffado_log)) |
---|
298 |
if retval: |
---|
299 |
print( """ ) |
---|
300 |
Failed to configure/build FFADO. Most likely this is due to uninstalled dependencies. |
---|
301 |
Check %s for details. |
---|
302 |
""" % ffado_log |
---|
303 |
exit(-1) |
---|
304 |
|
---|
305 |
# install FFADO |
---|
306 |
print( " Installing into %s..." % sandbox_dir ) |
---|
307 |
retval = os.system('scons install >> %s' % (ffado_log)) |
---|
308 |
if retval: |
---|
309 |
print( "Failed to install FFADO. Check %s for details." % ffado_log ) |
---|
310 |
exit(-1) |
---|
311 |
|
---|
312 |
# configure JACK |
---|
313 |
os.chdir("%s/jack/" % build_dir) |
---|
314 |
jack_log = "%s/jackbuild.log" % build_dir |
---|
315 |
os.system('echo "" > %s' % jack_log) |
---|
316 |
|
---|
317 |
print( "Building Jack..." ) |
---|
318 |
if use_jack_version[1] == 'svn': |
---|
319 |
print( " Initializing build system..." ) |
---|
320 |
retval = os.system('./autogen.sh >> %s' % jack_log) |
---|
321 |
if retval: |
---|
322 |
print( """ ) |
---|
323 |
Failed to initialize the jack build system. Most likely this is due to uninstalled dependencies. |
---|
324 |
Check %s for details. |
---|
325 |
""" % jack_log |
---|
326 |
exit(-1) |
---|
327 |
|
---|
328 |
print( " Configuring build..." ) |
---|
329 |
retval = os.system('./configure --prefix="%s" >> %s' % (sandbox_dir, jack_log)) |
---|
330 |
if retval: |
---|
331 |
print( """ ) |
---|
332 |
Failed to configure the jack build. Most likely this is due to uninstalled dependencies. |
---|
333 |
Check %s for details. |
---|
334 |
""" % jack_log |
---|
335 |
exit(-1) |
---|
336 |
|
---|
337 |
# build and install jack |
---|
338 |
print( " Compiling..." ) |
---|
339 |
retval = os.system('make >> %s' % (jack_log)) |
---|
340 |
if retval: |
---|
341 |
print( "Failed to build jack. Check %s for details." % jack_log ) |
---|
342 |
exit(-1) |
---|
343 |
|
---|
344 |
print( " Installing into %s..." % sandbox_dir ) |
---|
345 |
retval = os.system('make install >> %s' % (jack_log)) |
---|
346 |
if retval: |
---|
347 |
print( "Failed to install jack. Check %s for details." % jack_log ) |
---|
348 |
exit(-1) |
---|
349 |
|
---|
350 |
# write the bashrc file |
---|
351 |
sandbox_bashrc = """ |
---|
352 |
#!/bin/bash |
---|
353 |
# |
---|
354 |
|
---|
355 |
LD_LIBRARY_PATH="%s/lib:$LD_LIBRARY_PATH" |
---|
356 |
PKG_CONFIG_PATH="%s/lib/pkgconfig:$PKG_CONFIG_PATH" |
---|
357 |
PATH="%s/bin:$PATH" |
---|
358 |
|
---|
359 |
export LD_LIBRARY_PATH |
---|
360 |
export PKG_CONFIG_PATH |
---|
361 |
export PATH |
---|
362 |
""" % (sandbox_dir, sandbox_dir, sandbox_dir) |
---|
363 |
|
---|
364 |
print( "Writing shell configuration file..." ) |
---|
365 |
sandbox_rc_file = "%s/ffado.rc" % sandbox_dir |
---|
366 |
try: |
---|
367 |
fid = open(sandbox_rc_file, "w") |
---|
368 |
fid.write(sandbox_bashrc) |
---|
369 |
fid.close() |
---|
370 |
except: |
---|
371 |
print( "Could not write the sandbox rc file." ) |
---|
372 |
exit(-1) |
---|
373 |
|
---|
374 |
os.chdir(cwd) |
---|
375 |
|
---|
376 |
print( """ ) |
---|
377 |
FFADO and jack are installed into %s. If you want to use the |
---|
378 |
versions in the sandbox, you have to alter your environment |
---|
379 |
such that it uses them instead of the system versions. |
---|
380 |
|
---|
381 |
If you use the bash shell (or compatible) you can use the following |
---|
382 |
rc script: %s. The procedure to use the sandboxed ffado+jack would be: |
---|
383 |
|
---|
384 |
$ source %s |
---|
385 |
$ jackd -R -d firewire |
---|
386 |
|
---|
387 |
If you don't use the bash shell, you have to alter your environment |
---|
388 |
manually. Look at the %s script for inspiration. |
---|
389 |
|
---|
390 |
Note that you have to source the settings script for every terminal |
---|
391 |
you open. If you want a client application to use the sandboxed jack |
---|
392 |
you have to source the settings. |
---|
393 |
|
---|
394 |
E.g.: |
---|
395 |
terminal 1: |
---|
396 |
$ source %s |
---|
397 |
$ jackd -R -d firewire |
---|
398 |
terminal 2: |
---|
399 |
$ source %s |
---|
400 |
$ ardour2 |
---|
401 |
terminal 3: |
---|
402 |
$ source %s |
---|
403 |
$ qjackctl & |
---|
404 |
$ hydrogen |
---|
405 |
|
---|
406 |
If you want to use the sandboxed version as default, you have to ensure |
---|
407 |
that the default environment is changed. This can be done e.g. by adding |
---|
408 |
the settings script to ~/.bashrc. |
---|
409 |
|
---|
410 |
The build directory %s can now be deleted. To uninstall this sandbox, delete |
---|
411 |
the %s directory. |
---|
412 |
""" % (sandbox_dir, sandbox_rc_file, sandbox_rc_file, \ |
---|
413 |
sandbox_rc_file, sandbox_rc_file, sandbox_rc_file, \ |
---|
414 |
sandbox_rc_file, build_dir, sandbox_dir) |
---|