103 lines
2.4 KiB
Bash
Executable File
103 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build Debian root filesystem
|
|
|
|
IMAGE2="$1" # For example "/artifacts/debian-buster-armhf"
|
|
ARCH="$2" # For example "armhf"
|
|
DIST="$3" # For example "buster"
|
|
|
|
set -e
|
|
|
|
case "${ARCH}" in
|
|
armhf)
|
|
KERNEL=linux-image-armmp
|
|
;;
|
|
arm64)
|
|
KERNEL=linux-image-arm64
|
|
;;
|
|
*)
|
|
echo "Can't decide kernel package for \"${ARCH}\""
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Create fresh empty directory
|
|
TMP=$(mktemp -d tmp.XXXXXX)
|
|
cd "${TMP}"
|
|
|
|
# Build a Debian root filesystem (first stage)
|
|
debootstrap \
|
|
--arch="${ARCH}" \
|
|
--verbose \
|
|
--variant=minbase \
|
|
--foreign \
|
|
--include=\
|
|
netbase,\
|
|
ifupdown,\
|
|
net-tools,\
|
|
isc-dhcp-client,\
|
|
${KERNEL},\
|
|
systemd-sysv,\
|
|
u-boot-tools,\
|
|
openssh-server \
|
|
"${DIST}" \
|
|
debian \
|
|
"http://deb.debian.org/debian/"
|
|
|
|
# Randomly generated root password
|
|
PASSWORD=$(pwgen -B -A 6 1)
|
|
|
|
# Write apt sources config
|
|
case "${DIST}" in
|
|
sid)
|
|
tee debian/tmp/sources.list <<- EOF
|
|
deb http://deb.debian.org/debian ${DIST} main
|
|
deb-src http://deb.debian.org/debian ${DIST} main
|
|
EOF
|
|
;;
|
|
*)
|
|
tee debian/tmp/sources.list <<- EOF
|
|
deb http://deb.debian.org/debian ${DIST} main
|
|
deb-src http://deb.debian.org/debian ${DIST} main
|
|
deb http://deb.debian.org/debian ${DIST}-updates main
|
|
deb-src http://deb.debian.org/debian ${DIST}-updates main
|
|
deb http://security.debian.org/debian-security ${DIST}/updates main
|
|
deb-src http://security.debian.org/debian-security ${DIST}/updates main
|
|
EOF
|
|
;;
|
|
esac
|
|
|
|
cp -rv --preserve=mode ../2nd-stage-files/pre-2nd-stage-files/* debian
|
|
cp -rv --preserve=mode ../2nd-stage-files/pre-2nd-stage-files-${ARCH}/* debian
|
|
|
|
# Copy ARM emulation stuff
|
|
cp -v /usr/bin/qemu-*-static debian/usr/bin || :
|
|
|
|
# Build a Debian root filesystem (second stage)
|
|
chroot debian /bin/sh -e <<- EOF
|
|
/debootstrap/debootstrap --second-stage
|
|
/bin/mv /tmp/sources.list /etc/apt/sources.list
|
|
/usr/bin/apt-get update
|
|
/usr/bin/apt-get -y upgrade
|
|
/usr/bin/apt-get clean
|
|
/bin/rm -rf /var/lib/apt/lists/*
|
|
/bin/rm -f /var/log/*.log
|
|
/bin/echo root:${PASSWORD} | /usr/sbin/chpasswd
|
|
/bin/sed -i "s/#*\s*PermitRootLogin .*/PermitRootLogin yes/" /etc/ssh/sshd_config
|
|
EOF
|
|
|
|
# Remove ARM emulation stuff again
|
|
rm -v debian/usr/bin/qemu-*-static || :
|
|
|
|
cp -rv --preserve=mode ../2nd-stage-files/post-2nd-stage-files/* debian
|
|
|
|
# List all files
|
|
find debian ! -type d -printf "/%P\n" | sort > "/artifacts/debian-${DIST}-${ARCH}.files.txt"
|
|
|
|
# Make a ext4 filesystem of this and put it into the image
|
|
rm -f ext4.img
|
|
fallocate -l 900MiB ext4.img
|
|
mkfs.ext4 -d debian ext4.img
|
|
gzip ext4.img
|
|
|
|
cp -v ext4.img.gz "${IMAGE2}-${PASSWORD}.bin.gz"
|