xref: /freebsd/release/tools/gce.conf (revision 0b1c5628c74a37e2aa2aa3769c606d3e826302f8)
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
20vm_extra_install_base() {
21	echo 'search google.internal' > ${DESTDIR}/etc/resolv.conf
22	echo 'nameserver 169.254.169.254' >> ${DESTDIR}/etc/resolv.conf
23	echo 'nameserver 8.8.8.8' >> ${DESTDIR}/etc/resolv.conf
24}
25
26vm_extra_pre_umount() {
27	# Enable growfs on every boot, not only the first, as as instance's disk can
28	# be enlarged post-creation
29	sed -i -e '/KEYWORD: firstboot/d' /etc/rc.d/growfs
30
31	cat << EOF >> ${DESTDIR}/etc/rc.conf
32dumpdev="AUTO"
33ifconfig_DEFAULT="SYNCDHCP mtu 1460"
34ntpd_sync_on_start="YES"
35# need to fill in something here
36#firstboot_pkgs_list=""
37panicmail_autosubmit="YES"
38EOF
39
40	cat << EOF >> ${DESTDIR}/boot/loader.conf
41autoboot_delay="-1"
42beastie_disable="YES"
43loader_logo="none"
44hw.memtest.tests="0"
45console="comconsole,vidconsole"
46hw.vtnet.mq_disable=1
47kern.timecounter.hardware=ACPI-safe
48aesni_load="YES"
49nvme_load="YES"
50EOF
51
52	echo '169.254.169.254 metadata.google.internal metadata' >> \
53		${DESTDIR}/etc/hosts
54
55        # overwrite ntp.conf
56	cat << EOF > ${DESTDIR}/etc/ntp.conf
57server metadata.google.internal iburst
58
59restrict default kod nomodify notrap nopeer noquery
60restrict -6 default kod nomodify notrap nopeer noquery
61
62restrict 127.0.0.1
63restrict -6 ::1
64restrict 127.127.1.0
65EOF
66
67	cat << EOF >> ${DESTDIR}/etc/syslog.conf
68*.err;kern.warning;auth.notice;mail.crit                /dev/console
69EOF
70
71	cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config
72KbdInteractiveAuthentication no
73X11Forwarding no
74AcceptEnv LANG
75AllowAgentForwarding no
76ClientAliveInterval 420
77EOF
78
79	cat << EOF >> ${DESTDIR}/etc/crontab
800       3       *       *       *       root    /usr/sbin/freebsd-update cron
81EOF
82
83	cat << EOF >> ${DESTDIR}/etc/sysctl.conf
84net.inet.icmp.drop_redirect=1
85net.inet.ip.redirect=0
86kern.ipc.soacceptqueue=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	return 0
122}
123
124# Do everything except deleting resolv.conf since we construct our own
125# Googlized resolv.conf file in vm_extra_install_base.
126vm_emulation_cleanup() {
127	if ! [ -z "${QEMUSTATIC}" ]; then
128		rm -f ${DESTDIR}/${EMULATOR}
129	fi
130	umount_loop ${DESTDIR}/dev
131	return 0
132}
133