Skip to content

Instantly share code, notes, and snippets.

@henrich
Created July 5, 2018 03:35
Show Gist options
  • Save henrich/50ab1b7fa129e4d92075e8ccf541c0d2 to your computer and use it in GitHub Desktop.
Save henrich/50ab1b7fa129e4d92075e8ccf541c0d2 to your computer and use it in GitHub Desktop.
debootstrap
From 5cbe6582a3976c32b10b9d0114d5d8e970260fc2 Mon Sep 17 00:00:00 2001
From: Hideki Yamane <henrich@debian.org>
Date: Thu, 5 Jul 2018 11:25:17 +0900
Subject: [PATCH 1/2] improve related to container
---
debootstrap | 6 ++++--
functions | 58 ++++++++++++++++++++++++++---------------------------
2 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/debootstrap b/debootstrap
index c9cfc5b..db59c14 100755
--- a/debootstrap
+++ b/debootstrap
@@ -50,6 +50,9 @@ CACHE_DIR=""
DEF_MIRROR="http://deb.debian.org/debian"
DEF_HTTPS_MIRROR="https://deb.debian.org/debian"
+# set $CONTAINER
+detect_container
+
export LANG USE_COMPONENTS
umask 022
@@ -525,8 +528,7 @@ else
fi
# fakeroot cannot check /proc/1/environ
-if [ "$HOST_OS" = Linux ] && ! doing_variant fakechroot && \
- grep -q container=lxc-libvirt /proc/1/environ; then
+if [ "$HOST_OS" = Linux ] && ! doing_variant fakechroot && [ "$CONTAINER" = "lxc-libvirt" ]; then
CHROOT_CMD="unshare --net $CHROOT_CMD"
fi
diff --git a/functions b/functions
index 4d5b9b3..4003ed2 100644
--- a/functions
+++ b/functions
@@ -219,6 +219,18 @@ keyring () {
fi
}
+detect_container () {
+ if [ "$container" = lxc ]; then
+ CONTAINER="lxc"
+ elif grep -qs container=lxc-libvirt /proc/1/environ; then
+ CONTAINER="lxc-libvirt"
+ elif grep -qs ^systemd-nspawn$ /run/systemd/container || [ "$container" = "systemd-nspawn" ]; then
+ CONTAINER="systemd-nspawn"
+ else
+ CONTAINER=""
+ fi
+}
+
########################################################## variant handling
doing_variant () {
@@ -1053,21 +1065,6 @@ conditional_cp () {
fi
}
-detect_lxc () {
- if [ "$container" = lxc ] || [ "$container" = lxc-libvirt ]; then
- true
- else
- false
- fi
-}
-
-detect_systemd_nspawn () {
- if grep -qs ^systemd-nspawn$ /run/systemd/container || [ ! "$container" = "systemd-nspawn" ]; then
- true
- else
- false
- fi
-}
setup_apt_sources () {
mkdir -p "$TARGET/etc/apt"
@@ -1140,10 +1137,8 @@ setup_proc () {
umount_on_exit /proc/bus/usb
umount "$TARGET/proc" 2>/dev/null || true
- if detect_lxc; then
- true
- # if systemd-nspawn is used at second-stage, it already treats /proc and so on
- elif [ -z "$(ls -A "$TARGET/proc")" ]; then
+ # some container environment are used at second-stage, it already treats /proc and so on
+ if [ -z "$(ls -A "$TARGET/proc")" ]; then
in_target mount -t proc proc /proc
umount_on_exit /proc
fi
@@ -1151,8 +1146,6 @@ setup_proc () {
grep -qs '[[:space:]]sysfs' "$TARGET/proc/filesystems"; then
umount_on_exit /sys
umount "$TARGET/sys" 2>/dev/null || true
- elif detect_lxc; then
- true
else
in_target mount -t sysfs sysfs /sys
umount_on_exit /sys
@@ -1183,7 +1176,7 @@ setup_devices () {
hurd*)
;;
*)
- if detect_lxc; then
+ if [ "$CONTAINER" = "lxc" ] || [ "$CONTAINER" = "lxc-libvirt" ]; then
setup_devices_bind
return 0
fi
@@ -1234,7 +1227,7 @@ setup_devices_simple () {
mknod_if_needed "$TARGET/dev/random" c 1 8
mknod_if_needed "$TARGET/dev/urandom" c 1 9
mknod_if_needed "$TARGET/dev/tty" c 5 0
- if ! detect_systemd_nspawn; then
+ if [ ! "$CONTAINER" = "systemd-nspawn" ]; then
mknod_if_needed "$TARGET/dev/console" c 5 1
fi
# To avoid pre-exist directory causes error, specify "-p" option
@@ -1539,15 +1532,20 @@ check_sane_mount () {
*freebsd*|hurd*)
;;
*)
- if ! doing_variant fakechroot && ! detect_lxc; then
- mknod "$1/test-dev-null" c 1 3 || return 1
- if ! echo test > "$1/test-dev-null"; then
- rm -f "$1/test-dev-null"
- return 1
- fi
+ if ! doing_variant fakechroot; then
+ case "$CONTAINER" in
+ lxc|lxc-libvirt)
+ ;;
+ *)
+ mknod "$1/test-dev-null" c 1 3 || return 1
+ if ! echo test > "$1/test-dev-null"; then
rm -f "$1/test-dev-null"
+ return 1
+ fi
+ rm -f "$1/test-dev-null"
+ ;;
+ esac
fi
- ;;
esac
SH="/bin/sh"
--
2.18.0
From c895774c4041a9af942b1e455bccb5e04fc87c85 Mon Sep 17 00:00:00 2001
From: Hideki Yamane <henrich@debian.org>
Date: Thu, 5 Jul 2018 12:30:15 +0900
Subject: [PATCH 2/2] Add wget check
---
debootstrap | 3 +++
1 file changed, 3 insertions(+)
diff --git a/debootstrap b/debootstrap
index db59c14..d230f74 100755
--- a/debootstrap
+++ b/debootstrap
@@ -437,6 +437,9 @@ if [ "$SECOND_STAGE_ONLY" = "true" ]; then
fi
SCRIPT="$DEBOOTSTRAP_DIR/suite-script"
else
+ if ! in_path wget; then
+ error 1 NEEDWGET "You must install wget to download packages."
+ fi
if [ -z "$1" ] || [ -z "$2" ]; then
usage_err 1 NEEDSUITETARGET "You must specify a suite and a target."
fi
--
2.18.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment