e0831f8b68
- use current dir as working dir - add network config - add hostname
73 lines
1.8 KiB
Bash
Executable file
73 lines
1.8 KiB
Bash
Executable file
#!/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
|
|
|
|
working_directory=$(pwd -P)
|
|
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
|
|
run_root mkdir root/.ssh
|
|
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.
|
|
cat $RESOLVCONF > $rootfs_tmpdir/etc/resolv.conf
|
|
|
|
# Make sure init is found by the kernel.
|
|
run_root ln -s /sbin/init /init
|
|
|
|
cat > $rootfs_tmpdir/etc/network/interfaces <<EOF
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
auto eth0
|
|
iface eth0 inet6 auto
|
|
post-up ip addr show dev eth0 | grep inet6 | tee -a /etc/issue
|
|
EOF
|
|
|
|
cat > $rootfs_tmpdir/etc/hostname <<EOF
|
|
alpine-unconfigured
|
|
EOF
|
|
|
|
# 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
|
|
run_root rc-update add sshd
|
|
run_root rc-update add networking
|
|
|
|
# Generate iniramfs image
|
|
(cd $rootfs_tmpdir; find . | cpio -H newc -o | gzip -9 > "$working_directory/alpine-initramfs.gz")
|
|
cp $rootfs_tmpdir/boot/vmlinuz-vanilla "$working_directory/alpine-kernel"
|
|
|
|
# Upload to netboot server.
|
|
scp alpine-initramfs.gz alpine-kernel root@netboot.hack4glarus.ungleich.cloud:/var/www/html/
|
|
|
|
# Cleanup.
|
|
rm -r $rootfs_tmpdir
|
|
(cd "$working_directory/"; rm vmlinuz-vanilla alpine-kernel $IMAGE)
|