Replacing bootstrap_cdebootstrap with Python stub.
This commit is contained in:
parent
a06eea85ad
commit
c229d39dc8
|
@ -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,136 +8,159 @@
|
||||||
## 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 cdebootstrap(1)')"
|
# - lockfile handling
|
||||||
HELP=""
|
# - cdebootstrap-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}" != "cdebootstrap" ] && [ "${LB_BOOTSTRAP}" != "cdebootstrap-static" ]
|
try:
|
||||||
then
|
architecture = config.get('Image', 'Architecture')
|
||||||
exit 0
|
distribution = config.get('Image', 'Parent-Distribution')
|
||||||
fi
|
mirror_bootstrap = config.get('Image', 'Parent-Mirror-Bootstrap')
|
||||||
|
except:
|
||||||
|
distribution = config.get('Image', 'Distribution')
|
||||||
|
mirror_bootstrap = config.get('Image', 'Mirror-Bootstrap')
|
||||||
|
|
||||||
if [ ! -x "$(which cdebootstrap 2>/dev/null)" ]
|
## Parsing Arguments
|
||||||
then
|
arguments = argparse.ArgumentParser(
|
||||||
echo "E: cdebootstrap - command not found"
|
prog = 'lb bootstrap_cdebootstrap',
|
||||||
echo "I: cdebootstrap can be obtained from http://ftp.debian.org/debian/pool/main/d/cdebootstrap/"
|
usage = '%(prog)s [arguments]',
|
||||||
echo "I: On Debian based systems, cdebootstrap can be installed with 'apt-get install cdebootstrap'."
|
description = '''live-build contains the programs to build a live system from a configuration directory.
|
||||||
exit 1
|
The lb bootstrap_cdebootstrap program bootstraps the chroot system with cdebootstrap.''',
|
||||||
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('--cdebootstrap-options', help='set cdebootstrap(1) options' )
|
||||||
|
|
||||||
Echo_message "Begin bootstrapping system..."
|
args = arguments.parse_args()
|
||||||
|
|
||||||
Check_package /usr/bin/${LB_BOOTSTRAP} cdebootstrap
|
# --verbose
|
||||||
|
verbose = args.verbose
|
||||||
|
|
||||||
# Ensure that a system is built as root
|
# --cdebootstrap-options
|
||||||
lb testroot
|
cdebootstrap_options_late = distribution + ' chroot ' + mirror_bootstrap
|
||||||
|
|
||||||
# Checking stage file
|
cdebootstrap_options_early = ''
|
||||||
Check_stagefile .build/bootstrap
|
|
||||||
Check_stagefile .build/bootstrap_cache.restore
|
|
||||||
|
|
||||||
# Checking lock file
|
if (architecture) and (not architecture == 'auto'):
|
||||||
Check_lockfile .lock
|
cdebootstrap_options_early = cdebootstrap_options_early + ' --arch=' + architecture
|
||||||
|
|
||||||
# Creating lock file
|
if args.cdebootstrap_options:
|
||||||
Create_lockfile .lock
|
cdebootstrap_options = cdebootstrap_options_early + ' ' + args.cdebootstrap_options + ' ' + cdebootstrap_options_late
|
||||||
|
else:
|
||||||
|
cdebootstrap_options = cdebootstrap_options_early + ' ' + cdebootstrap_options_late
|
||||||
|
|
||||||
# Creating chroot directory
|
## Calling cdebootstrap
|
||||||
mkdir -p chroot
|
|
||||||
|
|
||||||
# Setting cdebootstrap options
|
# stagefile
|
||||||
if [ -n "${LIVE_IMAGE_ARCHITECTURE}" ]
|
if os.path.isfile('.build/bootstrap'):
|
||||||
then
|
if verbose:
|
||||||
CDEBOOTSTRAP_OPTIONS="${CDEBOOTSTRAP_OPTIONS} --arch=${LIVE_IMAGE_ARCHITECTURE}"
|
print('I: bootstrap already done - nothing to do')
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${_DEBUG}" = "true" ]
|
sys.exit(0)
|
||||||
then
|
|
||||||
CDEBOOTSTRAP_OPTIONS="${CDEBOOTSTRAP_OPTIONS} --debug"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${_QUIET}" = "true" ]
|
# dependencies
|
||||||
then
|
if not os.path.isfile('/usr/bin/cdebootstrap'):
|
||||||
CDEBOOTSTRAP_OPTIONS="${CDEBOOTSTRAP_OPTIONS} --quiet"
|
print('E: /usr/bin/cdebootstrap - no such file')
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${_VERBOSE}" = "true" ]
|
if verbose:
|
||||||
then
|
print('I: cdebootstrap can be optained from:\n'
|
||||||
CDEBOOTSTRAP_OPTIONS="${CDEBOOTSTRAP_OPTIONS} --verbose"
|
'I: http://anonscm.debian.org/gitweb/?p=users/waldi/cdebootstrap.git\n'
|
||||||
fi
|
'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')
|
||||||
|
|
||||||
if [ "${LB_APT_SECURE}" = "false" ]
|
sys.exit(1)
|
||||||
then
|
|
||||||
CDEBOOTSTRAP_OPTIONS="${CDEBOOTSTRAP_OPTIONS} --allow-unauthenticated"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -x "/usr/bin/cdebootstrap" ] || [ -x "/usr/bin/cdebootstrap-static" ]
|
# clean
|
||||||
then
|
if os.path.exists('chroot'):
|
||||||
if [ "${LB_CACHE_PACKAGES}" = "true" ]
|
print('E: chroot already exists - unclean build')
|
||||||
then
|
|
||||||
if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1
|
|
||||||
then
|
|
||||||
mkdir -p chroot/var/cache/bootstrap
|
|
||||||
cp cache/packages.bootstrap/*.deb chroot/var/cache/bootstrap
|
|
||||||
fi
|
|
||||||
|
|
||||||
Echo_breakage "Running ${LB_BOOTSTRAP} (download-only)... "
|
if verbose:
|
||||||
${LB_BOOTSTRAP} ${CDEBOOTSTRAP_OPTIONS} --download-only "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
|
print('I: use \'lb clean\' to clean up a previously incomplete build')
|
||||||
|
|
||||||
# Removing old cache
|
sys.exit(1)
|
||||||
rm -f cache/packages.bootstrap/*.deb
|
# stage cache
|
||||||
|
elif os.path.exists('cache/bootstrap'):
|
||||||
|
if verbose:
|
||||||
|
print('I: Copying cache/bootstrap to chroot')
|
||||||
|
|
||||||
# Saving new cache
|
# Note: copy instead of move to make cache survive incomplete build
|
||||||
mkdir -p cache/packages.bootstrap
|
#shutil.copytree('cache/bootstrap', 'chroot') # FIXME: copytree() doesn't work with device files :(
|
||||||
cp chroot/var/cache/bootstrap/*.deb cache/packages.bootstrap
|
cp = subprocess.call('cp -a cache/bootstrap chroot', shell=True)
|
||||||
fi
|
# packages cache
|
||||||
|
elif glob.glob('cache/packages.bootstrap/*.deb'):
|
||||||
|
if verbose:
|
||||||
|
print('I: Copying cache/packages.bootstrap/*.deb to chroot/var/cache/bootstrap/*.deb')
|
||||||
|
|
||||||
Echo_breakage "Running ${LB_BOOTSTRAP}... "
|
# Note: copy instead of move to make cache survive incomplete build
|
||||||
|
os.makedirs('chroot/var/cache/bootstrap', exist_ok=True)
|
||||||
|
|
||||||
# Run appropriate bootstrap, i.e. foreign or regular bootstrap
|
for package in glob.glob('cache/packages.bootstrap/*.deb'):
|
||||||
if [ "${LB_BOOTSTRAP_QEMU_ARCHITECTURES}" = "${LIVE_IMAGE_ARCHITECTURE}" ]; then
|
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 + '\'')
|
||||||
|
|
||||||
if [ -n "${LB_BOOTSTRAP_QEMU_EXCLUDE}" ]
|
# Note: calling cdebootstrap twice:
|
||||||
then
|
# - to use already downloaded /var/cache/bootstrap/*.deb on incomplete builds
|
||||||
CDEBOOTSTRAP_OPTIONS="${CDEBOOTSTRAP_OPTIONS} --exclude=$(echo ${LB_BOOTSTRAP_QEMU_EXCLUDE} | sed 's| *|,|g')"
|
# - to use /var/cache/boottrap/*.deb for debian-installer
|
||||||
fi
|
cdebootstrap = subprocess.call('/usr/bin/cdebootstrap --download-only ' + cdebootstrap_options, shell=True)
|
||||||
|
|
||||||
Echo_message "Bootstrap will be foreign"
|
# package cache
|
||||||
${LB_BOOTSTRAP} ${CDEBOOTSTRAP_OPTIONS} --foreign "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
|
if glob.glob('chroot/var/cache/bootstrap/*.deb'):
|
||||||
|
if verbose:
|
||||||
|
print('I: Copying chroot/var/cache/bootstrap/*.deb to cache/packages.bootstrap')
|
||||||
|
|
||||||
Echo_message "Running debootstrap second stage under QEMU"
|
# Notes: - remove first to keep cache minimal
|
||||||
cp ${LB_BOOTSTRAP_QEMU_STATIC} chroot/usr/bin
|
# - remove files instead of directory to work with symlinked directory
|
||||||
Chroot chroot /bin/sh /sbin/cdebootstrap-foreign
|
for package in glob.glob('cache/packages.bootstrap/*.deb'):
|
||||||
else
|
os.remove(package)
|
||||||
${LB_BOOTSTRAP} ${CDEBOOTSTRAP_OPTIONS} "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Deconfiguring cdebootstrap configurations
|
os.makedirs('cache/packages.bootstrap', exist_ok=True)
|
||||||
rm -f chroot/etc/apt/sources.list
|
|
||||||
rm -f chroot/etc/hosts
|
|
||||||
rm -f chroot/etc/resolv.conf
|
|
||||||
|
|
||||||
# Removing bootstrap cache
|
for package in glob.glob('chroot/var/cache/bootstrap/*.deb'):
|
||||||
rm -rf chroot/var/cache/bootstrap
|
shutil.copy2(package, 'cache/packages.bootstrap')
|
||||||
|
|
||||||
# Creating stage file
|
# cdebootstrap
|
||||||
Create_stagefile .build/bootstrap
|
if not os.path.exists('chroot/bin'):
|
||||||
else
|
if verbose:
|
||||||
Echo_error "Can't process file /usr/bin/${LB_BOOTSTRAP} (FIXME)"
|
print('I: Calling \'/usr/bin/debootstrap ' + cdebootstrap_options + '\'')
|
||||||
exit 1
|
|
||||||
fi
|
cdebootstrap = subprocess.call('/usr/bin/cdebootstrap ' + cdebootstrap_options, shell=True)
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
Loading…
Reference in New Issue