Debian Codegraph @

share/doc/examples/container-images.sh

raw symbols SCIP
1 #!/bin/sh
2
3 # Copyright (C) 2014-2026 Daniel Baumann <[email protected]>
4 #
5 # SPDX-License-Identifier: GPL-3.0+
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 # Description: example for automated Debian base system container image builds
21 # Requires: debootstrap plzip xz-utils sudo
22 # Usage: ./container-images.sh
23
24 set -e
25
26 ARCHITECTURES="amd64"
27 DISTRIBUTIONS="trixie sid"
28 MIRROR="https://deb.debian.org/debian"
29 INCLUDE="dbus"
30
31 KEY="2698683880B6A84A3D044602FBB4F0E80A80222F"
32
33 COMPRESSIONS="gz lz xz"
34
35 DATE="$(date +%Y%m%d)"
36
37 for DISTRIBUTION in ${DISTRIBUTIONS}
38 do
39 for ARCHITECTURE in ${ARCHITECTURES}
40 do
41 TITLE="Debian ${DISTRIBUTION} ${DATE}/${ARCHITECTURE}"
42 SYSTEM="debian-${DISTRIBUTION}-${DATE}_${ARCHITECTURE}"
43
44 sudo debootstrap --arch=${ARCHITECTURE} --include=${INCLUDE} ${DISTRIBUTION} ${SYSTEM} ${MIRROR}
45 sudo chroot "${SYSTEM}" apt-get clean
46
47 VERSION="$(cat ${SYSTEM}/etc/debian_version)"
48
49 case "${VERSION}" in
50 [0-9]*)
51 TITLE="Debian ${VERSION} (${DISTRIBUTION}) ${DATE}/${ARCHITECTURE}"
52 SYSTEM="debian-${VERSION}-${DATE}_${ARCHITECTURE}"
53
54 sudo mv "debian-${DISTRIBUTION}-${DATE}_${ARCHITECTURE}" "${SYSTEM}"
55 ;;
56 esac
57
58 sudo rm -f "${SYSTEM}/etc/apt/apt.conf.d/01autoremove-kernels"
59 sudo rm -f "${SYSTEM}/etc/hostname"
60 sudo rm -f "${SYSTEM}/etc/machine-id"
61 sudo rm -f "${SYSTEM}/etc/resolv.conf"
62 sudo rm -f "${SYSTEM}/var/lib/systemd/catalog/database"
63
64 for COMPRESSION in ${COMPRESSIONS}
65 do
66 case "${COMPRESSION}" in
67 gz)
68 TAR_OPTIONS="--gzip"
69 ;;
70
71 lz)
72 TAR_OPTIONS="--lzip"
73 ;;
74
75 xz)
76 TAR_OPTIONS="--xz"
77 ;;
78 esac
79
80 echo "Building ${SYSTEM}.system.tar.${COMPRESSION}"
81 sudo tar ${TAR_OPTIONS} -cf "${SYSTEM}.system.tar.${COMPRESSION}" "${SYSTEM}"
82
83 echo "Building ${SYSTEM}.system.tar.${COMPRESSION}.sha512"
84 sha512sum "${SYSTEM}.system.tar.${COMPRESSION}" > "${SYSTEM}.system.tar.${COMPRESSION}.sha512"
85
86 if [ -n "${KEY}" ]
87 then
88 echo "Building ${SYSTEM}.system.tar.${COMPRESSION}.sig"
89 gpg -a -b --default-key ${KEY} ${SYSTEM}.system.tar.${COMPRESSION}
90 mv "${SYSTEM}.system.tar.${COMPRESSION}.asc" "${SYSTEM}.system.tar.${COMPRESSION}.sig"
91 fi
92
93 echo "Building ${SYSTEM}.system.tar.${COMPRESSION} symlink"
94 ln -sf "${SYSTEM}.system.tar.${COMPRESSION}" "$(echo ${SYSTEM}.system.tar.${COMPRESSION} | sed -e "s|${DATE}|current|")"
95
96 echo "Building ${SYSTEM}.system.tar.${COMPRESSION}.sha512 copy"
97 sed -e "s|${DATE}|current|" "${SYSTEM}.system.tar.${COMPRESSION}.sha512" > "$(echo ${SYSTEM}.system.tar.${COMPRESSION}.sha512 | sed -e "s|${DATE}|current|")"
98
99 if [ -e "${SYSTEM}.system.tar.${COMPRESSION}.sig" ]
100 then
101 echo "Building ${SYSTEM}.system.tar.${COMPRESSION}.sig copy"
102 cp "${SYSTEM}.system.tar.${COMPRESSION}.sig" "$(echo ${SYSTEM}.system.tar.${COMPRESSION}.sig | sed -e "s|${DATE}|current|")"
103 fi
104 done
105
106 sudo rm -rf "${SYSTEM}"
107
108 cat >> container-list.txt << EOF
109 ${SYSTEM}.system.tar | ${TITLE}
110 EOF
111
112 done
113 done