3 ## live-build(7) - Live System Build Components
4 ## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
23 # * use gettext for i18n
27 arguments = argparse.ArgumentParser(
28 prog = 'lb binary-hooks',
29 usage = '%(prog)s [arguments]',
30 description = '''live-build contains the components to build a live system from a configuration directory.
31 The binary-hooks command executes hook files after the binary stage.''',
32 epilog = 'See \'man lb-binary-hooks\' for more information.',
33 formatter_class = argparse.ArgumentDefaultsHelpFormatter
36 arguments.add_argument('--version', help='show program\'s version number and exit', action='version', version='live-build 4')
37 arguments.add_argument('--verbose', help='set verbose option', action='store_true')
39 args = arguments.parse_args()
42 verbose = args.verbose
44 ## Calling binary hooks
47 if os.path.isfile('.build/binary-hooks'):
49 print('I: binary-hooks already done - nothing to do')
54 if not os.path.isfile('.build/bootstrap'):
55 print('E: bootstrap stage missing - aborting', file=sys.stderr)
58 print('I: use \'lb bootstrap\' to bootstrap system')
63 if not glob.glob('config/hooks/*.hook') and not glob.glob('config/hooks/*.hook.binary'):
65 print ('I: no binary hooks found at config/hooks/*.hook{,.binary} - nothing to do')
69 # bind mount configuration directory
71 print('I: Mounting config to binary/live-build/config')
73 os.makedirs('binary/live-build/config', exist_ok=True)
75 mount = subprocess.check_call('mount -o bind config binary/live-build/config', shell=True)
76 remount = subprocess.check_call('mount -o remount,ro,bind binary/live-build/config', shell=True)
79 os.makedirs('binary/live-build', exist_ok=True)
81 hooks = glob.glob('config/hooks/*.hook') + glob.glob('config/hooks/*.hook.binary')
83 for hook in sorted(hooks):
85 print('I: Copying config/hooks/*.hook.binary to binary/live-build')
87 shutil.copy(hook, os.path.join('binary/live-build/' + os.path.basename(hook)), follow_symlinks=True)
90 print('I: Executing \' ' + hook + '\'')
93 exec_hook = subprocess.check_call('cd binary && live-build/' + os.path.basename(hook), shell=True)
94 os.remove('binary/live-build/' + os.path.basename(hook))
96 # unmount coniguration directory
97 umount = subprocess.check_call('umount binary/live-build/config', shell=True)
99 os.rmdir('binary/live-build/config')
100 os.rmdir('binary/live-build')
103 os.makedirs('.build', exist_ok=True)
104 open('.build/binary-hooks', 'w').close()
107 if __name__ == '__main__':