57 lines
1.9 KiB
Bash
57 lines
1.9 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Terraform? We roll our own.
|
||
|
|
||
|
# Stop git bash being stupid
|
||
|
export MSYS_NO_PATHCONV=1
|
||
|
|
||
|
# Set your own
|
||
|
VBOXMANAGE="C:/Program Files/Oracle/VirtualBox/vboxmanage"
|
||
|
COREOSAPPLIANCEIMAGE="D:/VirtualBox/OVA/fedora-coreos-39.20231119.3.0-virtualbox.x86_64.ova"
|
||
|
|
||
|
# Function to create VirtualBox VM, accepts name of VM as argument
|
||
|
create_vbox_vm() {
|
||
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
||
|
echo "error: create_vm() called without specifying a VM name"
|
||
|
echo "Usage: create_vm <name> <MAC Address>"
|
||
|
echo "Example: create_vm kube_control01 \"08:00:27:00:00:01\""
|
||
|
return
|
||
|
fi
|
||
|
|
||
|
"$VBOXMANAGE" import --vsys 0 --vmname "$1" $COREOSAPPLIANCEIMAGE
|
||
|
"$VBOXMANAGE" modifyvm $1 --nic1 bridged
|
||
|
"$VBOXMANAGE" modifyvm $1 --bridge-adapter1 "Intel(R) Ethernet Controller I225-V"
|
||
|
"$VBOXMANAGE" modifyvm $1 --macaddress1 $2
|
||
|
"$VBOXMANAGE" guestproperty set $1 "/Ignition/Config" "$(cat ignition/$1-boot.json)"
|
||
|
"$VBOXMANAGE" startvm $1 --type headless
|
||
|
}
|
||
|
|
||
|
# Templating for Butane files to replace hostname with name passed
|
||
|
# to lighter, then it calls butane to generate ignition files
|
||
|
# It's "lighter" than using jinja or some other bloat ;)
|
||
|
# This allows us to re-use the same butane YAML files for multiple hosts,
|
||
|
# we can substitute values with whatever we want.
|
||
|
lighter() {
|
||
|
if [ -z "$1" ]; then
|
||
|
echo "error: lighter() called without specifying a VM name"
|
||
|
echo "Usage: lighter() <name>"
|
||
|
return
|
||
|
fi
|
||
|
|
||
|
# Create temporary working copies
|
||
|
cp butane/boot.yaml butane/boot~.yaml
|
||
|
cp butane/full.yaml butane/full~.yaml
|
||
|
|
||
|
# Replace hostname token with name provided
|
||
|
hostnameToken="{{HOSTNAME}}"
|
||
|
sed -i -e "s/$hostnameToken/$1/g" butane/boot~.yaml
|
||
|
sed -i -e "s/$hostnameToken/$1/g" butane/full~.yaml
|
||
|
|
||
|
# Butane transpile to ignition files
|
||
|
butane butane/boot~.yaml > ignition/$1-boot.json
|
||
|
butane butane/full~.yaml > ignition/$1-full.json
|
||
|
|
||
|
# Cleanup mess
|
||
|
rm -f butane/*~.yaml
|
||
|
}
|