Adding VM build script.

This commit is contained in:
Scott Duensing 2021-08-07 18:47:53 -05:00
parent ad949fdf68
commit 3dbcf4d7dd

139
scripts/build-VM.sh Executable file
View file

@ -0,0 +1,139 @@
#!/bin/bash -ex
#
# JoeyLib
# Copyright (C) 2018-2019 Scott Duensing <scott@kangaroopunch.com>
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
#
DIST=hirsute
BOX=ubuntu/${DIST}64
TARGET="/home/scott/VirtualBox VMs/JoeyDevVM/ubuntu-hirsute-21.04-cloudimg-configdrive.vmdk"
if [[ "$1" != "continue" ]]; then
:<<'SKIP'
apt-get update
apt-get -y install vagrant virtualbox
vagrant plugin install vagrant-disksize
mkdir -p installerWork
pushd installerWork
cat <<-VARS > vars.sh
#!/bin/bash
export SOMETHING=${SOMETHING}
VARS
chmod ugo+x vars.sh
cp "${JOEY}/joeylib/scripts/installer.sh" .
popd
SKIP
[[ -d vagrant ]] && rm -rf vagrant
mkdir -p vagrant
pushd vagrant
cat <<-VAGRANTFILE > Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "${BOX}"
config.vm.network "public_network", bridge: "$(ip route | awk '/default/ { print $5 }')"
#config.vm.synced_folder "../installerWork", "/installer"
config.vm.provider "virtualbox" do |vm|
vm.name = "JoeyDevVM"
vm.gui = false
vm.memory = 2048
vm.cpus = 2
end
config.vm.provision "shell", path: "../build-VM.sh", args: "continue"
end
VAGRANTFILE
vagrant box update
vagrant box prune
vagrant up
vagrant halt
vagrant package
mv -f package.box ../.
popd
rm -rf vagrant
sha256sum package.box > package.box.sha256
else
#source /installer/vars.sh
cat <<-SOURCES > /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu ${DIST} main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu ${DIST} main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST}-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu ${DIST}-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST}-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu ${DIST}-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu ${DIST}-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu ${DIST}-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu ${DIST} partner
deb-src http://archive.canonical.com/ubuntu ${DIST} partner
SOURCES
apt-get update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get -y autoremove
apt-get -y install virtualbox-guest-utils
hostname joeydev
echo joeydev > /etc/hostname
echo 127.0.0.1 localhost joeydev > /etc/hosts
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT/#GRUB_CMDLINE_LINUX_DEFAULT/' /etc/default/grub
sed -i 's/GRUB_TIMEOUT=0/GRUB_TIMEOUT=3/' /etc/default/grub
sed -i 's/GRUB_TIMEOUT=hidden/GRUB_TIMEOUT_STYLE=menu/' /etc/default/grub
update-grub
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
echo "joeydev:joeydev:::Joey Dev:/home/joeydev:/bin/bash" | newusers
usermod -aG sudo joeydev
mkdir -p /opt/joey
chown joeydev:joeydev /opt/joey
pushd /opt/joey
wget https://skunkworks.kangaroopunch.com/skunkworks/joeylib/raw/master/scripts/installer.sh
chown joeydev:joeydev installer.sh
chmod +x installer.sh
popd
su - joeydev -c "cd /opt/joey && ./installer.sh AUTOMATED joeydev"
rm -rf /opt/joey/installerWork
apt-get -y clean
set +e
dd if=/dev/zero of=/zzdummy
set -e
rm -f /zzdummy
/sbin/shutdown -h now
fi