summaryrefslogtreecommitdiffstats
path: root/share/doc/examples/container-images.sh
blob: a995be5c3a677854d9517fb752bce904d09e2dc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh

# container-tools - Manage systemd-nspawn containers
#
# Description: example for automated Debian base system container image creation
# Requires:    debootstrap plzip xz-utils
# Usage:       sudo ./container-images.sh

set -e

ARCHITECTURES="amd64 i386"
DISTRIBUTIONS="stretch sid"
MIRROR="https://deb.debian.org/debian"
INCLUDE="dbus"

DATE="$(date +%Y%m%d)"

for DISTRIBUTION in ${DISTRIBUTIONS}
do
	for ARCHITECTURE in ${ARCHITECTURES}
	do
		SOURCE="debian-${DISTRIBUTION}-${ARCHITECTURE}_${DATE}"
		TARGET="debian-${DISTRIBUTION}-${ARCHITECTURE}"

		debootstrap --arch=${ARCHITECTURE} --include=${INCLUDE} ${DISTRIBUTION} ${SOURCE} ${MIRROR}
		chroot "${SOURCE}" apt-get clean

		rm -f "${SOURCE}/etc/apt/apt.conf.d/01autoremove-kernels"
		rm -f "${SOURCE}/etc/hostname"
		echo "" > "${SOURCE}/etc/machine-id"
		rm -f "${SOURCE}/etc/resolv.conf"
		rm -f "${SOURCE}/var/lib/systemd/catalog/database"

		echo "Creating ${TARGET}.tar.lz"
		tar --lzip -cf "${TARGET}.tar.lz" "${SOURCE}"

		echo "Creating ${TARGET}.tar.xz"
		tar --xz -cf "${TARGET}.tar.xz" "${SOURCE}"
	done
done