| @@ -1,6 +1,7 @@ |
| 1 | 1 | #!/bin/sh |
| 2 | 2 | #- |
| 3 | 3 | # Copyright (c) 2013-2016 Juan Romero Pardines. |
| 4 | +# Copyright (c) 2017 Google |
| 4 | 5 | # All rights reserved. |
| 5 | 6 | # |
| 6 | 7 | # Redistribution and use in source and binary forms, with or without |
| @@ -29,7 +30,20 @@ readonly ARCH=$(uname -m) · 22 unmodified lines |
| 29 | 30 | |
| 30 | 31 | trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP |
| 31 | 32 | |
| 33 | +mount_pseudofs() { |
| 34 | + for f in sys dev proc; do |
| 35 | + mkdir -p $ROOTFSDIR/$f |
| 36 | + mount --bind /$f $ROOTFSDIR/$f |
| 37 | + done |
| 38 | +} |
| 39 | +umount_pseudofs() { |
| 40 | + umount -f $ROOTFSDIR/sys >/dev/null 2>&1 |
| 41 | + umount -f $ROOTFSDIR/dev >/dev/null 2>&1 |
| 42 | + umount -f $ROOTFSDIR/proc >/dev/null 2>&1 |
| 43 | +} |
| 44 | + |
| 32 | 45 | cleanup() { |
| 46 | + unmount_pseudofs |
| 33 | 47 | umount -f ${ROOTFSDIR}/boot 2>/dev/null |
| 34 | 48 | umount -f ${ROOTFSDIR} 2>/dev/null |
| 35 | 49 | if [ -e "$LOOPDEV" ]; then |
| @@ -113,7 +127,7 @@ fi · 77 unmodified lines |
| 113 | 127 | |
| 114 | 128 | # double check PLATFORM is supported... |
| 115 | 129 | case "$PLATFORM" in |
| 116 | | − bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|*-musl);; |
| 130 | + bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|GCP|*-musl);; |
| 117 | 131 | *) die "The $PLATFORM is not supported, exiting..." |
| 118 | 132 | esac |
| 119 | 133 | |
| @@ -212,6 +226,41 @@ ci20*) · 92 unmodified lines |
| 212 | 226 | dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1 |
| 213 | 227 | dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1 |
| 214 | 228 | ;; |
| 229 | +GCP*) |
| 230 | + # Setup GRUB |
| 231 | + mount_pseudofs |
| 232 | + chroot ${ROOTFSDIR} grub-install ${LOOPDEV} |
| 233 | + sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" ${ROOTFSDIR}/etc/default/grub |
| 234 | + chroot ${ROOTFSDIR} update-grub |
| 235 | + umount_pseudofs |
| 236 | + |
| 237 | + # Setup the GCP Guest services |
| 238 | + for _service in dhcpcd sshd agetty-console nanoklogd socklog-unix GCP-Guest-Initialization GCP-accounts GCP-clock-skew GCP-ip-forwarding ; do |
| 239 | + chroot ${ROOTFSDIR} ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service |
| 240 | + done |
| 241 | + |
| 242 | + # Turn off the agetty's since we can't use them anyway |
| 243 | + rm -v ${ROOTFSDIR}/etc/runit/runsvdir/default/agetty-tty* |
| 244 | + |
| 245 | + # Disable root login over ssh and lock account |
| 246 | + sed -i "s:PermitRootLogin yes:PermitRootLogin no:" ${ROOTFSDIR}/etc/ssh/sshd_config |
| 247 | + chroot ${ROOTFSDIR} passwd -l root |
| 248 | + |
| 249 | + # Set the Timezone |
| 250 | + chroot ${ROOTFSDIR} ln -svf /usr/share/zoneinfo/UTC /etc/localtime |
| 251 | + |
| 252 | + # Generate glibc-locales if necessary (this is a noop on musl) |
| 253 | + if [ "$PLATFORM" = GCP ] ; then |
| 254 | + chroot ${ROOTFSDIR} xbps-reconfigure -f glibc-locales |
| 255 | + fi |
| 256 | + |
| 257 | + # Remove SSH host keys (these will get rebuilt on first boot) |
| 258 | + rm -v ${ROOTFSDIR}/etc/ssh/*key* |
| 259 | + rm -v ${ROOTFSDIR}/etc/ssh/moduli |
| 260 | + |
| 261 | + # Force hte hostname since this isn't read from DHCP |
| 262 | + echo "void-GCE" > ${ROOTFSDIR}/etc/hostname |
| 263 | + ;; |
| 215 | 264 | esac |
| 216 | 265 | |
| 217 | 266 | mountpoint -q ${ROOTFSDIR}/boot && umount ${ROOTFSDIR}/boot |
| @@ -220,6 +269,17 @@ losetup -d $LOOPDEV · 2 unmodified lines |
| 220 | 269 | rmdir $ROOTFSDIR |
| 221 | 270 | |
| 222 | 271 | chmod 644 $FILENAME |
| 223 | | −info_msg "Successfully created $FILENAME image." |
| 272 | +case "$PLATFORM" in |
| 273 | + GCP*) |
| 274 | + mv void-GCP*.img disk.raw |
| 275 | + info_msg "Compressing disk.raw" |
| 276 | + tar Sczf "${FILENAME/.img/.tar.gz}" disk.raw |
| 277 | + rm disk.raw |
| 278 | + info_msg "Sucessfully created ${FILENAME/.img/.tar.gz/} image." |
| 279 | + ;; |
| 280 | + *) |
| 281 | + info_msg "Successfully created $FILENAME image." |
| 282 | + ;; |
| 283 | +esac |
| 224 | 284 | |
| 225 | 285 | # vim: set ts=4 sw=4 et: |