Switch to using config files for most settings.

This is to make it easier to juggle all the settings.
This commit is contained in:
Tom Alexander 2023-05-29 18:35:30 -04:00
parent 5f4939c9e6
commit 26d3f7e736
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -21,16 +21,22 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# doas bhyve_netgraph_bridge start poudriere zdata/vm/poudriere /vm/poudriere jail_nat 10.215.1.1/24 /vm/iso/FreeBSD-13.2-RELEASE-amd64-bootonly.iso
# doas bhyve_netgraph_bridge start poudriere zdata/vm/poudriere /vm/poudriere jail_nat 10.215.1.1/24
: ${CPU_CORES:="1"}
: ${MEMORY:="1G"}
: ${NETWORK:="NAT"} # or RAW
: ${IP_RANGE:="10.215.1.1/24"} # Ignored for RAW networks
: ${INTERFACE_NAME:="jail_nat"} # or the external interface like lagg0 for RAW networks
: ${BRIDGE_NAME:="bridge_$INTERFACE_NAME"} # or bridge_raw for RAW networks
function main {
if [ "$1" = "create-disk" ]; then
cmd="$1"
shift 1
if [ "$cmd" = "create-disk" ]; then
create_disk "${@}"
elif [ "$1" = "start" ]; then
shift 1
elif [ "$cmd" = "start" ]; then
start_vm "${@}"
else
>&2 echo "Unrecognized command"
exit 1
die 1 "Unrecognized command $cmd"
fi
}
@ -48,9 +54,12 @@ function create_disk {
zfs create -o "mountpoint=$mount_path" "$zfs_path"
cp /usr/local/share/edk2-bhyve/BHYVE_UEFI_VARS.fd "${mount_path}/"
tee "${mount_path}/settings" <<EOF
CPU_CORES=1
MEMORY=1G
NETWORK=NAT
CPU_CORES="$CPU_CORES"
MEMORY="$MEMORY"
NETWORK="$NETWORK"
IP_RANGE="$IP_RANGE"
BRIDGE_NAME="$BRIDGE_NAME"
INTERFACE_NAME="$INTERFACE_NAME"
EOF
zfs create -s "-V${gigabytes}G" -o volmode=dev "$zfs_path/disk0"
}
@ -59,20 +68,19 @@ function start_vm {
name="$1"
zfs_path="$2"
mount_path="$3"
host_interface_name="$4" # for raw, external interface
bridge_name="bridge_${host_interface_name}"
ip_range="$5" # for raw this value does not matter
mount_cd="${6:-}"
mount_cd="${4:-}"
mac_address=$(calculate_mac_address "$name")
CPU_CORES=1
MEMORY=1G
NETWORK="NAT"
if [ -e "${mount_path}/settings" ]; then
source "${mount_path}/settings"
fi
host_interface_name="$INTERFACE_NAME" # for raw, external interface
bridge_name="$BRIDGE_NAME"
ip_range="$IP_RANGE" # for raw this value does not matter
mac_address=$(calculate_mac_address "$name")
if [ "$NETWORK" = "NAT" ]; then
assert_bridge "$host_interface_name" "$bridge_name" "$ip_range"
elif [ "$NETWORK" = "RAW" ]; then