45 lines
1.3 KiB
Bash
Executable File
45 lines
1.3 KiB
Bash
Executable File
#!/bin/env bash
|
|
#Define variable names on env_scripts/common.sh
|
|
#VM_NETWORK=
|
|
#VM_BASE_DIR=
|
|
#Install dependencies
|
|
source env_scripts/common.sh
|
|
source env_scripts/functions.sh
|
|
detect_distro
|
|
|
|
case $DISTRO in
|
|
ubuntu|debian)
|
|
install_debian_ubuntu
|
|
;;
|
|
arch)
|
|
install_arch
|
|
;;
|
|
fedora)
|
|
install_fedora
|
|
;;
|
|
*)
|
|
print_error "Distribution not supported: $DISTRO"
|
|
print_info "Supported: Ubuntu, Debian, Arch, Fedora"
|
|
exit 1
|
|
;;
|
|
esac
|
|
sudo usermod -aG libvirt $(whoami)
|
|
sudo usermod -aG kvm $(whoami)
|
|
sudo systemctl enable libvirtd
|
|
sudo systemctl start libvirtd
|
|
|
|
mkdir -p "${VM_BASE_DIR}"/{images,xml,init,base,ssh}
|
|
#Isolated network
|
|
cp files/network-host-only.xml ${VM_BASE_DIR}/xml/network-host-only.xml
|
|
sed -i "s/YOURNETWORK/${VM_NETWORK_NAT}/g" ${VM_BASE_DIR}/xml/network-host-only.xml
|
|
virsh net-define ${VM_BASE_DIR}/xml/network-host-only.xml
|
|
virsh net-autostart ${VM_NETWORK_HOSTONLY}
|
|
virsh net-start ${VM_NETWORK_HOSTONLY}
|
|
#NAT
|
|
cp files/network-nat.xml ${VM_BASE_DIR}/xml/network-nat.xml
|
|
sed -i "s/YOURNETWORK/${VM_NETWORK_NAT}/g" ${VM_BASE_DIR}/xml/network-nat.xml
|
|
virsh net-define ${VM_BASE_DIR}/xml/network-nat.xml
|
|
virsh net-autostart ${VM_NETWORK_NAT}
|
|
virsh net-start ${VM_NETWORK_NAT}
|
|
newgrp libvirt
|