|
| 1 | +#!/bin/bash -ex |
| 2 | + |
| 3 | +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 4 | + |
| 5 | +ARCH=$1 |
| 6 | +DEB_ARCH=$(dpkg --print-architecture) |
| 7 | +REPO=http://http.debian.net/debian |
| 8 | +KEY=https://ftp-master.debian.org/keys/archive-key-12.asc |
| 9 | +DISTRO=bookworm |
| 10 | + |
| 11 | +#Fix debconf frontend warnings |
| 12 | +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| 13 | +export DEBCONF_FRONTEND=noninteractive |
| 14 | +export DEBIAN_FRONTEND=noninteractive |
| 15 | +export TMPDIR=/tmp |
| 16 | +export TMP=/tmp |
| 17 | + |
| 18 | +ROOTFS=${DIR}/build |
| 19 | + |
| 20 | +function cleanup { |
| 21 | + |
| 22 | + mount | grep $ROOTFS || true |
| 23 | + mount | grep $ROOTFS | awk '{print "umounting "$1; system("umount "$3)}' || true |
| 24 | + mount | grep $ROOTFS || true |
| 25 | + |
| 26 | + echo "killing chroot services" |
| 27 | + lsof 2>&1 | grep $ROOTFS | awk '{print $1 $2}' | sort | uniq |
| 28 | + echo "chroot services after kill" |
| 29 | + lsof 2>&1 | grep $ROOTFS || true |
| 30 | +} |
| 31 | + |
| 32 | +cleanup |
| 33 | + |
| 34 | +rm -rf ${ROOTFS} |
| 35 | +apt update |
| 36 | +apt install -y debootstrap rsync |
| 37 | +debootstrap --no-check-gpg --include=\ |
| 38 | +avahi-daemon,\ |
| 39 | +bzip2,\ |
| 40 | +ca-certificates,\ |
| 41 | +curl,\ |
| 42 | +dbus,\ |
| 43 | +fancontrol,\ |
| 44 | +gnupg,\ |
| 45 | +less,\ |
| 46 | +locales,\ |
| 47 | +net-tools,\ |
| 48 | +ntp,\ |
| 49 | +openssh-server,\ |
| 50 | +parted,\ |
| 51 | +rsync,\ |
| 52 | +sudo,\ |
| 53 | +unzip,\ |
| 54 | +wget,\ |
| 55 | +wireless-tools \ |
| 56 | +--arch=${DEB_ARCH} ${DISTRO} ${ROOTFS} ${REPO} |
| 57 | + |
| 58 | +sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' ${ROOTFS}/etc/locale.gen |
| 59 | +echo "LC_ALL=en_US.UTF-8" >> ${ROOTFS}/etc/environment |
| 60 | +chroot ${ROOTFS} /bin/bash -c "locale-gen en_US en_US.UTF-8" |
| 61 | +chroot ${ROOTFS} wget ${KEY} -O archive.key |
| 62 | +chroot ${ROOTFS} apt-key add archive.key |
| 63 | +mount -v --bind /dev ${ROOTFS}/dev |
| 64 | +chroot ${ROOTFS} /bin/bash -c "echo \"root:syncloud\" | chpasswd" |
| 65 | + |
| 66 | +echo "copy system files to get image working" |
| 67 | +rsync -avhp --ignore-times --stats ${DIR}/files/common/ ${ROOTFS} |
| 68 | +rsync -avhp --ignore-times --stats ${DIR}/files/arch/${ARCH}/ ${ROOTFS} |
| 69 | +rsync -avhp --ignore-times --stats ${DIR}/files/distro/${DISTRO}/ ${ROOTFS} |
| 70 | +cp $DIR/../install.sh ${ROOTFS}/root |
| 71 | +grep localhost ${ROOTFS}/etc/hosts |
| 72 | +grep dev ${ROOTFS}/etc/fstab |
| 73 | +ls -la ${ROOTFS}/etc/network |
| 74 | +grep eth ${ROOTFS}/etc/network/interfaces |
| 75 | + |
| 76 | +sed -i -e'/AVAHI_DAEMON_DETECT_LOCAL/s/1/0/' ${ROOTFS}/etc/default/avahi-daemon |
| 77 | +sed -i "s/^.*PermitRootLogin.*/PermitRootLogin yes/g" ${ROOTFS}/etc/ssh/sshd_config |
| 78 | + |
| 79 | +umount ${ROOTFS}/dev |
| 80 | +cleanup |
| 81 | + |
| 82 | +echo "cleaning apt cache" |
| 83 | +rm -rf ${ROOTFS}/var/cache/apt/archives/*.deb |
| 84 | +tar cf $DIR/bootstrap.tar -C $ROOTFS . |
0 commit comments