1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
#!/usr/bin/python3
## live-build(7) - Live System Build Components
## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.
import argparse
import configparser
import glob
import os
import platform
import shutil
import subprocess
import sys
import urllib.request
# TODO:
# * logfile output
# * lockfile handling
# * use gettext for i18n
def main():
## early defaults detection
architecture = platform.machine()
if (architecture == 'x86_64'):
architecture = 'amd64'
## Parsing Arguments
arguments = argparse.ArgumentParser(
prog = 'lb init',
usage = '%(prog)s [arguments]',
description = '''live-build contains the components to build a live system from a configuration directory.
The init command creates an empty configuration directory or reinitialize an existing one.''',
epilog = 'See \'man lb-init\' for more information.',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)
arguments.add_argument('--version', help='show program\'s version number and exit', action='version', version='live-build 4')
arguments.add_argument('--verbose', help='set verbose option', action='store_true')
arguments.add_argument('--project', help='set project defaults', default='debian')
arguments.add_argument('--system', help='set system type', default='live')
arguments.add_argument('--architecture', help='set system architecture', default=architecture)
arguments.add_argument('--archive-areas', help='set default archive areas', default='main')
arguments.add_argument('--parent-archive-areas', help='set default parent archive areas', default='main')
arguments.add_argument('--distribution', help='set default distribution', default='jessie')
arguments.add_argument('--parent-distribution', help='set default parent distribution', default='jessie')
arguments.add_argument('--mirror-bootstrap', help='set default bootstrap mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--parent-mirror-bootstrap', help='set default parent bootstrap mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--mirror-bootstrap-security', help='set default bootstrap security mirror', default='http://security.debian.org')
arguments.add_argument('--parent-mirror-bootstrap-security', help='set default parent security bootstrap mirror', default='http://security.debian.org')
arguments.add_argument('--mirror-chroot', help='set default chroot mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--parent-mirror-chroot', help='set default parent chroot mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--mirror-chroot-security', help='set default chroot security mirror', default='http://security.debian.org')
arguments.add_argument('--parent-mirror-chroot-security', help='set default parent chroot security mirror', default='http://security.debian.org')
arguments.add_argument('--mirror-installer', help='set default installer mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--parent-mirror-installer', help='set default parent installer mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--mirror-installer-security', help='set default installer security mirror', default='http://security.debian.org')
arguments.add_argument('--parent-mirror-installer-security', help='set default parent installer security mirror', default='http://security.debian.org')
arguments.add_argument('--mirror-binary', help='set default binary mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--parent-mirror-binary', help='set default parent binary mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--mirror-binary-security', help='set default binary security mirror', default='http://security.debian.org')
arguments.add_argument('--parent-mirror-binary-security', help='set default parent binary security mirror', default='http://security.debian.org')
arguments.add_argument('--mirror-source', help='set default source mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--parent-mirror-source', help='set default parent source mirror', default='http://ftp.debian.org/debian')
arguments.add_argument('--mirror-source-security', help='set default source security mirror', default='http://security.debian.org')
arguments.add_argument('--parent-mirror-source-security', help='set default parent source security mirror', default='http://security.debian.org')
args = arguments.parse_args()
# --verbose
verbose = args.verbose
# --project
project = args.project
# --system
system = args.system
# --architecture
architecture = args.architecture
# --archive-areas
archive_areas = args.archive_areas
# --parent-archive-areas
parent_archive_areas = args.parent_archive_areas
# --distribution
distribution = args.distribution
# --parent-distribution
parent_distribution = args.parent_distribution
# --mirror-bootstrap
mirror_bootstrap = args.mirror_bootstrap
# --parent-mirror-bootstrap
parent_mirror_bootstrap = args.parent_mirror_bootstrap
# --mirror-bootstrap-security
mirror_bootstrap_security = args.mirror_bootstrap_security
# --parent-mirror-bootstrap-security
parent_mirror_bootstrap_security = args.parent_mirror_bootstrap_security
# --mirror-chroot
mirror_chroot = args.mirror_chroot
# --parent-mirror-chroot
parent_mirror_chroot = args.parent_mirror_chroot
# --mirror-chroot-security
mirror_chroot_security = args.mirror_chroot_security
# --parent-mirror-chroot-security
parent_mirror_chroot_security = args.parent_mirror_chroot_security
# --mirror-installer
mirror_installer = args.mirror_installer
# --parent-mirror-installer
parent_mirror_installer = args.parent_mirror_installer
# --mirror-installer-security
mirror_installer_security = args.mirror_installer_security
# --parent-mirror-installer-security
parent_mirror_installer_security = args.parent_mirror_installer_security
# --mirror-binary
mirror_binary = args.mirror_binary
# --parent-mirror-binary
parent_mirror_binary = args.parent_mirror_binary
# --mirror-binary-security
mirror_binary_security = args.mirror_binary_security
# --parent-mirror-binary-security
parent_mirror_binary_security = args.parent_mirror_binary_security
# --mirror-source
mirror_source = args.mirror_source
# --parent-mirror-source
parent_mirror_source = args.parent_mirror_source
# --mirror-source-security
mirror_source_security = args.mirror_source_security
# --parent-mirror-source-security
parent_mirror_source_security = args.parent_mirror_source_security
## Setting defaults
if not system:
system = 'live'
if not project:
# FIXME: hardcoded project information
project = 'debian'
if not distribution:
# FIXME hardcoded release information
default_distribution = { 'debian' : 'jessie',
'progress-linux' : 'cairon',
}
distribution = default_distribution[project]
## Setting derivative defaults
if (project == 'progress-linux'):
# parent-distribution
if(distribution == 'artax'):
parent_distribution = 'squeeze'
if(distribution == 'artax-backports'):
parent_distribution = 'squeeze'
if(distribution == 'baureo'):
parent_distribution = 'wheezy'
if(distribution == 'baureo-backports'):
parent_distribution = 'wheezy'
if(distribution == 'cairon'):
parent_distribution = 'jessie'
if(distribution == 'cairon-backports'):
parent_distribution = 'jessie'
else:
# parent-architecture
parent_architecture = architecture
# parent-distribution
parent_distribution = distribution
# parent-mirror-bootstrap
parent_mirror_bootstrap = mirror_bootstrap
# parent-mirror-bootstrap-security
parent_mirror_bootstrap_security = mirror_bootstrap_security
# parent-mirror-chroot
parent_mirror_chroot = mirror_chroot
# parent-mirror-chroot-security
parent_mirror_chroot_security = mirror_chroot_security
# parent-mirror-installer
parent_mirror_installer = mirror_installer
# parent-mirror-installer-security
parent_mirror_installer_security = mirror_installer_security
# parent-mirror-binary
parent_mirror_binary = mirror_binary
# parent-mirror-binary-security
parent_mirror_binary_security = mirror_binary_security
# parent-mirror-source
parent_mirror_source = mirror_source
# parent-mirror-source-security
parent_mirror_source_security = mirror_source_security
## Creating configuration directory
# stagefile
if os.path.exists('.build/init'):
if verbose:
print('I: configuration directory already initialized - nothing to do')
# Notes:
# * until further tests, we do not allow to re-run lb init on an already initialized directory.
sys.exit(0)
# Print warning about live-build development version
print('WARNING: THIS VERSION OF LIVE-BUILD IS EXPERIMENTAL\n')
print('IT IS UNFINISHED AND CHANGES HEAVILY WITHOUT PRIOR NOTICE.')
print('USER DISCRETION IS ADVISED.\n')
print('Please also note that you are running a live-build development version')
print('and that we are only supporting the newest development version.\n')
print('Make sure you are using the newest version at all times.')
## Writing main configuration file
os.makedirs('config', exist_ok=True)
config = configparser.ConfigParser()
# build.conf
f = open('config/build.conf', 'w')
config.add_section('build')
config.set('build','architecture', architecture)
config.set('build','archive-areas', archive_areas)
config.set('build','parent-archive-areas', parent_archive_areas)
config.set('build','distribution', distribution)
config.set('build','parent-distribution', parent_distribution)
config.set('build','project', project)
config.set('build','system', system)
config.add_section('meta')
config.set('meta','version', '4.0')
config.write(f)
f.close()
# config/archives
os.makedirs('config/archives', exist_ok=True)
if (project == 'debian'):
# config/archives/debian.list.bootstrap
f = open('config/archives/debian.list.bootstrap', 'w')
f.write('deb ' + mirror_bootstrap + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_bootstrap_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_bootstrap + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/debian.list.chroot
f = open('config/archives/debian.list.chroot', 'w')
f.write('deb ' + mirror_chroot + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_chroot_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + mirror_chroot + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_chroot + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/debian.list.installer
f = open('config/archives/debian.list.installer', 'w')
f.write('deb ' + mirror_installer + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_installer_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + mirror_installer + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_installer + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/debian.list.binary
f = open('config/archives/debian.list.binary', 'w')
f.write('deb ' + mirror_binary + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_binary_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + mirror_binary + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_binary + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/debian.list.source
f = open('config/archives/debian.list.source', 'w')
f.write('deb ' + mirror_source + ' ' + distribution + ' ' + archive_areas + '\n'
'deb-src ' + mirror_source + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_source_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb-src ' + mirror_source_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + mirror_source + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb-src ' + mirror_source + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_source + ' ' + distribution + '-backports ' + archive_areas + '\n'
'deb-src ' + mirror_source + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
elif(project == 'progress-linux'):
# config/archives/debian.list.bootstrap
f = open('config/archives/debian.list.bootstrap', 'w')
f.write('deb ' + parent_mirror_bootstrap + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-backports' + archive_areas + '\n')
f.close()
# config/archives/debian.list.chroot
f = open('config/archives/debian.list.chroot', 'w')
f.write('deb ' + parent_mirror_chroot + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + parent_mirror_chroot_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-backports' + archive_areas + '\n')
f.close()
# config/archives/debian.list.installer
f = open('config/archives/debian.list.installer', 'w')
f.write('deb ' + parent_mirror_installer + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + parent_mirror_installer_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-backports' + archive_areas + '\n')
f.close()
# config/archives/debian.list.binary
f = open('config/archives/debian.list.binary', 'w')
f.write('deb ' + parent_mirror_binary + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + parent_mirror_binary_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-backports' + archive_areas + '\n')
f.close()
# config/archives/debian.list.source
f = open('config/archives/debian.list.source', 'w')
f.write('deb ' + parent_mirror_source + ' ' + distribution + ' ' + archive_areas + '\n'
'deb-src ' + parent_mirror_source + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + parent_mirror_source_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb-src ' + parent_mirror_source_security + ' ' + distribution + '/updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb-src ' + parent_mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + parent_mirror_bootstrap + ' ' + distribution + '-backports' + archive_areas + '\n'
'deb-src ' + parent_mirror_bootstrap + ' ' + distribution + '-backports' + archive_areas + '\n')
f.close()
# config/archives/project.list.bootstrap
f = open('config/archives/' + project + '.list.bootstrap', 'w')
f.write('deb ' + mirror_bootstrap + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_bootstrap_security + ' ' + distribution + '-security ' + archive_areas + '\n'
'deb ' + mirror_bootstrap + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_bootstrap + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/project.list.chroot
f = open('config/archives/' + project + '.list.chroot', 'w')
f.write('deb ' + mirror_chroot + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_chroot_security + ' ' + distribution + '-security ' + archive_areas + '\n'
'deb ' + mirror_chroot + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_chroot + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/project.list.installer
f = open('config/archives/' + project + '.list.installer', 'w')
f.write('deb ' + mirror_installer + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_installer_security + ' ' + distribution + '-security ' + archive_areas + '\n'
'deb ' + mirror_installer + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_installer + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/project.list.binary
f = open('config/archives/' + project + '.list.binary', 'w')
f.write('deb ' + mirror_binary + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_binary_security + ' ' + distribution + '-security ' + archive_areas + '\n'
'deb ' + mirror_binary + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_binary + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
# config/archives/project.list.source
f = open('config/archives/' + project + '.list.source', 'w')
f.write('deb ' + mirror_source + ' ' + distribution + ' ' + archive_areas + '\n'
'deb-src ' + mirror_source + ' ' + distribution + ' ' + archive_areas + '\n'
'deb ' + mirror_source_security + ' ' + distribution + '-security ' + archive_areas + '\n'
'deb-src ' + mirror_source_security + ' ' + distribution + '-security ' + archive_areas + '\n'
'deb ' + mirror_source + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb-src ' + mirror_source + ' ' + distribution + '-updates ' + archive_areas + '\n'
'deb ' + mirror_source + ' ' + distribution + '-backports ' + archive_areas + '\n'
'deb-src ' + mirror_source + ' ' + distribution + '-backports ' + archive_areas + '\n')
f.close()
## Populating configuration directory
# Configuring default archive-keys
if (project == 'progress-linux'):
# dependencies
if not os.path.isfile('/usr/bin/gpgv'):
print('E: /usr/bin/gpgv - no such file', file=sys.stderr)
if verbose:
print('I: gnupg can be obtained from:\n'
'I: http://www.gnupg.org/\n'
'I: On Debian based systems, gnupg can be installed with:\n'
'I: # sudo apt-get install gnupg')
sys.exit(1)
os.makedirs('config/archives', exist_ok=True)
# FIXME hardcoded release information
archive_keys_url = 'http://cdn.archive.progress-linux.org/packages/project/keys/'
archive_keys = { 'artax' : [ 'archive-key-1-artax.asc' , 'archive-key-1+-artax-backports.asc' ],
'artax-backports' : [ 'archive-key-1-artax.asc' , 'archive-key-1+-artax-backports.asc' ],
'baureo' : [ 'archive-key-2-baureo.asc' , 'archive-key-2+-baureo-backports.asc' ],
'baureo-backports' : [ 'archive-key-2-baureo.asc' , 'archive-key-2+-baureo-backports.asc' ],
'cairon' : [ 'archive-key-3-cairon.asc' , 'archive-key-3+-cairon-backports.asc' ],
'cairon-backports' : [ 'archive-key-3-cairon.asc' , 'archive-key-3+-cairon-backports.asc' ],
}
keys = archive_keys[distribution]
for key in keys:
url = archive_keys_url + key
target = os.path.splitext(os.path.basename(key))
if verbose:
print('I: Downloading ' + url)
r = urllib.request.urlopen(url)
f = open('config/archives/' + target[0] + '.key', 'w')
f.write(r.read())
# FIXME: download signatures and verify them against debian-keyring
# Configuring default hooks
os.makedirs('config/hooks', exist_ok=True)
for hook in glob.glob('/usr/share/live/build/hooks/all/*.hook*'):
os.symlink(hook, os.path.join('config/hooks/' + os.path.basename(hook)))
if os.path.exists('/usr/share/live/build/hooks/' + system):
for hook in glob.glob('/usr/share/live/build/hooks/' + system + '/*.hook*'):
os.symlink(hook, os.path.join('config/hooks/' + os.path.basename(hook)))
# Configuring default includes
os.makedirs('config/includes', exist_ok=True)
os.makedirs('config/includes.bootstrap', exist_ok=True)
os.makedirs('config/includes.chroot', exist_ok=True)
#os.makedirs('config/includes.installer', exist_ok=True) FIXME
os.makedirs('config/includes.binary', exist_ok=True)
os.makedirs('config/includes.source', exist_ok=True)
# Ensure correct include directory permissions avoiding tainting of target system
os.chmod('config/includes', 0o755)
os.chmod('config/includes.bootstrap', 0o755)
os.chmod('config/includes.chroot', 0o755)
#os.chmod('config/includes.installer', 0o755) FIXME
os.chmod('config/includes.binary', 0o755)
os.chmod('config/includes.source', 0o755)
# Configuring default package lists
os.makedirs('config/package-lists', exist_ok=True)
f = open('config/package-lists/live.list.chroot', 'w')
f.write('live-boot\n'
'live-config\n')
if(parent_distribution == 'wheezy'):
f.write('live-config-sysvinit\n')
else:
f.write('live-config-systemd\n')
f.close()
## stagefile
os.makedirs('.build', exist_ok=True)
open('.build/init', 'w').close()
if __name__ == '__main__':
main()
|