live-build/scripts/build/bootstrap_cdebootstrap

159 lines
5.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
2007-09-23 08:04:46 +00:00
2013-10-17 09:22:34 +00:00
## live-build(7) - Live Systems 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.
2007-09-23 08:04:46 +00:00
import argparse
import configparser
2013-05-15 20:49:13 +00:00
import glob
import os
import shutil
import subprocess
2013-05-15 20:49:13 +00:00
import sys
2007-09-23 08:04:46 +00:00
2013-10-17 09:22:34 +00:00
# TODOs:
# * lockfile handling
# * cdebootstrap-options from config
# * use gettext for i18n
# * take mirrors from config/archives/debian.{bootstrap,chroot}
2007-09-23 08:04:48 +00:00
def main():
## Parsing Arguments
arguments = argparse.ArgumentParser(
prog = 'lb bootstrap_cdebootstrap',
usage = '%(prog)s [arguments]',
description = '''live-build contains the programs to build a live system from a configuration directory.
The lb bootstrap_cdebootstrap program bootstraps the chroot system with cdebootstrap.''',
epilog = 'See \'man lb_bootstrap_cdebootstrap\' for more information.',
version = 'live-build 4',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)
arguments.add_argument('--verbose', help='set verbose option', action='store_true')
arguments.add_argument('--cdebootstrap-options', help='set cdebootstrap(1) options' )
2007-09-23 08:04:46 +00:00
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
2007-09-23 08:04:49 +00:00
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
2007-09-23 08:05:11 +00:00
# stagefile
if os.path.isfile('.build/bootstrap'):
if verbose:
print('I: bootstrap already done - nothing to do')
2007-09-23 08:05:16 +00:00
sys.exit(0)
2007-09-23 08:05:11 +00:00
# dependencies
if not os.path.isfile('/usr/bin/cdebootstrap'):
print('E: /usr/bin/cdebootstrap - no such file', file=sys.stderr)
2007-09-23 08:04:46 +00:00
if verbose:
print('I: cdebootstrap can be optained 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')
2007-09-23 08:04:46 +00:00
sys.exit(1)
2007-09-23 08:04:46 +00:00
# clean
if os.path.exists('chroot'):
print('E: chroot already exists - unclean build', file=sys.stderr)
2007-09-23 08:04:46 +00:00
if verbose:
print('I: use \'lb clean\' to clean up a previously incomplete build')
2007-09-23 08:04:46 +00:00
sys.exit(1)
# packages cache
elif glob.glob('cache/packages.bootstrap/*.deb'):
if verbose:
print('I: Copying cache/packages.bootstrap/*.deb to chroot/var/cache/bootstrap/*.deb')
2013-10-17 09:22:34 +00:00
# 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 + '\'')
2013-10-17 09:22:34 +00:00
# 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.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')
2013-10-17 09:22:34 +00:00
# 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)
2007-09-23 08:04:49 +00:00
os.makedirs('cache/packages.bootstrap', exist_ok=True)
for package in glob.glob('chroot/var/cache/bootstrap/*.deb'):
shutil.copy2(package, 'cache/packages.bootstrap')
2007-09-23 08:04:49 +00:00
# cdebootstrap
if not os.path.exists('chroot/bin'):
if verbose:
print('I: Calling \'/usr/bin/debootstrap ' + cdebootstrap_options + '\'')
cdebootstrap = subprocess.call('/usr/bin/cdebootstrap ' + cdebootstrap_options, shell=True)
2007-09-23 08:04:48 +00:00
## stagefile
os.makedirs('.build', exist_ok=True)
open('.build/bootstrap', 'w').close()
2007-09-23 08:04:46 +00:00
if __name__ == '__main__':
main()