1284893Sbrd#!/bin/sh 2284893Sbrd# 3284893Sbrd# $FreeBSD$ 4284893Sbrd# 5284893Sbrd 6284893Sbrd# Packages to install into the image we're creating. This is a deliberately 7284893Sbrd# minimalist set, providing only the packages necessary to bootstrap. 8284893Sbrdexport VM_EXTRA_PACKAGES="firstboot-freebsd-update firstboot-pkgs" 9284893Sbrd 10284893Sbrd# Set to a list of third-party software to enable in rc.conf(5). 11284893Sbrdexport VM_RC_LIST="firstboot_freebsd_update firstboot_pkgs" 12284893Sbrd 13285814Sgjbvagrant_common () { 14284893Sbrd # The firstboot_pkgs rc.d script will download the repository 15284893Sbrd # catalogue and install or update pkg when the instance first 16284893Sbrd # launches, so these files would just be replaced anyway; removing 17284893Sbrd # them from the image allows it to boot faster. 18285814Sgjb env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} clean -y -a 19284893Sbrd env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} delete -f -y pkg 20284893Sbrd rm ${DESTDIR}/var/db/pkg/repo-*.sqlite 21284893Sbrd 22284893Sbrd # Vagrant instances use DHCP to get their network configuration. 23284893Sbrd echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf 24284893Sbrd 25284893Sbrd # Enable sshd by default 26284893Sbrd echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf 27284893Sbrd # Disable DNS lookups by default to make SSH connect quickly 28284893Sbrd echo 'UseDNS no' >> ${DESTDIR}/etc/ssh/sshd_config 29284893Sbrd 30284893Sbrd # Disable sendmail 31284893Sbrd echo 'sendmail_enable="NO"' >> ${DESTDIR}/etc/rc.conf 32284893Sbrd echo 'sendmail_submit_enable="NO"' >> ${DESTDIR}/etc/rc.conf 33284893Sbrd echo 'sendmail_outbound_enable="NO"' >> ${DESTDIR}/etc/rc.conf 34284893Sbrd echo 'sendmail_msp_queue_enable="NO"' >> ${DESTDIR}/etc/rc.conf 35284893Sbrd 36284893Sbrd # Create the vagrant user with a password of vagrant 37284893Sbrd /usr/sbin/pw -R ${DESTDIR} \ 38284893Sbrd groupadd vagrant -g 1001 39284893Sbrd chroot ${DESTDIR} mkdir -p /home/vagrant 40284893Sbrd /usr/sbin/pw -R ${DESTDIR} \ 41284893Sbrd useradd vagrant \ 42284893Sbrd -m -M 0755 -w yes -n vagrant -u 1001 -g 1001 -G 0 \ 43284893Sbrd -c 'Vagrant User' -d '/home/vagrant' -s '/bin/csh' 44284893Sbrd 45284893Sbrd # Change root's password to vagrant 46284893Sbrd echo 'vagrant' | /usr/sbin/pw -R ${DESTDIR} \ 47284893Sbrd usermod root -h 0 48284893Sbrd 49284893Sbrd # Configure sudo to allow the vagrant user 50284893Sbrd echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> ${DESTDIR}/usr/local/etc/sudoers 51284893Sbrd 52284893Sbrd # Configure the vagrant ssh key 53284893Sbrd mkdir ${DESTDIR}/home/vagrant/.ssh 54284893Sbrd chmod 700 ${DESTDIR}/home/vagrant/.ssh 55284893Sbrd echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > ${DESTDIR}/home/vagrant/.ssh/authorized_keys 56284893Sbrd chown -R 1001 ${DESTDIR}/home/vagrant/.ssh 57284893Sbrd chmod 600 ${DESTDIR}/home/vagrant/.ssh/authorized_keys 58284893Sbrd 59284893Sbrd # Reboot quickly, Don't wait at the panic screen 60284893Sbrd echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf 61284893Sbrd echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf 62284893Sbrd echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf 63284893Sbrd 64284893Sbrd # The console is not interactive, so we might as well boot quickly. 65284893Sbrd echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf 66284893Sbrd 67284893Sbrd # The first time the VM boots, the installed "first boot" scripts 68284893Sbrd # should be allowed to run: 69284893Sbrd # * growfs (expand the filesystem to fill the provided disk) 70284893Sbrd # * firstboot_freebsd_update (install critical updates) 71284893Sbrd # * firstboot_pkgs (install packages) 72284893Sbrd touch ${DESTDIR}/firstboot 73284893Sbrd 74284893Sbrd return 0 75284893Sbrd} 76