#!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$DIR/debootstrap_conf.sh" # Usage: create_debootstrap OS RELEASE [ARCH] INSTALLDIR # e.g. create_debootstrap ubuntu bionic /mnt/root # Creates a basic installation of a given OS release into # the folder INSTALLDIR. If no arch is specified, amd64 is used. # NOTE: As of Jan 2019, only amd64 is available on the local mirror create_debootstrap() { if (( $# < 3 )); then echo "Error! create_debootstrap requires at least 3 arguments, but only $# were specified" return 1 fi local OS="$1" local RELEASE="$2" if (( $# == 3 )); then local ARCH="amd64" local INSTALLDIR="$3" else local ARCH="$3" local INSTALLDIR="$4" fi echo "OS: $OS; Arch: $ARCH; Release: $RELEASE; Dir: $INSTALLDIR" [[ -d "$INSTALLDIR" ]] || { echo "Install dir $INSTALLDIR does not exist... aborting!"; return 1; } [ -z ${NFSDIR+x} ] && { echo "ERROR: NFSDIR is undefined. Aborting!"; return 1; } local DBSRC="${NFSDIR}/images/bootstrap/${OS}/dbs/${ARCH}/${RELEASE}.tgz" echo $DBSRC case $OS in ubuntu) debootstrap --components="$UBUNTU_COMPONENTS" --include="$UBUNTU_PKGS" --arch="$ARCH" \ --unpack-tarball="$DBSRC" "$RELEASE" "$INSTALLDIR" ;; debian) debootstrap --components="$DEBIAN_COMPONENTS" --include="$DEBIAN_PKGS" --arch="$ARCH" \ --unpack-tarball="$DBSRC" "$RELEASE" "$INSTALLDIR" ;; *) echo "WARNING: Unknown OS. Will try anyway without any additional packages or repository components" debootstrap --arch="$ARCH" --unpack-tarball="$DBSRC" "$RELEASE" "$INSTALLDIR" ;; esac }