1278985Sgjb#!/bin/sh 2278985Sgjb# 3278985Sgjb# $FreeBSD: stable/10/release/tools/gce.conf 337908 2018-08-16 15:17:22Z gjb $ 4278985Sgjb# 5278985Sgjb 6278985Sgjb# Set to a list of packages to install. 7278985Sgjbexport VM_EXTRA_PACKAGES="firstboot-freebsd-update firstboot-pkgs \ 8337908Sgjb google-cloud-sdk panicmail sudo sysutils/py-google-compute-engine \ 9337908Sgjb lang/python lang/python2 lang/python3" 10278985Sgjb 11278985Sgjb# Set to a list of third-party software to enable in rc.conf(5). 12337908Sgjbexport VM_RC_LIST="ntpd sshd growfs \ 13331363Sgjb firstboot_pkgs firstboot_freebsd_update google_startup \ 14331717Sgjb google_accounts_daemon google_clock_skew_daemon \ 15337710Sgjb google_instance_setup google_network_daemon" 16278985Sgjb 17278985Sgjbvm_extra_install_base() { 18278985Sgjb echo 'search google.internal' > ${DESTDIR}/etc/resolv.conf 19278985Sgjb echo 'nameserver 169.254.169.254' >> ${DESTDIR}/etc/resolv.conf 20278985Sgjb echo 'nameserver 8.8.8.8' >> ${DESTDIR}/etc/resolv.conf 21278985Sgjb} 22278985Sgjb 23278985Sgjbvm_extra_pre_umount() { 24337710Sgjb # Enable growfs on every boot, not only the first, as as instance's disk can 25337710Sgjb # be enlarged post-creation 26337710Sgjb sed -i -e '/KEYWORD: firstboot/d' /etc/rc.d/growfs 27337710Sgjb 28278985Sgjb cat << EOF >> ${DESTDIR}/etc/rc.conf 29278985Sgjbdumpdev="AUTO" 30278985Sgjbifconfig_DEFAULT="SYNCDHCP mtu 1460" 31278985Sgjbntpd_sync_on_start="YES" 32278985Sgjb# need to fill in something here 33278985Sgjb#firstboot_pkgs_list="" 34278985Sgjbpanicmail_autosubmit="YES" 35278985SgjbEOF 36278985Sgjb 37278985Sgjb cat << EOF >> ${DESTDIR}/boot/loader.conf 38278985Sgjbautoboot_delay="-1" 39278985Sgjbbeastie_disable="YES" 40278985Sgjbloader_logo="none" 41278985Sgjbhw.memtest.tests="0" 42278985Sgjbconsole="comconsole,vidconsole" 43278985Sgjbhw.vtnet.mq_disable=1 44278985Sgjbkern.timecounter.hardware=ACPI-safe 45278985Sgjbaesni_load="YES" 46278985Sgjbnvme_load="YES" 47278985SgjbEOF 48278985Sgjb 49278985Sgjb echo '169.254.169.254 metadata.google.internal metadata' > \ 50278985Sgjb ${DESTDIR}/etc/hosts 51278985Sgjb 52278985Sgjb # overwrite ntp.conf 53278985Sgjb cat << EOF > ${DESTDIR}/etc/ntp.conf 54278985Sgjbserver metadata.google.internal iburst 55278985Sgjb 56278985Sgjbrestrict default kod nomodify notrap nopeer noquery 57278985Sgjbrestrict -6 default kod nomodify notrap nopeer noquery 58278985Sgjb 59278985Sgjbrestrict 127.0.0.1 60278985Sgjbrestrict -6 ::1 61278985Sgjbrestrict 127.127.1.0 62278985SgjbEOF 63278985Sgjb 64278985Sgjb cat << EOF >> ${DESTDIR}/etc/syslog.conf 65278985Sgjb*.err;kern.warning;auth.notice;mail.crit /dev/console 66278985SgjbEOF 67278985Sgjb 68278985Sgjb cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config 69278985SgjbChallengeResponseAuthentication no 70278985SgjbX11Forwarding no 71278985SgjbAcceptEnv LANG 72278985SgjbCiphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc 73278985SgjbAllowAgentForwarding no 74278985SgjbClientAliveInterval 420 75278985SgjbEOF 76278985Sgjb 77278985Sgjb cat << EOF >> ${DESTDIR}/etc/crontab 78278985Sgjb0 3 * * * root /usr/sbin/freebsd-update cron 79278985SgjbEOF 80278985Sgjb 81278985Sgjb cat << EOF >> ${DESTDIR}/etc/sysctl.conf 82278985Sgjbnet.inet.icmp.drop_redirect=1 83278985Sgjbnet.inet.ip.redirect=0 84278985Sgjbnet.inet.tcp.blackhole=2 85278985Sgjbnet.inet.udp.blackhole=1 86278985Sgjbkern.ipc.somaxconn=1024 87278985Sgjbdebug.trace_on_panic=1 88278985Sgjbdebug.debugger_on_panic=0 89278985SgjbEOF 90278985Sgjb 91333327Sgjb # To meet GCE marketplace requirements, extract the src.txz and 92333327Sgjb # ports.txz distributions to the target virtual machine disk image 93333327Sgjb # and fetch the sources for the third-party software installed on 94333327Sgjb # the image. 95333327Sgjb if [ ! -c "${DESTDIR}/dev/null" ]; then 96333327Sgjb mkdir -p ${DESTDIR}/dev 97333327Sgjb mount -t devfs devfs ${DESTDIR}/dev 98333327Sgjb fi 99333327Sgjb if [ -e "${DESTDIR}/../ftp/src.txz" ]; then 100333327Sgjb tar fxJ ${DESTDIR}/../ftp/src.txz -C ${DESTDIR} 101333327Sgjb fi 102333327Sgjb if [ -e "${DESTDIR}/../ftp/ports.txz" ]; then 103333327Sgjb tar fxJ ${DESTDIR}/../ftp/ports.txz -C ${DESTDIR} 104333327Sgjb _INSTALLED_PACKAGES=$(chroot ${DESTDIR} pkg info -o -q -a) 105333327Sgjb for PACKAGE in ${_INSTALLED_PACKAGES}; do 106333327Sgjb chroot ${DESTDIR} \ 107333327Sgjb make -C /usr/ports/${PACKAGE} fetch 108333327Sgjb done 109333327Sgjb fi 110333327Sgjb if [ -c "${DESTDIR}/dev/null" ]; then 111333327Sgjb umount_loop ${DESTDIR}/dev 112333327Sgjb fi 113333327Sgjb 114278985Sgjb ## XXX: Verify this is needed. I do not see this requirement 115278985Sgjb ## in the docs, and it impairs the ability to boot-test a copy 116278985Sgjb ## of the image prior to packaging for upload to GCE. 117278985Sgjb #sed -E -i '' 's/^([^#].*[[:space:]])on/\1off/' ${DESTDIR}/etc/ttys 118278985Sgjb 119278985Sgjb touch ${DESTDIR}/firstboot 120278985Sgjb 121326264Sgjb rm -f ${DESTDIR}/etc/resolv.conf 122326264Sgjb 123278985Sgjb return 0 124278985Sgjb} 125