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