|
@@ -1,6 +1,7 @@
|
|
|
#!/bin/sh
|
|
|
#-
|
|
|
# Copyright (c) 2013-2016 Juan Romero Pardines.
|
|
|
+# Copyright (c) 2017 Google
|
|
|
# All rights reserved.
|
|
|
#
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -29,7 +30,20 @@ readonly ARCH=$(uname -m)
|
|
|
|
|
|
trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP
|
|
|
|
|
|
+mount_pseudofs() {
|
|
|
+ for f in sys dev proc; do
|
|
|
+ mkdir -p $ROOTFSDIR/$f
|
|
|
+ mount --bind /$f $ROOTFSDIR/$f
|
|
|
+ done
|
|
|
+}
|
|
|
+umount_pseudofs() {
|
|
|
+ umount -f $ROOTFSDIR/sys >/dev/null 2>&1
|
|
|
+ umount -f $ROOTFSDIR/dev >/dev/null 2>&1
|
|
|
+ umount -f $ROOTFSDIR/proc >/dev/null 2>&1
|
|
|
+}
|
|
|
+
|
|
|
cleanup() {
|
|
|
+ unmount_pseudofs
|
|
|
umount -f ${ROOTFSDIR}/boot 2>/dev/null
|
|
|
umount -f ${ROOTFSDIR} 2>/dev/null
|
|
|
if [ -e "$LOOPDEV" ]; then
|
|
@@ -113,7 +127,7 @@ fi
|
|
|
|
|
|
# double check PLATFORM is supported...
|
|
|
case "$PLATFORM" in
|
|
|
- bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|*-musl);;
|
|
|
+ bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|GCP|*-musl);;
|
|
|
*) die "The $PLATFORM is not supported, exiting..."
|
|
|
esac
|
|
|
|
|
@@ -212,6 +226,41 @@ ci20*)
|
|
|
dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1
|
|
|
dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1
|
|
|
;;
|
|
|
+GCP*)
|
|
|
+ # Setup GRUB
|
|
|
+ mount_pseudofs
|
|
|
+ chroot ${ROOTFSDIR} grub-install ${LOOPDEV}
|
|
|
+ sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" ${ROOTFSDIR}/etc/default/grub
|
|
|
+ chroot ${ROOTFSDIR} update-grub
|
|
|
+ umount_pseudofs
|
|
|
+
|
|
|
+ # Setup the GCP Guest services
|
|
|
+ for _service in dhcpcd sshd agetty-console nanoklogd socklog-unix GCP-Guest-Initialization GCP-accounts GCP-clock-skew GCP-ip-forwarding ; do
|
|
|
+ chroot ${ROOTFSDIR} ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service
|
|
|
+ done
|
|
|
+
|
|
|
+ # Turn off the agetty's since we can't use them anyway
|
|
|
+ rm -v ${ROOTFSDIR}/etc/runit/runsvdir/default/agetty-tty*
|
|
|
+
|
|
|
+ # Disable root login over ssh and lock account
|
|
|
+ sed -i "s:PermitRootLogin yes:PermitRootLogin no:" ${ROOTFSDIR}/etc/ssh/sshd_config
|
|
|
+ chroot ${ROOTFSDIR} passwd -l root
|
|
|
+
|
|
|
+ # Set the Timezone
|
|
|
+ chroot ${ROOTFSDIR} ln -svf /usr/share/zoneinfo/UTC /etc/localtime
|
|
|
+
|
|
|
+ # Generate glibc-locales if necessary (this is a noop on musl)
|
|
|
+ if [ "$PLATFORM" = GCP ] ; then
|
|
|
+ chroot ${ROOTFSDIR} xbps-reconfigure -f glibc-locales
|
|
|
+ fi
|
|
|
+
|
|
|
+ # Remove SSH host keys (these will get rebuilt on first boot)
|
|
|
+ rm -v ${ROOTFSDIR}/etc/ssh/*key*
|
|
|
+ rm -v ${ROOTFSDIR}/etc/ssh/moduli
|
|
|
+
|
|
|
+ # Force hte hostname since this isn't read from DHCP
|
|
|
+ echo "void-GCE" > ${ROOTFSDIR}/etc/hostname
|
|
|
+ ;;
|
|
|
esac
|
|
|
|
|
|
mountpoint -q ${ROOTFSDIR}/boot && umount ${ROOTFSDIR}/boot
|
|
@@ -220,6 +269,17 @@ losetup -d $LOOPDEV
|
|
|
rmdir $ROOTFSDIR
|
|
|
|
|
|
chmod 644 $FILENAME
|
|
|
-info_msg "Successfully created $FILENAME image."
|
|
|
+case "$PLATFORM" in
|
|
|
+ GCP*)
|
|
|
+ mv void-GCP*.img disk.raw
|
|
|
+ info_msg "Compressing disk.raw"
|
|
|
+ tar Sczf "${FILENAME/.img/.tar.gz}" disk.raw
|
|
|
+ rm disk.raw
|
|
|
+ info_msg "Sucessfully created ${FILENAME/.img/.tar.gz/} image."
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ info_msg "Successfully created $FILENAME image."
|
|
|
+ ;;
|
|
|
+esac
|
|
|
|
|
|
# vim: set ts=4 sw=4 et:
|