1#!/bin/sh 2# 3# $FreeBSD$ 4# 5 6# Set to a list of packages to install. 7export VM_EXTRA_PACKAGES="firstboot-freebsd-update firstboot-pkgs \ 8 google-cloud-sdk panicmail sudo sysutils/py-google-compute-engine" 9 10# Set to a list of third-party software to enable in rc.conf(5). 11export VM_RC_LIST="ntpd sshd growfs\ 12 firstboot_pkgs firstboot_freebsd_update google_startup \ 13 google_accounts_daemon google_clock_skew_daemon \ 14 google_instance_setup google_network_daemon" 15 16vm_extra_install_base() { 17 echo 'search google.internal' > ${DESTDIR}/etc/resolv.conf 18 echo 'nameserver 169.254.169.254' >> ${DESTDIR}/etc/resolv.conf 19 echo 'nameserver 8.8.8.8' >> ${DESTDIR}/etc/resolv.conf 20} 21 22vm_extra_pre_umount() { 23 # Enable growfs on every boot, not only the first, as as instance's disk can 24 # be enlarged post-creation 25 sed -i -e '/KEYWORD: firstboot/d' /etc/rc.d/growfs 26 27 cat << EOF >> ${DESTDIR}/etc/rc.conf 28dumpdev="AUTO" 29ifconfig_DEFAULT="SYNCDHCP mtu 1460" 30ntpd_sync_on_start="YES" 31# need to fill in something here 32#firstboot_pkgs_list="" 33panicmail_autosubmit="YES" 34EOF 35 36 cat << EOF >> ${DESTDIR}/boot/loader.conf 37autoboot_delay="-1" 38beastie_disable="YES" 39loader_logo="none" 40hw.memtest.tests="0" 41console="comconsole,vidconsole" 42hw.vtnet.mq_disable=1 43kern.timecounter.hardware=ACPI-safe 44aesni_load="YES" 45nvme_load="YES" 46EOF 47 48 echo '169.254.169.254 metadata.google.internal metadata' > \ 49 ${DESTDIR}/etc/hosts 50 51 # overwrite ntp.conf 52 cat << EOF > ${DESTDIR}/etc/ntp.conf 53server metadata.google.internal iburst 54 55restrict default kod nomodify notrap nopeer noquery 56restrict -6 default kod nomodify notrap nopeer noquery 57 58restrict 127.0.0.1 59restrict -6 ::1 60restrict 127.127.1.0 61EOF 62 63 cat << EOF >> ${DESTDIR}/etc/syslog.conf 64*.err;kern.warning;auth.notice;mail.crit /dev/console 65EOF 66 67 cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config 68ChallengeResponseAuthentication no 69X11Forwarding no 70AcceptEnv LANG 71AllowAgentForwarding no 72ClientAliveInterval 420 73EOF 74 75 cat << EOF >> ${DESTDIR}/etc/crontab 760 3 * * * root /usr/sbin/freebsd-update cron 77EOF 78 79 cat << EOF >> ${DESTDIR}/etc/sysctl.conf 80net.inet.icmp.drop_redirect=1 81net.inet.ip.redirect=0 82net.inet.tcp.blackhole=2 83net.inet.udp.blackhole=1 84kern.ipc.somaxconn=1024 85debug.trace_on_panic=1 86debug.debugger_on_panic=0 87EOF 88 89 # To meet GCE marketplace requirements, extract the src.txz and 90 # ports.txz distributions to the target virtual machine disk image 91 # and fetch the sources for the third-party software installed on 92 # the image. 93 if [ ! -c "${DESTDIR}/dev/null" ]; then 94 mkdir -p ${DESTDIR}/dev 95 mount -t devfs devfs ${DESTDIR}/dev 96 fi 97 if [ -e "${DESTDIR}/../ftp/src.txz" ]; then 98 tar fxJ ${DESTDIR}/../ftp/src.txz -C ${DESTDIR} 99 fi 100 if [ -e "${DESTDIR}/../ftp/ports.txz" ]; then 101 tar fxJ ${DESTDIR}/../ftp/ports.txz -C ${DESTDIR} 102 _INSTALLED_PACKAGES=$(chroot ${DESTDIR} pkg info -o -q -a) 103 for PACKAGE in ${_INSTALLED_PACKAGES}; do 104 chroot ${DESTDIR} \ 105 make -C /usr/ports/${PACKAGE} fetch 106 done 107 fi 108 if [ -c "${DESTDIR}/dev/null" ]; then 109 umount_loop ${DESTDIR}/dev 110 fi 111 112 ## XXX: Verify this is needed. I do not see this requirement 113 ## in the docs, and it impairs the ability to boot-test a copy 114 ## of the image prior to packaging for upload to GCE. 115 #sed -E -i '' 's/^([^#].*[[:space:]])on/\1off/' ${DESTDIR}/etc/ttys 116 117 touch ${DESTDIR}/firstboot 118 119 rm -f ${DESTDIR}/etc/resolv.conf 120 121 return 0 122} 123