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' /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" 59hw.vtnet.mq_disable=1 60kern.timecounter.hardware=ACPI-safe 61aesni_load="YES" 62nvme_load="YES" 63EOF 64 metalog_add_data ./boot/loader.conf 65 66 echo '169.254.169.254 metadata.google.internal metadata' >> \ 67 ${DESTDIR}/etc/hosts 68 69 # overwrite ntp.conf 70 cat << EOF > ${DESTDIR}/etc/ntp.conf 71server metadata.google.internal iburst 72 73restrict default kod nomodify notrap nopeer noquery 74restrict -6 default kod nomodify notrap nopeer noquery 75 76restrict 127.0.0.1 77restrict -6 ::1 78restrict 127.127.1.0 79EOF 80 81 cat << EOF >> ${DESTDIR}/etc/syslog.conf 82*.err;kern.warning;auth.notice;mail.crit /dev/console 83EOF 84 85 cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config 86KbdInteractiveAuthentication no 87X11Forwarding no 88AcceptEnv LANG 89AllowAgentForwarding no 90ClientAliveInterval 420 91EOF 92 93 cat << EOF >> ${DESTDIR}/etc/crontab 940 3 * * * root /usr/sbin/freebsd-update cron 95EOF 96 97 cat << EOF >> ${DESTDIR}/etc/sysctl.conf 98net.inet.icmp.drop_redirect=1 99net.inet.ip.redirect=0 100kern.ipc.soacceptqueue=1024 101debug.trace_on_panic=1 102debug.debugger_on_panic=0 103EOF 104 105 # To meet GCE marketplace requirements, extract the src.txz and 106 # ports.txz distributions to the target virtual machine disk image 107 # and fetch the sources for the third-party software installed on 108 # the image. 109 if [ -e "${DESTDIR}/../ftp/src.txz" ]; then 110 tar fxJ ${DESTDIR}/../ftp/src.txz -C ${DESTDIR} 111 ( cd ${DESTDIR} && find ./usr/src ) | 112 while read P; do 113 metalog_add_data ${P} 114 done 115 fi 116 if [ -e "${DESTDIR}/../ftp/ports.txz" ]; then 117 tar fxJ ${DESTDIR}/../ftp/ports.txz -C ${DESTDIR} 118 _INSTALLED_PACKAGES=$(pkg -r ${DESTDIR} info -o -q -a | grep -v ^base/) 119 for PACKAGE in ${_INSTALLED_PACKAGES}; do 120 make -C ${DESTDIR}/usr/ports/${PACKAGE} fetch \ 121 DISTDIR=${DESTDIR}/usr/ports/distfiles \ 122 DISABLE_VULNERABILITIES=YES \ 123 I_DONT_CARE_IF_MY_BUILDS_TARGET_THE_WRONG_RELEASE=YES 124 done 125 ( cd ${DESTDIR} && find ./usr/ports ) | 126 while read P; do 127 metalog_add_data ${P} 128 done 129 fi 130 131 ## XXX: Verify this is needed. I do not see this requirement 132 ## in the docs, and it impairs the ability to boot-test a copy 133 ## of the image prior to packaging for upload to GCE. 134 #sed -E -i '' 's/^([^#].*[[:space:]])on/\1off/' ${DESTDIR}/etc/ttys 135 136 return 0 137} 138 139# Do everything except deleting resolv.conf since we construct our own 140# Googlized resolv.conf file in vm_extra_install_base. 141vm_emulation_cleanup() { 142 if [ -n "${QEMUSTATIC}" ]; then 143 rm -f ${DESTDIR}/${EMULATOR} 144 fi 145 return 0 146} 147