commit 9383d6dc16d86623ae31a1e5f033b6393a4b5f5c Author: Andrew R. M Date: Sun Feb 27 17:03:21 2022 -0500 First step in personal vagrant dev machine setup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86e0025 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +data/ +personal +.vagrant diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..3f8cd2d --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,89 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +unless ENV["VAGRANT_BYPASS_REQUIRED_PLUGINS"] + required_plugins = [ "vagrant-disksize", "vagrant-vbguest", "vagrant-reload" ] + plugins_installed = required_plugins.reduce(true) do |pi, rp| + pi && Vagrant.has_plugin?(rp) + end + + unless plugins_installed + STDERR.puts "ERROR: Required plugins not installed!" + STDERR.puts "This vagrant configuration requires the following plugins: #{required_plugins.join(' ')}" + STDERR.puts "Please install these using the `vagrant plugin install` command and try again" + exit 127 + end +end + +gui_enabled = ENV['VAGRANT_GUI'] || true + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + config.vm.box = "ubuntu/focal64" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Share a folder between guest and host for convenience + config.vm.synced_folder File.join(".", "data"), "/media/data" + + # Use vagrant-disksize plugin to resize disk as desired + config.disksize.size = ENV["VAGRANT_DISKSIZE"] || "20GB" + + config.vm.provider "virtualbox" do |vb| + vb.memory = ENV['VAGRANT_MEMORY'] || 1024 * 8 + vb.cpus = ENV['VAGRANT_CPUS'] || 4 + + # Graphical settings + vb.gui = gui_enabled + if gui_enabled + vb.customize ["modifyvm", :id, "--monitorcount", (ENV['VAGRANT_MONITORS'] || '1')] + vb.customize ["modifyvm", :id, "--graphicscontroller", "vboxsvga"] + vb.customize ["modifyvm", :id, "--vram", "128"] + end + end + + config.vm.define "default", primary: true do |primary| + end + + config.vm.define "test", autostart: false do |test| + end + + config.vm.provision :shell, + name: "Install Minimal XFCE", + path: "provisioners/install-xfce-minimal.sh" \ + if gui_enabled + + config.vm.provision :shell, + name: "Install Nix", + path: "provisioners/install-nix.sh", + privileged: false + + config.vm.provision :shell, + name: "Install APT Packages", + path: "provisioners/install-apt-packages.sh" + + config.vm.provision :shell, + name: "Cleanup tasks", + inline: <<~SHELLEND + userdel ubuntu + SHELLEND + + # Run any personal customization that exist outside git + if Dir.exists?('personal') + Dir['personal/*.sh'].each do |script| + config.vm.provision :shell, path: script, privileged: false + end + end + + config.vm.provision :reload +end diff --git a/provisioners/install-apt-packages.sh b/provisioners/install-apt-packages.sh new file mode 100644 index 0000000..3439070 --- /dev/null +++ b/provisioners/install-apt-packages.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Installs utility packages for general development. + +# A list of packages to install +apt_packages=( + # Docker setup + "docker" + "docker-compose" + + # General utilities + "dos2unix" + "tree" + "git" + "vim" + "expect" + "jq" + + # For encryption in git + "git-crypt" +) + +# If the list of packages to install isn't empty install the whole list +install_apt_packages() +{ + export DEBIAN_FRONTEND="noninteractive" + if [ "${apt_packages[*]}" ]; then + apt-get -qy install "${apt_packages[@]}" + fi +} + +install_apt_packages diff --git a/provisioners/install-nix.sh b/provisioners/install-nix.sh new file mode 100644 index 0000000..f1284f8 --- /dev/null +++ b/provisioners/install-nix.sh @@ -0,0 +1,129 @@ +#!/usr/bin/env bash + +# Install the Nix package manager as a secondary package manager. +# This can sometimes be useful for getting more recent packages. + +set -e + +# Abort installation if Nix is already installed +if [ -d /nix ]; then + exit 0 +fi + +# Download the Nix installer and it's signature from NixOS.org +curl -so install-nix https://releases.nixos.org/nix/nix-2.3.6/install +curl -so install-nix.asc https://releases.nixos.org/nix/nix-2.3.6/install.asc + +# Verify the signature matches Eelco Dolstra's +# Fetching from keyservers fails and is somewhat unreliable. +# To avoid intermittent failures we have written the key out in this file +gpg --import < ~vagrant/.bashrc +# Source nix if it's installed +if [ -r ~/.nix-profile/etc/profile.d/nix.sh ]; then + . ~/.nix-profile/etc/profile.d/nix.sh +fi +EOF + +# Remove the installer and signature +rm -f ./install-nix{,.asc} diff --git a/provisioners/install-xfce-minimal.sh b/provisioners/install-xfce-minimal.sh new file mode 100755 index 0000000..755f476 --- /dev/null +++ b/provisioners/install-xfce-minimal.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Ensure that no interactive prompts are used +export DEBIAN_FRONTEND=noninteractive + +# Additional pacakges to ensure a nice experience +additional_packages=( + xfce4 + xfce4-terminal + xfce4-whiskermenu-plugin + menulibre + firefox + pinentry-gtk2 + policykit-desktop-privileges +) +apt-get install -qy "${additional_packages[@]}" || exit 1 + +# Install a minimal xubuntu desktop +apt-get install --no-install-recommends -qy xubuntu-desktop || exit 1