#!/bin/sh
setxkbmap it
vms="$(ls /dev/vmm/*)"
vncs="vm$(ps ax | awk '/vncviewer [0]/{print $6}')"
echo "*** checkpoint 1"
echo "*** checkpoint 1"
echo "*** checkpoint 1"
printf 'Do you want to pass 1060 (a) or 2080ti (b) ?'
read answer
if [ "$answer" != "${answer#[a]}" ] ;then
#echo "pci100:" ${pci100="pci0:1:0:0"}
#echo "pci101:" ${pci101="pci0:1:0:1"}
pci100="pci0:1:0:0"
pci101="pci0:1:0:1"
echo ${pci100}
echo ${pci101}
else
#echo "pci200:" ${pci200="pci0:2:0:0"}
#echo "pci201:" ${pci201="pci0:2:0:1"}
#echo "pci202:" ${pci202="pci0:2:0:2"}
#echo "pci203:" ${pci203="pci0:2:0:3"}
pci200="pci0:2:0:0"
pci201="pci0:2:0:1"
pci202="pci0:2:0:2"
pci203="pci0:2:0:3"
echo ${pci200}
echo ${pci201}
echo ${pci202}
echo ${pci203}
fi
for vm in $vms; do
session="${vm##*/}"
echo "bhyve session = $session"
echo "vnc session = $vncs"
if ! pciconf -l pci0:1:0:0 | grep -q "^ppt"; then
echo "attach/detach driver ppt 1:0:0"
devctl detach ${pci100}
devctl set driver ${pci100} ppt
/bin/sh
fi
if ! pciconf -l pci0:1:0:1 | grep -q "^ppt"; then
echo "attach / detach driver ppt 1:0:1"
devctl detach ${pci101}
devctl set driver ${pci101} ppt
fi
if ! pciconf -l pci0:2:0:0 | grep -q "^ppt"; then
echo "attach / detach driver ppt 2:0:0"
devctl detach ${pci200}
devctl set driver ${pci200} ppt
fi
if ! pciconf -l pci0:2:0:1 | grep -q "^ppt"; then
echo "attach / detach driver ppt 2:0:1"
devctl detach ${pci201}
devctl set driver ${pci201} ppt
fi
if ! pciconf -l pci0:2:0:2 | grep -q "^ppt"; then
echo "attach / detach driver ppt 2:0:2"
devctl detach ${pci202}
devctl set driver ${pci202} ppt
fi
if ! pciconf -l pci0:2:0:3 | grep -q "^ppt"; then
echo "attach / detach driver ppt 2:0:3"
devctl detach ${pci203}
devctl set driver ${pci203} ppt
fi
if ! printf '%s\n' "${vncs}" | grep "${session}"; then
printf 'VNC session not found,destroying ghost vms\n'
bhyvectl --vm=$session --destroy
echo "*** checkpoint 2"
echo "*** checkpoint 2"
echo "*** checkpoint 2"
else
printf 'Found VNC session %s\n' "${session},no ghost vms found,not destroying them"
echo "*** checkpoint 3"
echo "*** checkpoint 3"
echo "*** checkpoint 3"
fi
done
echo "*** checkpoint 4"
echo "*** checkpoint 4"
echo "*** checkpoint 4"
vmdisk0=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (NM13N4CZ)/ && d{print d}'`
echo "Seagate M3 Portable 1.8 TB ; $vmdisk0"
vmdisk1=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (2015020204055E)/ && d{print d}'`
echo "TOSHIBA External USB 1.8 TB ; $vmdisk1"
vmdisk2=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (2022285F1175)/ && d{print d}'`
echo "CT1000P1SSD8 ; $vmdisk2"
vmdisk3=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (20130506005976F)/ && d{print d}'`
echo "TOSHIBA External USB 932GB ; echo $vmdisk3"
vmdisk4=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (BE0191500218)/ && d{print d}'`
echo "G-DISK ; $vmdisk4"
vmdisk5=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (38434B4237354B45)/ && d{print d}'`
echo "Elements ; $vmdisk5"
vmdisk6=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (WD-WCAV2X597309)/ && d{print d}'`
echo "WDC WD3200AAJS-00L7A0-298GB ; $vmdisk6"
vmdisk7=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (0774911DDC4200A6)/ && d{print d}'`
echo "SanDisk Cruzer-15GB ; $vmdisk7"
vmdisk8=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (60A44C4138D8F311190A0149)/ && d{print d}'`
echo "Kingston DataTraveler 2.0 ; $vmdisk8"
vmdisk9=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (20140100006C)/ && d{print d}'`
echo "SAMSUNG HM320JI ; $vmdisk9"
vmdisk10=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (1924E20B2AE5)/ && d{print d}'`
echo "CT500MX500SSD4 ; $vmdisk10"
mount -t ufs /dev/$vmdisk0'p2' /mnt/$vmdisk0'p2'
echo "*** checkpoint 5"
echo "*** checkpoint 5"
echo "*** checkpoint 5"
if [ "$answer" != "${answer#[a]}" ] ;then
bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,virtio-blk,/mnt/$vmdisk0'p2'/bhyve/img/Linux/ubuntu2004-SD.img,bootindex=1 \
-s 2,virtio-blk,/dev/$vmdisk3 \
-s 8:0,passthru,$pci100 \
-s 8:1,passthru,$pci101 \
-s 11,virtio-net,tap20 \
-s 12,virtio-9p,sharename=/ \
-s 13,hda,play=/dev/dsp,rec=/dev/dsp \
-s 29,fbuf,tcp=0.0.0.0:5920,w=1600,h=950 \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_BHF_CODE.fd \
vm0:20 < /dev/null & sleep 2 && vncviewer 0:20
else
bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,virtio-blk,/mnt/$vmdisk0'p2'/bhyve/img/Linux/ubuntu2004-SD.img,bootindex=1 \
-s 2,virtio-blk,/dev/$vmdisk3 \
-s 8:0,passthru,$pci200 \
-s 8:1,passthru,$pci201 \
-s 8:2,passthru,$pci202 \
-s 8:3,passthru,$pci203 \
-s 11,virtio-net,tap20 \
-s 12,virtio-9p,sharename=/ \
-s 13,hda,play=/dev/dsp,rec=/dev/dsp \
-s 29,fbuf,tcp=0.0.0.0:5920,w=1600,h=950 \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_BHF_CODE.fd \
vm0:20 < /dev/null & sleep 2 && vncviewer 0:20
fi
echo "*** checkpoint 6"
echo "*** checkpoint 6"
echo "*** checkpoint 6"