diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2014-08-27 23:14:12 +0200 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2014-08-28 00:59:28 +0200 |
commit | bc50443cf043616c7087f383e11bf85cd233c54e (patch) | |
tree | d7a6c03bc3207f809f4ca4ab13f079f02df28acf /components/bootstrap-cdebootstrap | |
parent | 5fc57865a4124c4432333cb73468ac2494e91d75 (diff) | |
download | vyos-live-build-bc50443cf043616c7087f383e11bf85cd233c54e.tar.gz vyos-live-build-bc50443cf043616c7087f383e11bf85cd233c54e.zip |
Moving partial python rewrite to separate branch, let's do it in the jessie+1 cycle rather than go with the current mixed code.
Diffstat (limited to 'components/bootstrap-cdebootstrap')
-rwxr-xr-x | components/bootstrap-cdebootstrap | 183 |
1 files changed, 0 insertions, 183 deletions
diff --git a/components/bootstrap-cdebootstrap b/components/bootstrap-cdebootstrap deleted file mode 100755 index 59c83c8df..000000000 --- a/components/bootstrap-cdebootstrap +++ /dev/null @@ -1,183 +0,0 @@ -#!/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 shutil -import subprocess -import sys - - -# TODO: -# * logfile output -# * lockfile handling -# * use gettext for i18n -# * cdebootstrap-options from config/options/cdebootstrap -# * take mirrors from config/archives/mirror.{bootstrap,chroot} - -def main(): - ## Parsing Arguments - arguments = argparse.ArgumentParser( - prog = 'lb bootstrap-cdebootstrap', - usage = '%(prog)s [arguments]', - description = '''live-build contains the components to build a live system from a configuration directory. - The bootstrap-cdebootstrap command bootstraps the chroot system with cdebootstrap.''', - epilog = 'See \'man lb-bootstrap-cdebootstrap\' 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('--cdebootstrap-options', help='set cdebootstrap(1) options' ) - - args = arguments.parse_args() - - ## Parsing Configuration - if not os.path.isfile('config/build'): - print('E: config/build - no such file', file=sys.stderr) - - sys.exit(1) - - config = configparser.ConfigParser() - - config.read('config/build') - - try: - architecture = config.get('Image', 'Architecture') - distribution = config.get('Image', 'Parent-Distribution') - mirror_bootstrap = config.get('Image', 'Parent-Mirror-Bootstrap') - except: - distribution = config.get('Image', 'Distribution') - mirror_bootstrap = config.get('Image', 'Mirror-Bootstrap') - - # --verbose - verbose = args.verbose - - # --cdebootstrap-options - cdebootstrap_options_late = distribution + ' chroot ' + mirror_bootstrap - - cdebootstrap_options_early = '' - - if (architecture) and (not architecture == 'auto'): - cdebootstrap_options_early = cdebootstrap_options_early + ' --arch=' + architecture - - if args.cdebootstrap_options: - cdebootstrap_options = cdebootstrap_options_early + ' ' + args.cdebootstrap_options + ' ' + cdebootstrap_options_late - else: - cdebootstrap_options = cdebootstrap_options_early + ' ' + cdebootstrap_options_late - - ## Calling cdebootstrap - - # stagefile - if os.path.isfile('.build/bootstrap'): - if verbose: - print('I: bootstrap already done - nothing to do') - - sys.exit(0) - - # dependencies - if not os.path.isfile('/usr/bin/cdebootstrap'): - print('E: /usr/bin/cdebootstrap - no such file', file=sys.stderr) - - if verbose: - print('I: cdebootstrap can be obtained from:\n' - 'I: http://anonscm.debian.org/gitweb/?p=users/waldi/cdebootstrap.git\n' - 'I: http://ftp.debian.org/debian/pool/main/c/cdebootstrap/\n' - 'I: On Debian based systems, cdebootstrap can be installed with:\n' - 'I: # sudo apt-get install cdebootstrap') - - sys.exit(1) - - # clean - if os.path.exists('chroot'): - print('E: chroot already exists - unclean build', file=sys.stderr) - - if verbose: - print('I: use \'lb clean\' to clean up a previously incomplete build') - - sys.exit(1) - - # stage cache - if os.path.exists('cache/bootstrap'): - if verbose: - print('I: Copying cache/bootstrap to chroot') - - # Notes: - # * there's no Python equivalent to 'cp -a' that handels both symlinks and device nodes properly. - cache = subprocess.check_call('cp -a cache/bootstrap chroot', shell=True) - - os.makedirs('.build', exist_ok=True) - open('.build/bootstrap', 'w').close() - - sys.exit(0) - - # packages cache - if glob.glob('cache/packages.bootstrap/*.deb'): - if verbose: - print('I: Copying cache/packages.bootstrap/*.deb to chroot/var/cache/bootstrap/*.deb') - - # Notes: - # * copy instead of move to make cache survive incomplete build - os.makedirs('chroot/var/cache/bootstrap', exist_ok=True) - - for package in glob.glob('cache/packages.bootstrap/*.deb'): - os.link(package, os.path.join('chroot/var/cache/bootstrap/' + os.path.basename(package))) - else: - # cdebootstrap - if verbose: - print('I: Calling \'/usr/bin/debootstrap --download-only ' + cdebootstrap_options + '\'') - - # Notes: - # * calling cdebootstrap twice: - # - to use already downloaded /var/cache/bootstrap/*.deb on incomplete builds - # - to use /var/cache/boottrap/*.deb for debian-installer - cdebootstrap = subprocess.check_call('/usr/bin/cdebootstrap --download-only ' + cdebootstrap_options, shell=True) - - # package cache - if glob.glob('chroot/var/cache/bootstrap/*.deb'): - if verbose: - print('I: Copying chroot/var/cache/bootstrap/*.deb to cache/packages.bootstrap') - - # Notes: - # * remove first to keep cache minimal - # * remove files instead of directory to work with symlinked directory - for package in glob.glob('cache/packages.bootstrap/*.deb'): - os.remove(package) - - os.makedirs('cache/packages.bootstrap', exist_ok=True) - - for package in glob.glob('chroot/var/cache/bootstrap/*.deb'): - shutil.copy2(package, 'cache/packages.bootstrap') - - # cdebootstrap - if not os.path.exists('chroot/bin'): - if verbose: - print('I: Calling \'/usr/bin/debootstrap ' + cdebootstrap_options + '\'') - - cdebootstrap = subprocess.check_call('/usr/bin/cdebootstrap ' + cdebootstrap_options, shell=True) - - # stage cache - if not os.path.exists('cache/bootstrap'): - if verbose: - print('I: Copying chroot to cache/bootstrap') - - # Notes: - # * there's no Python equivalent to 'cp -a' that handels both symlinks and device nodes properly. - cache = subprocess.check_call('cp -a chroot cache/bootstrap', shell=True) - - # stagefile - os.makedirs('.build', exist_ok=True) - open('.build/bootstrap', 'w').close() - - -if __name__ == '__main__': - main() |