Replacing bootstrap_debootstrap with Python stub.

This commit is contained in:
Daniel Baumann 2013-04-05 19:58:37 +02:00
parent 428da01aea
commit a06eea85ad
1 changed files with 124 additions and 100 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/python3.2
## live-build(7) - System Build Scripts ## live-build(7) - System Build Scripts
## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch> ## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
@ -8,132 +8,156 @@
## under certain conditions; see COPYING for details. ## under certain conditions; see COPYING for details.
set -e import configparser
import argparse
import os
import sys
import shutil
import glob
import subprocess
# Including common functions
[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
# Setting static variables # TODO:
DESCRIPTION="$(Echo 'bootstrap a Debian system with debootstrap(8)')" # - lockfile handling
HELP="" # - debootstrap-options from config
USAGE="${PROGRAM} [--force]"
Arguments "${@}" def main():
## Parsing Configuration
config = configparser.ConfigParser()
# Reading configuration files config.read('config/build')
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
Set_defaults
if [ "${LB_BOOTSTRAP}" != "debootstrap" ] try:
then architecture = config.get('Image', 'Architecture')
exit 0 archive_areas = config.get('Image', 'Parent-Archive-Areas')
fi distribution = config.get('Image', 'Parent-Distribution')
mirror_bootstrap = config.get('Image', 'Parent-Mirror-Bootstrap')
except:
archive_areas = config.get('Image', 'Archive-Areas')
distribution = config.get('Image', 'Distribution')
mirror_bootstrap = config.get('Image', 'Mirror-Bootstrap')
if [ ! -x "$(which debootstrap 2>/dev/null)" ] ## Parsing Arguments
then arguments = argparse.ArgumentParser(
echo "E: debootstrap - command not found" prog = 'lb bootstrap_debootstrap',
echo "I: debootstrap can be obtained from http://ftp.debian.org/debian/pool/main/d/debootstrap/" usage = '%(prog)s [arguments]',
echo "I: On Debian based systems, debootstrap can be installed with 'apt-get install debootstrap'." description = '''live-build contains the programs to build a live system from a configuration directory.
exit 1 The lb bootstrap_debootstrap program bootstraps the chroot system with debootstrap.''',
fi epilog = 'live-build was written by Daniel Baumann <mail@daniel-baumann.ch>.',
version = 'live-build 4.0',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)
# Check architecture arguments.add_argument('--verbose', help='set verbose option', action='store_true')
Check_crossarchitectures arguments.add_argument('--debootstrap-options', help='set debootstrap(8) options' )
Echo_message "Begin bootstrapping system..." args = arguments.parse_args()
Check_package /usr/sbin/debootstrap debootstrap # --verbose
verbose = args.verbose
# Ensure that a system is built as root # --debootstrap-options
lb testroot debootstrap_options_late = distribution + ' chroot ' + mirror_bootstrap
# Checking stage file debootstrap_options_early = ''
Check_stagefile .build/bootstrap
Check_stagefile .build/bootstrap_cache.restore
# Checking lock file if (architecture) and (not architecture == 'auto'):
Check_lockfile .lock debootstrap_options_early = debootstrap_options_early + ' --arch=' + architecture
# Creating lock file if (archive_areas) and (not archive_areas == 'main'):
Create_lockfile .lock debootstrap_options_early = debootstrap_options_early + ' --components=' + archive_areas.replace(' ',',')
# Creating chroot directory if args.debootstrap_options:
mkdir -p chroot debootstrap_options = debootstrap_options_early + ' ' + args.debootstrap_options + ' ' + debootstrap_options_late
else:
debootstrap_options = debootstrap_options_early + ' ' + debootstrap_options_late
# Setting debootstrap options ## Calling debootstrap
if [ -n "${LIVE_IMAGE_ARCHITECTURE}" ]
then
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --arch=${LIVE_IMAGE_ARCHITECTURE}"
fi
if [ "${LIVE_IMAGE_ARCHIVE_AREAS}" != "main" ] # stagefile
then if os.path.isfile('.build/bootstrap'):
# Modify archive areas to remove leading/trailing whitespaces and replace other whitepspace with commas if verbose:
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --components=$(echo ${LIVE_IMAGE_ARCHIVE_AREAS} | sed -e 's| |,|g')" print('I: bootstrap already done - nothing to do')
fi
if [ "${_VERBOSE}" = "true" ] sys.exit(0)
then
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --verbose"
fi
# If LB_APT_SECURE is false, do not check signatures of the Release file # dependencies
# (requires debootstrap >= 1.0.30) if not os.path.isfile('/usr/sbin/debootstrap'):
if [ "${LB_APT_SECURE}" = "false" ] && /usr/sbin/debootstrap --help | grep -qs '\-\-no-check-gpg' print('E: /usr/sbin/debootstrap - no such file')
then
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --no-check-gpg"
fi
if [ -x "/usr/sbin/debootstrap" ] if verbose:
then print('I: debootstrap can be optained from:\n'
if [ "${LB_CACHE_PACKAGES}" = "true" ] 'I: http://anonscm.debian.org/gitweb/?p=d-i/debootstrap.git\n'
then 'I: http://ftp.debian.org/debian/pool/main/d/debootstrap/\n'
if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1 'I: On Debian based systems, debootstrap can be installed with:\n'
then 'I: # sudo apt-get install debootstrap')
mkdir -p chroot/var/cache/apt/archives
cp cache/packages.bootstrap/*.deb chroot/var/cache/apt/archives
fi
Echo_breakage "Running debootstrap (download-only)... " sys.exit(1)
debootstrap ${DEBOOTSTRAP_OPTIONS} --download-only "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
# Removing old cache # clean
rm -f cache/packages.bootstrap/*.deb if os.path.exists('chroot'):
print('E: chroot already exists - unclean build')
# Saving new cache if verbose:
mkdir -p cache/packages.bootstrap print('I: use \'lb clean\' to clean up a previously incomplete build')
cp chroot/var/cache/apt/archives/*.deb cache/packages.bootstrap
fi
Echo_breakage "Running debootstrap... " sys.exit(1)
# stage cache
elif os.path.exists('cache/bootstrap'):
if verbose:
print('I: Copying cache/bootstrap to chroot')
# Run appropriate bootstrap, i.e. foreign or regular bootstrap # Note: copy instead of move to make cache survive incomplete build
if [ "${LB_BOOTSTRAP_QEMU_ARCHITECTURES}" = "${LIVE_IMAGE_ARCHITECTURE}" ]; then #shutil.copytree('cache/bootstrap', 'chroot') # FIXME: copytree() doesn't work with device files :(
cp = subprocess.call('cp -a cache/bootstrap chroot', shell=True)
# packages cache
elif glob.glob('cache/packages.bootstrap/*.deb'):
if verbose:
print('I: Copying cache/packages.bootstrap/*.deb to chroot/var/cache/apt/archives/*.deb')
if [ -n "${LB_BOOTSTRAP_QEMU_EXCLUDE}" ] # Note: copy instead of move to make cache survive incomplete build
then os.makedirs('chroot/var/cache/apt/archives', exist_ok=True)
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --exclude=$(echo ${LB_BOOTSTRAP_QEMU_EXCLUDE} | sed 's| *|,|g')"
fi
Echo_message "Bootstrap will be foreign" for package in glob.glob('cache/packages.bootstrap/*.deb'):
debootstrap ${DEBOOTSTRAP_OPTIONS} --foreign "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" os.link(package, os.path.join('chroot/var/cache/apt/archives/' + os.path.basename(package)))
Echo_message "Running debootstrap second stage under QEMU" # debootstrap
cp ${LB_BOOTSTRAP_QEMU_STATIC} chroot/usr/bin if not os.path.exists('chroot/bin'):
Chroot chroot /bin/sh /debootstrap/debootstrap --second-stage if verbose:
else print('I: Calling \'/usr/sbin/debootstrap ' + debootstrap_options + '\'')
debootstrap ${DEBOOTSTRAP_OPTIONS} "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
fi
# Deconfiguring debootstrap configurations debootstrap = subprocess.call('/usr/sbin/debootstrap ' + debootstrap_options, shell=True)
rm -f chroot/etc/hosts
# Removing bootstrap cache # package cache
rm -f chroot/var/cache/apt/archives/*.deb if glob.glob('chroot/var/cache/apt/archives/*.deb'):
if verbose:
print('I: Copying chroot/var/cache/apt/archives/*.deb to cache/packages.bootstrap')
# Creating stage file # Note: remove first to keep cache minimal,
Create_stagefile .build/bootstrap # remove files instead of directory to work with symlinked directory
else for package in glob.glob('cache/packages.bootstrap/*.deb'):
Echo_error "Can't process file /usr/bin/debootstrap (FIXME)" os.remove(package)
exit 1
fi os.makedirs('cache/packages.bootstrap', exist_ok=True)
# Note: move instead of copy to keep stage minimal
for package in glob.glob('chroot/var/cache/apt/archives/*.deb'):
shutil.move(package, 'cache/packages.bootstrap')
# stage cache
if (os.path.exists('chroot')) and (not os.path.exists('cache/bootstrap')):
if verbose:
print('I: Copying chroot to cache/bootstrap')
# Note: copy instead of move to keep stage
#shutil.copytree('chroot', 'cache/bootstrap') # FIXME: copytree() doesn't work with device files :(
os.makedirs('cache', exist_ok=True)
cp = subprocess.call('cp -a chroot cache/bootstrap', shell=True)
## stagefile
os.makedirs('.build', exist_ok=True)
open('.build/bootstrap', 'w').close()
if __name__ == '__main__':
main()