summaryrefslogtreecommitdiff
path: root/components/init
blob: c1dba21dc346f8ac50eda5ba786babc56b0c15e6 (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
#!/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

def main():
	## 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 tree 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')

	args = arguments.parse_args()

	# --verbose
	verbose = args.verbose

	# --project
	project = args.project

	## Creating configuration directory

	# stagefile
	if os.path.isdir('.build'):
		if verbose:
			print('I: configuration directory already initialized - nothing to do')

		# Note: until further tests, we do not allow to re-run lb init on an already initialized directory.
		sys.exit(0)

	# Configuring default hooks
	os.makedirs('config/hooks', exist_ok=True)

	for hook in glob.glob('/usr/share/live/build/hooks/*.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.binary', exist_ok=True)
	os.makedirs('config/includes.source', exist_ok=True)

	# Configuring default package lists
	os.makedirs('config/package-lists', exist_ok=True)

	f = open('config/package-lists/live.list.chroot', 'a')
	f.write('live-boot\nlive-config\nlive-config-sysvinit\n')
	f.close()

	## stagefile
	os.makedirs('.build', exist_ok=True)


if __name__ == '__main__':
	main()