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