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 20# Hack for FreeBSD 15.0; should go away before 15.1. 21MISSING_METALOGS=" 22./usr/local/etc/instance_configs.cfg.distro 23./usr/local/etc/pam.d/sudo 24./usr/local/etc/sudo.conf 25./usr/local/etc/sudo_logsrvd.conf 26./usr/local/etc/sudoers 27./usr/local/etc/syslog.d/90-google.conf 28" 29 30vm_extra_install_base() { 31 echo 'search google.internal' > ${DESTDIR}/etc/resolv.conf 32 echo 'nameserver 169.254.169.254' >> ${DESTDIR}/etc/resolv.conf 33 echo 'nameserver 8.8.8.8' >> ${DESTDIR}/etc/resolv.conf 34 metalog_add_data ./etc/resolv.conf 35} 36 37vm_extra_pre_umount() { 38 local DEVFSISOURS 39 40 # Enable growfs on every boot, not only the first, as as instance's disk can 41 # be enlarged post-creation 42 sed -i -e '/KEYWORD: firstboot/d' ${DESTDIR}/etc/rc.d/growfs 43 44 cat << EOF >> ${DESTDIR}/etc/rc.conf 45dumpdev="AUTO" 46ifconfig_DEFAULT="SYNCDHCP mtu 1460" 47ntpd_sync_on_start="YES" 48# need to fill in something here 49#firstboot_pkgs_list="" 50panicmail_autosubmit="YES" 51EOF 52 53 cat << EOF >> ${DESTDIR}/boot/loader.conf 54autoboot_delay="-1" 55beastie_disable="YES" 56loader_logo="none" 57hw.memtest.tests="0" 58console="comconsole,vidconsole" 59kern.timecounter.hardware=ACPI-safe 60aesni_load="YES" 61nvme_load="YES" 62 63# Required for arm64. 64hw.pci.honor_msi_blacklist=0 65EOF 66 metalog_add_data ./boot/loader.conf 67 68 echo '169.254.169.254 metadata.google.internal metadata' >> \ 69 ${DESTDIR}/etc/hosts 70 71 # overwrite ntp.conf 72 cat << EOF > ${DESTDIR}/etc/ntp.conf 73server metadata.google.internal iburst 74 75restrict default kod nomodify notrap nopeer noquery 76restrict -6 default kod nomodify notrap nopeer noquery 77 78restrict 127.0.0.1 79restrict -6 ::1 80restrict 127.127.1.0 81EOF 82 83 cat << EOF >> ${DESTDIR}/etc/syslog.conf 84*.err;kern.warning;auth.notice;mail.crit /dev/console 85EOF 86 87 cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config 88KbdInteractiveAuthentication no 89X11Forwarding no 90AcceptEnv LANG 91AllowAgentForwarding no 92ClientAliveInterval 420 93EOF 94 95 cat << EOF >> ${DESTDIR}/etc/crontab 960 3 * * * root /usr/sbin/freebsd-update cron 97EOF 98 99 cat << EOF >> ${DESTDIR}/etc/sysctl.conf 100net.inet.icmp.drop_redirect=1 101net.inet.ip.redirect=0 102kern.ipc.soacceptqueue=1024 103debug.trace_on_panic=1 104debug.debugger_on_panic=0 105EOF 106 107 # To meet GCE marketplace requirements, extract the src.txz and 108 # ports.txz distributions to the target virtual machine disk image 109 # and fetch the sources for the third-party software installed on 110 # the image. 111 if [ -e "${DESTDIR}/../ftp/src.txz" ]; then 112 tar fxJ ${DESTDIR}/../ftp/src.txz -C ${DESTDIR} 113 ( cd ${DESTDIR} && find ./usr/src ) | 114 while read P; do 115 metalog_add_data ${P} 116 done 117 fi 118 if [ -e "${DESTDIR}/../ftp/ports.txz" ]; then 119 tar fxJ ${DESTDIR}/../ftp/ports.txz -C ${DESTDIR} 120 _INSTALLED_PACKAGES=$(pkg -r ${DESTDIR} info -o -q -a | grep -v ^base/) 121 for PACKAGE in ${_INSTALLED_PACKAGES}; do 122 make -C ${DESTDIR}/usr/ports/${PACKAGE} fetch \ 123 DISTDIR=${DESTDIR}/usr/ports/distfiles \ 124 DISABLE_VULNERABILITIES=YES \ 125 I_DONT_CARE_IF_MY_BUILDS_TARGET_THE_WRONG_RELEASE=YES 126 done 127 ( cd ${DESTDIR} && find ./usr/ports ) | 128 while read P; do 129 metalog_add_data ${P} 130 done 131 fi 132 133 ## XXX: Verify this is needed. I do not see this requirement 134 ## in the docs, and it impairs the ability to boot-test a copy 135 ## of the image prior to packaging for upload to GCE. 136 #sed -E -i '' 's/^([^#].*[[:space:]])on/\1off/' ${DESTDIR}/etc/ttys 137 138 return 0 139} 140 141# Do everything except deleting resolv.conf since we construct our own 142# Googlized resolv.conf file in vm_extra_install_base. 143vm_emulation_cleanup() { 144 if [ -n "${QEMUSTATIC}" ]; then 145 rm -f ${DESTDIR}/${EMULATOR} 146 fi 147 return 0 148} 149