-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-default.sh
More file actions
executable file
·82 lines (73 loc) · 1.87 KB
/
start-default.sh
File metadata and controls
executable file
·82 lines (73 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
#
# This starts the default template
#
# gnd @ gnd.sk, 2017 - 2019
#
####################################################################
# Check if LIMA_ROOT set
if [ -z $LIMA_ROOT ]; then
echo "Cant find LIMA. Please check if the install finished correctly."
echo "Exiting. Reason: LIMA_ROOT not set."
exit
fi
# Define globals
source $LIMA_ROOT/vms/settings
### waits until conection to new VM established
connect-ssh() {
local ip=${1}
local hostname=${2}
con=0
tries=0
draw_tries() { for ((i=0; i<try; i=i+1)); do printf "▇"; done }
clean_line() { printf "\r"; }
while [[ "$con" == "0" ]]; do
check=`ssh -q -o ConnectTimeout=1 -o StrictHostKeyChecking=no $ip hostname`
sleep 1
if [[ ! "$check" == "$hostname" ]]; then
clean_line
tries=$((tries+1))
draw_tries=$((tries % 100))
for (( try=1; try<=draw_tries; try=try+1 )); do
printf "Waiting for VM: "$tries"s "; draw_tries
clean_line
done
else
con=1
printf "\n\nVM up ! "
fi
done
}
# Ask what default VM to use
shopt -s extglob
echo "Please select what default VM to start:"
vms=`ls $VM_DIR/default/`
opts=`echo $vms|sed 's/ /|/g'`
opts=`echo "+($opts)"`
select vm in $vms
do
case $vm in
$vms)
echo "Choosing: $vm"
break
;;
*)
echo "Invalid: $vm"
;;
esac
done
DEF_VM=$vm
## Make sure the default instance is not running
CHECK=`virsh list --all|grep default`
if [[ ! -z $CHECK ]]; then
echo "Default instance is already running."
echo "Exiting."
else
### Start the default machine
echo "Starting the $DEF_VM virtual machine"
virsh create $VM_DIR/default/$DEF_VM/vm.xml
### Wait for the VM to come up
connect-ssh $DEFAULT_IP default
### Print connection data
echo "To connect use 'ssh $DEFAULT_IP'"
fi