diff options
author | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2021-08-19 07:50:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2021-08-19 09:20:40 +0000 |
commit | c0060c31fdf1c2af1454c5877c311b6680618084 (patch) | |
tree | d85f1dac8fbc7ab60a55acef6a4a777893d2209a | |
parent | Adding cdebootstrap support. (diff) | |
download | compute-tools-c0060c31fdf1c2af1454c5877c311b6680618084.tar.xz compute-tools-c0060c31fdf1c2af1454c5877c311b6680618084.zip |
Refactor debootstrap create script (FIXME WIP).
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | share/create-scripts/bootstrap (renamed from share/create-scripts/debootstrap) | 27 | ||||
-rwxr-xr-x | share/create-scripts/parts/chroot_clean-apt-archives | 23 | ||||
-rwxr-xr-x | share/create-scripts/parts/chroot_config-root-password | 33 | ||||
-rwxr-xr-x | share/create-scripts/parts/chroot_config-system-hostname | 23 |
5 files changed, 95 insertions, 15 deletions
@@ -123,7 +123,7 @@ install: build ln -sf container-build-debconf.1 $(DESTDIR)/usr/share/man/man1/container-build-$${MODE}.1; \ done - for BOOTSTRAP in mmdebstrap; \ + for BOOTSTRAP in debootstrap cdebootstrap mmdebstrap; \ do \ ln -sf bootstrap $(DESTDIR)/usr/share/$(SOFTWARE)/build-scripts/$${BOOTSTRAP}; \ ln -sf container-build-bootstrap.1 $(DESTDIR)/usr/share/man/man1/container-build-$${BOOTSTRAP}.1; \ @@ -174,7 +174,7 @@ uninstall: rm -f $(DESTDIR)/usr/share/man/man1/container-build-$${MODE}.1; \ done - for BOOTSTRAP in mmdebstrap; \ + for BOOTSTRAP in debootstrap cdebootstrap mmdebstrap; \ do \ rm -f $(DESTDIR)/usr/share/man/man1/container-build-$${BOOTSTRAP}.1; \ done diff --git a/share/create-scripts/debootstrap b/share/create-scripts/bootstrap index bef75b1..a332d4d 100755 --- a/share/create-scripts/debootstrap +++ b/share/create-scripts/bootstrap @@ -24,6 +24,7 @@ SOFTWARE="compute-tools" PROGRAM="container" SCRIPT="$(basename ${0})" +DIRECTORY="$(dirname ${0})" HOOKS="/etc/${SOFTWARE}/hooks" MACHINES="/var/lib/machines" @@ -109,15 +110,15 @@ case "${SCRIPT}" in BOOTSTRAP_OPTIONS="" ;; - debootstrap) - BOOTSTRAP="/usr/sbin/debootstrap" - BOOTSTRAP_OPTIONS="" - ;; - mmdebstrap) BOOTSTRAP="/usr/bin/mmdebstrap" BOOTSTRAP_OPTIONS="--mode=root" ;; + + *) + BOOTSTRAP="/usr/sbin/debootstrap" + BOOTSTRAP_OPTIONS="" + ;; esac if [ ! -x "${BOOTSTRAP}" ] @@ -135,7 +136,6 @@ fi ARCHITECTURE="${ARCHITECTURE:-$(dpkg --print-architecture)}" DISTRIBUTION="${DISTRIBUTION:-bullseye}" MIRROR="${MIRROR:-https://deb.debian.org/debian}" -PASSWORD="${PASSWORD:-$(dd if=/dev/urandom bs=12 count=1 2> /dev/null | base64)}" INCLUDE="dbus" @@ -158,15 +158,16 @@ done mkdir -p "${MACHINES}" ${BOOTSTRAP} ${BOOTSTRAP_OPTIONS} --arch=${ARCHITECTURE} --include=${INCLUDE} ${DISTRIBUTION} ${MACHINES}/${NAME} ${MIRROR} -# Cleaning apt cache -chroot "${MACHINES}/${NAME}" apt clean +SYSTEM_NAME="${NAME}" +SYSTEM_PATH="${MACHINES}/${NAME}" +SYSTEM_ROOT_PASSWORD="${PASSWORD}" -# Setting hostname -echo "${NAME}" > "${MACHINES}/${NAME}/etc/hostname" +export SYSTEM_NAME SYSTEM_PATH SYSTEM_ROOT_PASSWORD -# Setting root password -echo root:${PASSWORD} | chroot "${MACHINES}/${NAME}" chpasswd -echo "${NAME}: root password set to '${PASSWORD}'." +# Customization +"${DIRECTORY}"/parts/chroot_clean-apt-archives +"${DIRECTORY}"/parts/chroot_config-root-password +"${DIRECTORY}"/parts/chroot_config-system-hostname # Post hooks for FILE in "${HOOKS}/post-${SCRIPT}".* "${HOOKS}/${NAME}.post-${SCRIPT}" diff --git a/share/create-scripts/parts/chroot_clean-apt-archives b/share/create-scripts/parts/chroot_clean-apt-archives new file mode 100755 index 0000000..5c86cf0 --- /dev/null +++ b/share/create-scripts/parts/chroot_clean-apt-archives @@ -0,0 +1,23 @@ +#!/bin/sh + +# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +echo "${SYSTEM_NAME}: cleaning apt archives" +chroot "${SYSTEM_PATH}" apt-get clean diff --git a/share/create-scripts/parts/chroot_config-root-password b/share/create-scripts/parts/chroot_config-root-password new file mode 100755 index 0000000..4868ccd --- /dev/null +++ b/share/create-scripts/parts/chroot_config-root-password @@ -0,0 +1,33 @@ +#!/bin/sh + +# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +if [ -e "${SYSTEM_ROOT_PASSWORD}" ] +then + SYSTEM_ROOT_PASSWORD="$(head -n1 ${SYSTEM_ROOT_PASSWORD})" +fi + +if [ -z "${SYSTEM_ROOT_PASSWORD}" ] +then + SYSTEM_ROOT_PASSWORD="$(dd if=/dev/urandom bs=12 count=1 2> /dev/null | base64)" +fi + +echo "${SYSTEM_NAME}: setting root password to '${SYSTEM_ROOT_PASSWORD}'" +echo root:${SYSTEM_ROOT_PASSWORD} | chroot "${SYSTEM_PATH}" chpasswd diff --git a/share/create-scripts/parts/chroot_config-system-hostname b/share/create-scripts/parts/chroot_config-system-hostname new file mode 100755 index 0000000..7580f45 --- /dev/null +++ b/share/create-scripts/parts/chroot_config-system-hostname @@ -0,0 +1,23 @@ +#!/bin/sh + +# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +echo "${SYSTEM_NAME}: setting hostname" +echo "${SYSTEM_NAME}" > "${SYSTEM_PATH}/etc/hostname" |