2019-11-30 22:43:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-10-12 16:53:48 +00:00
|
|
|
if [ $# -ne 1 ]; then
|
|
|
|
echo "$0 ssh-keyfile"
|
|
|
|
echo " ssh-keyfile: ssh keys to add into the image"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-30 22:43:21 +00:00
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
2020-10-12 16:53:48 +00:00
|
|
|
SSH_KEYS=$1; shift
|
|
|
|
|
2021-02-08 21:53:15 +00:00
|
|
|
MAJOR_VERSION=3.13
|
2021-03-14 16:06:28 +00:00
|
|
|
MINOR_VERSION=2
|
2019-11-30 22:43:21 +00:00
|
|
|
IMAGE=alpine-minirootfs-$MAJOR_VERSION.$MINOR_VERSION-x86_64.tar.gz
|
2020-10-12 16:53:48 +00:00
|
|
|
|
2019-11-30 22:43:21 +00:00
|
|
|
RESOLVCONF=/etc/resolv.conf
|
|
|
|
|
2019-11-30 23:10:32 +00:00
|
|
|
working_directory=$(pwd -P)
|
2021-02-09 11:50:55 +00:00
|
|
|
#rootfs_tmpdir=$(mktemp -d)
|
|
|
|
rootfs_tmpdir=alpine_${MAJOR_VERSION}-${MINOR_VERSION}-rootfs
|
2020-10-12 16:53:48 +00:00
|
|
|
|
2021-03-14 16:06:28 +00:00
|
|
|
initramfs="$working_directory/initramfs-alpine-${MAJOR_VERSION}.${MINOR_VERSION}"
|
|
|
|
kernel="$working_directory/kernel-alpine-${MAJOR_VERSION}.${MINOR_VERSION}"
|
|
|
|
|
2020-10-12 16:53:48 +00:00
|
|
|
mkdir -p ${rootfs_tmpdir}
|
|
|
|
|
2019-11-30 22:43:21 +00:00
|
|
|
rootfs_url="http://dl-cdn.alpinelinux.org/alpine/v$MAJOR_VERSION/releases/x86_64/$IMAGE"
|
|
|
|
|
|
|
|
run_root () {
|
2020-10-12 16:53:48 +00:00
|
|
|
sudo chroot $rootfs_tmpdir /usr/bin/env \
|
2019-11-30 22:43:21 +00:00
|
|
|
PATH=/bin:/sbin \
|
|
|
|
/bin/sh -c "$*"
|
|
|
|
}
|
|
|
|
|
2020-10-18 07:47:53 +00:00
|
|
|
wget -c "$rootfs_url" -O "$IMAGE"
|
2019-11-30 22:43:21 +00:00
|
|
|
|
2020-10-12 16:53:48 +00:00
|
|
|
# keep right permissions, use sudo
|
|
|
|
sudo tar xf $IMAGE -C $rootfs_tmpdir
|
2019-11-30 22:43:21 +00:00
|
|
|
|
|
|
|
# Add SSH keys
|
2019-11-30 23:38:13 +00:00
|
|
|
run_root mkdir -p root/.ssh
|
2020-10-12 16:53:48 +00:00
|
|
|
sudo cp $SSH_KEYS $rootfs_tmpdir/root/.ssh/authorized_keys
|
2021-02-09 11:50:55 +00:00
|
|
|
run_root chown root:root /root/.ssh/authorized_keys
|
|
|
|
run_root chmod 0600 /root/.ssh/authorized_keys
|
|
|
|
run_root chmod 0700 /root/.ssh
|
2019-11-30 22:43:21 +00:00
|
|
|
|
|
|
|
# Import local resolv.conf.
|
2020-10-12 16:53:48 +00:00
|
|
|
sudo cp "$RESOLVCONF" $rootfs_tmpdir/etc/resolv.conf
|
2019-11-30 22:43:21 +00:00
|
|
|
|
|
|
|
# Make sure init is found by the kernel.
|
2020-10-18 07:47:53 +00:00
|
|
|
run_root ln -sf /sbin/init /init
|
2020-10-12 16:53:48 +00:00
|
|
|
|
|
|
|
run_root apk update
|
2021-03-14 16:16:07 +00:00
|
|
|
run_root apk add linux-lts openrc udev openssh rdnssd bonding vlan
|
2020-10-18 08:03:38 +00:00
|
|
|
# rdnssd
|
2020-10-12 16:53:48 +00:00
|
|
|
run_root rc-update add udev
|
|
|
|
run_root rc-update add udev-trigger
|
|
|
|
run_root rc-update add sshd
|
2021-02-09 11:50:55 +00:00
|
|
|
run_root rc-update add rdnssd
|
2020-10-18 08:03:38 +00:00
|
|
|
run_root rc-update add networking
|
|
|
|
run_root rc-update add hostname
|
2021-02-09 13:29:52 +00:00
|
|
|
run_root sed -i 's/root:!::0:::::/root:*::0:::::/' /etc/shadow
|
2020-10-18 07:47:53 +00:00
|
|
|
|
|
|
|
sudo tee "$rootfs_tmpdir/etc/network/interfaces" <<EOF
|
|
|
|
auto lo
|
|
|
|
iface lo inet loopback
|
|
|
|
|
|
|
|
auto eth0
|
|
|
|
iface eth0 inet6 manual
|
2021-03-14 16:06:28 +00:00
|
|
|
bond-master bond0
|
|
|
|
post-up /sbin/ip link set \$IFACE up
|
|
|
|
post-up /sbin/ip link set \$IFACE mtu 9000
|
|
|
|
|
|
|
|
auto eth1
|
|
|
|
iface eth1 inet6 manual
|
|
|
|
bond-master bond0
|
|
|
|
post-up /sbin/ip link set \$IFACE up
|
|
|
|
post-up /sbin/ip link set \$IFACE mtu 9000
|
|
|
|
|
|
|
|
auto bond0
|
|
|
|
iface bond0 inet6 manual
|
|
|
|
bond-miimon 500
|
|
|
|
bond-mode 4
|
|
|
|
post-up /sbin/ip link set \$IFACE up
|
|
|
|
post-up /sbin/ip link set \$IFACE mtu 9000
|
|
|
|
bond-slaves none
|
|
|
|
|
2020-10-18 07:47:53 +00:00
|
|
|
EOF
|
|
|
|
|
2020-10-12 16:53:48 +00:00
|
|
|
sudo tee "$rootfs_tmpdir/etc/hostname" <<EOF
|
2019-11-30 23:10:32 +00:00
|
|
|
alpine-unconfigured
|
|
|
|
EOF
|
|
|
|
|
2021-03-14 16:06:28 +00:00
|
|
|
# Cleanup resolv.conf
|
|
|
|
run_root rm -f /etc/resolv.conf
|
|
|
|
|
2020-10-18 08:03:38 +00:00
|
|
|
# Generate iniramfs image
|
2021-03-14 16:06:28 +00:00
|
|
|
(cd $rootfs_tmpdir; sudo find . | sudo cpio -H newc -o | gzip -9 > ${initramfs})
|
|
|
|
cp "$rootfs_tmpdir/boot/vmlinuz-lts" "${kernel}"
|
2020-10-12 16:53:48 +00:00
|
|
|
|
2020-10-18 08:03:38 +00:00
|
|
|
echo rm -rf "$rootfs_tmpdir"
|
2020-10-12 16:53:48 +00:00
|
|
|
|
2021-03-14 16:06:28 +00:00
|
|
|
echo "Use ${initramfs} and ${kernel} from $working_directory"!
|
2020-10-12 16:53:48 +00:00
|
|
|
|
|
|
|
exit 0
|