141f7db3aSBrad Davis#!/bin/sh 241f7db3aSBrad Davis# 341f7db3aSBrad Davis# 441f7db3aSBrad Davis 5885f5b4aSGlen Barber# The default of 3GB is too small for Vagrant, so override the size here. 6fa04db47SGlen Barberexport VMSIZE=8g 7885f5b4aSGlen Barber 841f7db3aSBrad Davis# Packages to install into the image we're creating. This is a deliberately 941f7db3aSBrad Davis# minimalist set, providing only the packages necessary to bootstrap. 1083952a5bSBrad Davisexport VM_EXTRA_PACKAGES="${VM_EXTRA_PACKAGES} shells/bash \ 1183952a5bSBrad Davis firstboot-freebsd-update firstboot-pkgs" 1241f7db3aSBrad Davis 1341f7db3aSBrad Davis# Set to a list of third-party software to enable in rc.conf(5). 14885f5b4aSGlen Barberexport VM_RC_LIST="firstboot_freebsd_update firstboot_pkgs growfs" 1541f7db3aSBrad Davis 16a54bd595SBrad Davisvagrant_common () { 1741f7db3aSBrad Davis # The firstboot_pkgs rc.d script will download the repository 1841f7db3aSBrad Davis # catalogue and install or update pkg when the instance first 1941f7db3aSBrad Davis # launches, so these files would just be replaced anyway; removing 2041f7db3aSBrad Davis # them from the image allows it to boot faster. 216a277d6eSGlen Barber env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} clean -y -a 2241f7db3aSBrad Davis env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} delete -f -y pkg 23*078e8b34SColin Percival rm -r ${DESTDIR}/var/db/pkg/repos/FreeBSD 2441f7db3aSBrad Davis 2541f7db3aSBrad Davis # Vagrant instances use DHCP to get their network configuration. 2641f7db3aSBrad Davis echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf 2741f7db3aSBrad Davis 2841f7db3aSBrad Davis # Enable sshd by default 2941f7db3aSBrad Davis echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf 3041f7db3aSBrad Davis # Disable DNS lookups by default to make SSH connect quickly 3141f7db3aSBrad Davis echo 'UseDNS no' >> ${DESTDIR}/etc/ssh/sshd_config 3241f7db3aSBrad Davis 3341f7db3aSBrad Davis # Disable sendmail 3441f7db3aSBrad Davis echo 'sendmail_enable="NO"' >> ${DESTDIR}/etc/rc.conf 3541f7db3aSBrad Davis echo 'sendmail_submit_enable="NO"' >> ${DESTDIR}/etc/rc.conf 3641f7db3aSBrad Davis echo 'sendmail_outbound_enable="NO"' >> ${DESTDIR}/etc/rc.conf 3741f7db3aSBrad Davis echo 'sendmail_msp_queue_enable="NO"' >> ${DESTDIR}/etc/rc.conf 3841f7db3aSBrad Davis 3941f7db3aSBrad Davis # Create the vagrant user with a password of vagrant 4041f7db3aSBrad Davis /usr/sbin/pw -R ${DESTDIR} \ 4141f7db3aSBrad Davis groupadd vagrant -g 1001 4241f7db3aSBrad Davis chroot ${DESTDIR} mkdir -p /home/vagrant 4341f7db3aSBrad Davis /usr/sbin/pw -R ${DESTDIR} \ 4441f7db3aSBrad Davis useradd vagrant \ 4541f7db3aSBrad Davis -m -M 0755 -w yes -n vagrant -u 1001 -g 1001 -G 0 \ 4641f7db3aSBrad Davis -c 'Vagrant User' -d '/home/vagrant' -s '/bin/csh' 4741f7db3aSBrad Davis 4841f7db3aSBrad Davis # Change root's password to vagrant 4941f7db3aSBrad Davis echo 'vagrant' | /usr/sbin/pw -R ${DESTDIR} \ 5041f7db3aSBrad Davis usermod root -h 0 5141f7db3aSBrad Davis 5241f7db3aSBrad Davis # Configure sudo to allow the vagrant user 530fa637ffSJose Luis Duran echo 'vagrant ALL=(ALL:ALL) NOPASSWD: ALL' >> ${DESTDIR}/usr/local/etc/sudoers 5441f7db3aSBrad Davis 55ef35e5eaSJose Luis Duran # Configure the vagrant ssh keys 5641f7db3aSBrad Davis mkdir ${DESTDIR}/home/vagrant/.ssh 5741f7db3aSBrad Davis chmod 700 ${DESTDIR}/home/vagrant/.ssh 5841f7db3aSBrad Davis echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > ${DESTDIR}/home/vagrant/.ssh/authorized_keys 59ef35e5eaSJose Luis Duran echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN1YdxBpNlzxDqfJyw/QKow1F+wvG9hXGoqiysfJOn5Y vagrant insecure public key" >> ${DESTDIR}/home/vagrant/.ssh/authorized_keys 6041f7db3aSBrad Davis chown -R 1001 ${DESTDIR}/home/vagrant/.ssh 6141f7db3aSBrad Davis chmod 600 ${DESTDIR}/home/vagrant/.ssh/authorized_keys 6241f7db3aSBrad Davis 6341f7db3aSBrad Davis # Reboot quickly, Don't wait at the panic screen 6441f7db3aSBrad Davis echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf 6541f7db3aSBrad Davis echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf 6641f7db3aSBrad Davis echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf 6741f7db3aSBrad Davis 6841f7db3aSBrad Davis # The console is not interactive, so we might as well boot quickly. 6941f7db3aSBrad Davis echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf 7041f7db3aSBrad Davis 7141f7db3aSBrad Davis # The first time the VM boots, the installed "first boot" scripts 7241f7db3aSBrad Davis # should be allowed to run: 7341f7db3aSBrad Davis # * growfs (expand the filesystem to fill the provided disk) 7441f7db3aSBrad Davis # * firstboot_freebsd_update (install critical updates) 7541f7db3aSBrad Davis # * firstboot_pkgs (install packages) 7641f7db3aSBrad Davis touch ${DESTDIR}/firstboot 7741f7db3aSBrad Davis 7841f7db3aSBrad Davis return 0 7941f7db3aSBrad Davis} 80