summaryrefslogtreecommitdiff
path: root/components/binary-includes
blob: 8e19e822d4a28e205260ba4904bda85387008bb4 (plain)
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
#!/usr/bin/python3

## live-build(7) - Live System Build Components
## Copyright (C) 2006-2013 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 shutil
import subprocess
import sys


# TODO:
#   * logfile output
#   * lockfile handling
#   * use gettext for i18n
#   * derefence or remove symlinks if binary filesystem does not support them

def main():
	## Parsing Arguments
	arguments = argparse.ArgumentParser(
		prog            = 'lb binary-includes',
		usage           = '%(prog)s [arguments]',
		description     = '''live-build contains the components to build a live system from a configuration directory.
		                     The binary-includes command copies include files into the binary stage.''',
		epilog          = 'See \'man lb-binary-includes\' 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')

	args = arguments.parse_args()

	# --verbose
	verbose = args.verbose

	## Copying binary includes

	# stagefile
	if os.path.isfile('.build/binary-includes'):
		if verbose:
			print('I: binary-includes already done - nothing to do')

		sys.exit(0)

	# dependencies
	if not os.path.isfile('.build/bootstrap'):
		print('E: bootstrap stage missing - aborting', file=sys.stderr)

		if verbose:
			print('I: use \'lb bootstrap\' to bootstrap system')

		sys.exit(1)

	if not os.path.isfile('/bin/cpio'):
		print('E: /bin/cpio - no such file', file=sys.stderr)

		if verbose:
			print('I: cpio can be obtained from:\n'
			      'I:   http://www.gnu.org/software/cpio/\n'
			      'I:   http://ftp.gnu.org/gnu/cpio/\n'
			      'I: On Debian based systems, cpio can be installed with:\n'
			      'I:   # sudo apt-get install cpio')

		sys.exit(1)

	# includes
	if not glob.glob('config/includes/*') and not glob.glob('config/includes/.*') and not glob.glob('config/includes.binary/*') and not glob.glob('config/includes.binary/.*'):
		if verbose:
			print ('I: no binary includes found at config/includes{,.binary} - nothing to do')

		sys.exit(0)

	# process includes
	if glob.glob('config/includes/*') or glob.glob('config/includes/.*'):
		if verbose:
			print('I: Copying config/includes to binary')

		cpio = subprocess.call('cd config/includes && find . | cpio -dmpu --no-preserve-owner ../../binary', shell=True)

	if glob.glob('config/includes.binary/*') or glob.glob('config/includes.binary/.*'):
		if verbose:
			print('I: Copying config/includes.binary to binary')

		cpio = subprocess.call('cd config/includes.binary && find . | cpio -dmpu --no-preserve-owner ../../binary', shell=True)

	# stagefile
	os.makedirs('.build', exist_ok=True)
	open('.build/binary-includes', 'w').close()


if __name__ == '__main__':
	main()