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