1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# Packages to install into the image we're creating.  This is a deliberately
7# minimalist set, providing only the packages necessary to bootstrap.
8export VM_EXTRA_PACKAGES="firstboot-freebsd-update firstboot-pkgs"
9
10# Set to a list of third-party software to enable in rc.conf(5).
11export VM_RC_LIST="firstboot_freebsd_update firstboot_pkgs"
12
13vagrant_common () {
14	# The firstboot_pkgs rc.d script will download the repository
15	# catalogue and install or update pkg when the instance first
16	# launches, so these files would just be replaced anyway; removing
17	# them from the image allows it to boot faster.
18	env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} clean -y -a
19	env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} delete -f -y pkg
20	rm ${DESTDIR}/var/db/pkg/repo-*.sqlite
21
22	# Vagrant instances use DHCP to get their network configuration.
23	echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf
24
25	# Enable sshd by default
26	echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf
27	# Disable DNS lookups by default to make SSH connect quickly
28	echo 'UseDNS no' >> ${DESTDIR}/etc/ssh/sshd_config
29
30	# Disable sendmail
31	echo 'sendmail_enable="NO"' >> ${DESTDIR}/etc/rc.conf
32	echo 'sendmail_submit_enable="NO"' >> ${DESTDIR}/etc/rc.conf
33	echo 'sendmail_outbound_enable="NO"' >> ${DESTDIR}/etc/rc.conf
34	echo 'sendmail_msp_queue_enable="NO"' >> ${DESTDIR}/etc/rc.conf
35
36	# Create the vagrant user with a password of vagrant
37	/usr/sbin/pw -R ${DESTDIR} \
38		groupadd vagrant -g 1001
39	chroot ${DESTDIR} mkdir -p /home/vagrant
40	/usr/sbin/pw -R ${DESTDIR} \
41		useradd vagrant \
42		-m -M 0755 -w yes -n vagrant -u 1001 -g 1001 -G 0 \
43		-c 'Vagrant User' -d '/home/vagrant' -s '/bin/csh'
44
45	# Change root's password to vagrant
46	echo 'vagrant' | /usr/sbin/pw -R ${DESTDIR} \
47		usermod root -h 0
48
49	# Configure sudo to allow the vagrant user
50	echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> ${DESTDIR}/usr/local/etc/sudoers
51
52	# Configure the vagrant ssh key
53	mkdir ${DESTDIR}/home/vagrant/.ssh
54	chmod 700 ${DESTDIR}/home/vagrant/.ssh
55	echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > ${DESTDIR}/home/vagrant/.ssh/authorized_keys
56	chown -R 1001 ${DESTDIR}/home/vagrant/.ssh
57	chmod 600 ${DESTDIR}/home/vagrant/.ssh/authorized_keys
58
59	# Reboot quickly, Don't wait at the panic screen
60	echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf
61	echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf
62	echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf
63
64	# The console is not interactive, so we might as well boot quickly.
65	echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf
66
67	# The first time the VM boots, the installed "first boot" scripts
68	# should be allowed to run:
69	# * growfs (expand the filesystem to fill the provided disk)
70	# * firstboot_freebsd_update (install critical updates)
71	# * firstboot_pkgs (install packages)
72	touch ${DESTDIR}/firstboot
73
74	return 0
75}
76