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