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