-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullRun.sh
85 lines (68 loc) · 1.91 KB
/
fullRun.sh
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
83
84
85
#!/bin/bash
set -x
cd
sudo apt-get update
sudo apt-get install -y qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker sshpass expect
cat << END > cloud-init1.txt
#cloud-config
password: Password
chpasswd: { expire: False }
ssh_pwauth: True
hostname: centos1
END
cloud-localds centos1.iso cloud-init1.txt
sudo wget http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-20140929_01.qcow2
qemu-img create -f qcow2 -b CentOS-7-x86_64-GenericCloud-20140929_01.qcow2 centos1.qcow2
sudo virt-install --name centos1 --memory 2048 \
--disk ~/centos1.qcow2,device=disk,bus=virtio \
--disk ~/centos1.iso,device=cdrom \
--os-type linux --os-variant centos7.0 \
--virt-type kvm --noautoconsole
domid=$(sudo virsh list |grep centos| awk '{print $1}')
echo $domid
for i in {1..60}; do
sleep 10
sudo virsh list
t=$(sudo virsh list | grep centos1 | grep running | wc -l)
if [ $t -eq 0 ]; then
echo "Waiting a little longer for VM to be running"
continue
fi
sudo virsh domifaddr $domid
ip=$(sudo virsh domifaddr $domid|grep vnet|awk '{print $4}'|sed 's/\/24//')
if [ -z $ip ] ; then
echo "Waiting a little longer to get an IP"
else
break
fi
done
if [ -z $ip ] ; then
echo "VM is still not up after a long time; aborting"
exit 1
else
echo "Centos7 VM IP=$ip"
fi
echo "Wait for ssh to come up ..."
for i in {1..10}; do
t=$(nc -zv $ip 22 2>&1 | grep succeeded |wc -l)
if [ $t -eq 0 ]; then
echo "ssh still not up ..."
sleep 10
else
break
fi
done
if [ $t -eq 0 ]; then
echo "ssh never came up; aborting ..."
exit 1
fi
# Let's not clobber the one you might already have
#
cp ~/.ssh/config ~/.ssh/backup_ssh_config123
cat << END > .ssh/config
Host 192.168.122.*
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
END
./setRoot.sh $ip Password
sshpass -p Password ssh root@$ip "some command as root"