]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/tools/gce.conf
Merge bmake-20230208
[FreeBSD/FreeBSD.git] / release / tools / gce.conf
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # The default of 3GB is too small for GCE, so override the size here.
7 export VMSIZE=20g
8
9 # Set to a list of packages to install.
10 export 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).
16 export 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
21 vm_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
27 vm_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
33 dumpdev="AUTO"
34 ifconfig_DEFAULT="SYNCDHCP mtu 1460"
35 ntpd_sync_on_start="YES"
36 # need to fill in something here
37 #firstboot_pkgs_list=""
38 panicmail_autosubmit="YES"
39 EOF
40
41         cat << EOF >> ${DESTDIR}/boot/loader.conf
42 autoboot_delay="-1"
43 beastie_disable="YES"
44 loader_logo="none"
45 hw.memtest.tests="0"
46 console="comconsole,vidconsole"
47 hw.vtnet.mq_disable=1
48 kern.timecounter.hardware=ACPI-safe
49 aesni_load="YES"
50 nvme_load="YES"
51 EOF
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
58 server metadata.google.internal iburst
59
60 restrict default kod nomodify notrap nopeer noquery
61 restrict -6 default kod nomodify notrap nopeer noquery
62
63 restrict 127.0.0.1
64 restrict -6 ::1
65 restrict 127.127.1.0
66 EOF
67
68         cat << EOF >> ${DESTDIR}/etc/syslog.conf
69 *.err;kern.warning;auth.notice;mail.crit                /dev/console
70 EOF
71
72         cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config
73 KbdInteractiveAuthentication no
74 X11Forwarding no
75 AcceptEnv LANG
76 AllowAgentForwarding no
77 ClientAliveInterval 420
78 EOF
79
80         cat << EOF >> ${DESTDIR}/etc/crontab
81 0       3       *       *       *       root    /usr/sbin/freebsd-update cron
82 EOF
83
84         cat << EOF >> ${DESTDIR}/etc/sysctl.conf
85 net.inet.icmp.drop_redirect=1
86 net.inet.ip.redirect=0
87 net.inet.tcp.blackhole=2
88 net.inet.udp.blackhole=1
89 kern.ipc.soacceptqueue=1024
90 debug.trace_on_panic=1
91 debug.debugger_on_panic=0
92 EOF
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 }