diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2013-11-04 17:31:41 +0100 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2013-11-04 17:51:36 +0100 |
commit | fee4e8b349cf7c126834df63548683a5814a4c74 (patch) | |
tree | f9b6a7235c15e3baf5024a878d07356c51088c03 /components | |
parent | 9987bdcc1a4e94e0d86d8d2632f9fa132a7800a6 (diff) | |
download | vyos-live-build-fee4e8b349cf7c126834df63548683a5814a4c74.tar.gz vyos-live-build-fee4e8b349cf7c126834df63548683a5814a4c74.zip |
Rewriting chroot_includes in python.
Diffstat (limited to 'components')
-rwxr-xr-x | components/chroot-includes | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/components/chroot-includes b/components/chroot-includes new file mode 100755 index 000000000..f4c5d46db --- /dev/null +++ b/components/chroot-includes @@ -0,0 +1,92 @@ +#!/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 chroot-includes', + usage = '%(prog)s [arguments]', + description = '''live-build contains the components to build a live system from a configuration directory. + The chroot-includes command copies include files into the chroot stage.''', + epilog = 'See \'man lb-chroot-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 chroot includes + + # stagefile + if os.path.isfile('.build/chroot-includes'): + if verbose: + print('I: chroot-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) + + # includes + if not glob.glob('config/includes/*') and not glob.glob('config/includes/.*') and not glob.glob('config/includes.chroot/*') and not glob.glob('config/includes.chroot/.*'): + if verbose: + print ('I: no chroot includes found at config/includes.chroot - nothing to do') + + sys.exit(0) + + # process includes + if glob.glob('config/includes/*') or glob.glob('config/includes/.*'): + hooks = glob.glob('config/includes/*') + glob.glob('config/includes/.*') + + if verbose: + print('I: Copying config/includes to') + + cpio = subprocess.call('cd config/includes && find . | cpio -dmpu --no-preserve-owner ../../chroot', shell=True) + + if glob.glob('config/includes.chroot/*') and not glob.glob('config/includes.chroot/.*'): + hooks = glob.glob('config/includes.chroot/*') + glob.glob('config/includes.chroot/.*') + + if verbose: + print('I: Copying config/includes.chroot to chroot') + + cpio = subprocess.call('cd config/includes.chroot && find . | cpio -dmpu --no-preserve-owner ../../chroot', shell=True) + + # stagefile + os.makedirs('.build', exist_ok=True) + open('.build/chroot-includes', 'w').close() + + +if __name__ == '__main__': + main() |