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