2019-11-30 22:43:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
|
|
|
MAJOR_VERSION=3.10
|
|
|
|
MINOR_VERSION=3
|
|
|
|
IMAGE=alpine-minirootfs-$MAJOR_VERSION.$MINOR_VERSION-x86_64.tar.gz
|
|
|
|
SSH_KEYS=$(cat ~/.ssh/id_rsa.pub)
|
|
|
|
RESOLVCONF=/etc/resolv.conf
|
|
|
|
|
2019-11-30 23:10:32 +00:00
|
|
|
working_directory=$(pwd -P)
|
2019-11-30 22:43:21 +00:00
|
|
|
rootfs_tmpdir=$(mktemp -d)
|
|
|
|
rootfs_url="http://dl-cdn.alpinelinux.org/alpine/v$MAJOR_VERSION/releases/x86_64/$IMAGE"
|
|
|
|
|
|
|
|
run_root () {
|
|
|
|
chroot $rootfs_tmpdir /usr/bin/env \
|
|
|
|
PATH=/bin:/sbin \
|
|
|
|
/bin/sh -c "$*"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$(whoami)" != 'root' ]; then
|
|
|
|
echo "This script must be run as root." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Download, extract inital rootfs.
|
|
|
|
curl "$rootfs_url" -o "$working_directory/$IMAGE"
|
|
|
|
tar xf $IMAGE -C $rootfs_tmpdir
|
|
|
|
|
|
|
|
# Add SSH keys
|
2019-11-30 23:38:13 +00:00
|
|
|
run_root mkdir -p root/.ssh
|
2019-11-30 22:43:21 +00:00
|
|
|
echo $SSH_KEYS > $rootfs_tmpdir/root/.ssh/authorized_keys
|
|
|
|
run_root chmod 0600 root/.ssh/authorized_keys
|
|
|
|
run_root chmod 0700 root/.ssh
|
|
|
|
|
|
|
|
# Import local resolv.conf.
|
2019-11-30 23:38:13 +00:00
|
|
|
cat "$RESOLVCONF" > $rootfs_tmpdir/etc/resolv.conf
|
2019-11-30 22:43:21 +00:00
|
|
|
|
|
|
|
# Make sure init is found by the kernel.
|
|
|
|
run_root ln -s /sbin/init /init
|
|
|
|
|
2019-12-01 00:18:21 +00:00
|
|
|
# Servers have static addresses, disable the standard
|
|
|
|
# alpine setting of using tempaddr = 2
|
|
|
|
cat > "$rootfs_tmpdir/etc/sysctl.d/99-ipv6.conf" <<EOF
|
|
|
|
net.ipv6.conf.default.use_tempaddr = 0
|
|
|
|
net.ipv6.conf.all.use_tempaddr = 0
|
|
|
|
|
|
|
|
net.ipv6.conf.all.accept_ra = 1
|
|
|
|
EOF
|
|
|
|
|
2019-11-30 23:38:13 +00:00
|
|
|
cat > "$rootfs_tmpdir/etc/network/interfaces" <<EOF
|
2019-11-30 23:10:32 +00:00
|
|
|
auto lo
|
|
|
|
iface lo inet loopback
|
|
|
|
|
|
|
|
auto eth0
|
2019-11-30 23:38:13 +00:00
|
|
|
iface eth0 inet6 manual
|
2019-12-01 00:18:21 +00:00
|
|
|
pre-up ip link set eth0 up
|
2019-11-30 23:38:13 +00:00
|
|
|
post-up ip addr show dev eth0 | grep inet6 >> /etc/issue
|
2019-12-01 00:18:21 +00:00
|
|
|
post-up echo post post up >> /etc/issue
|
2019-11-30 23:10:32 +00:00
|
|
|
EOF
|
|
|
|
|
2019-11-30 23:38:13 +00:00
|
|
|
cat > "$rootfs_tmpdir/etc/hostname" <<EOF
|
2019-11-30 23:10:32 +00:00
|
|
|
alpine-unconfigured
|
|
|
|
EOF
|
|
|
|
|
2019-12-01 00:18:21 +00:00
|
|
|
echo ipv6 >> "$rootfs_tmpdir/etc/modules"
|
|
|
|
|
2019-11-30 22:43:21 +00:00
|
|
|
# Layer atop base rootfs.
|
|
|
|
run_root apk update
|
|
|
|
run_root apk upgrade
|
|
|
|
run_root apk add openssh linux-vanilla openrc udev
|
|
|
|
run_root rc-update add udev
|
2019-12-01 00:18:21 +00:00
|
|
|
run_root rc-update add udev-trigger
|
2019-11-30 22:43:21 +00:00
|
|
|
run_root rc-update add sshd
|
2019-11-30 23:10:32 +00:00
|
|
|
run_root rc-update add networking
|
2019-11-30 23:11:42 +00:00
|
|
|
run_root rc-update add hostname
|
2019-11-30 22:43:21 +00:00
|
|
|
|
2019-11-30 23:38:13 +00:00
|
|
|
# FIXME: add / install rdnssd / ndisc6 / start it on boot
|
|
|
|
# ndisc6 is only @testing
|
|
|
|
|
2019-11-30 22:43:21 +00:00
|
|
|
# Generate iniramfs image
|
|
|
|
(cd $rootfs_tmpdir; find . | cpio -H newc -o | gzip -9 > "$working_directory/alpine-initramfs.gz")
|
2019-11-30 23:38:13 +00:00
|
|
|
cp "$rootfs_tmpdir/boot/vmlinuz-vanilla" "$working_directory/alpine-kernel"
|
2019-11-30 22:43:21 +00:00
|
|
|
|
|
|
|
# Cleanup.
|
2019-12-01 00:18:21 +00:00
|
|
|
#rm -r "$rootfs_tmpdir"
|
2019-11-30 23:38:13 +00:00
|
|
|
|
|
|
|
# Upload to netboot server. - needs to be done outside sudo
|
|
|
|
echo "Use alpine-initramfs.gz alpine-kernel from $working_directory"!
|