-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.sh
executable file
·95 lines (84 loc) · 2.17 KB
/
runtime.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
86
87
88
89
90
91
92
93
94
95
#!/bin/bash -i
#
# Ultimate GNS3 server installer for Linux host machines
#
# Runtime script
# Gets:
# * $1 = runtime location path
# * $2 = bridge interface name
#
# Author: Piotr J. Węgrzyn
# GitHub: https://github.com/piotrjwegrzyn/ug3si
# Environment params:
# * gns3ip = ip address
# * gns3path = location of runtime files
# * gns3bridge = bridge interface (libvirt interface)
# * gns3tap = tap interface (attached to bridge)
gns3ip=10.10.10.10
gns3path=$1
gns3bridge=$2
gns3tap=gns3tap
# VM params:
# * gns3mem = RAM size
# * gns3maxmem = maximum size of RAM+swap (gns3maxmem >= gns3mem)
# * gns3cores = CPU cores
gns3mem=4G
gns3maxmem=8G
gns3cores=4
echo "GNS3 server runtime"
ps aux | grep "GNS3" | grep -v "grep" > /dev/null
if [ $? -eq 0 ];
then
echo "GNS3 server is detected as running"
else
ip link show $gns3tap > /dev/null
if [ $? -ne 0 ];
then
echo "Configuring virtual network..."
# creating tap interface
sudo ip tuntap add dev $gns3tap mode tap user $(whoami)
# setting up tap interface
sudo ip link set $gns3tap up
# adding tap interface to bridge
sudo brctl addif $gns3bridge $gns3tap
else
echo "Recovering virtual network..."
# removing tap interface from bridge
sudo brctl delif $gns3bridge $gns3tap
sleep 1
# setting down and up tap interface
sudo ip link set $gns3tap down
sleep 1
sudo ip link set $gns3tap up
# adding tap interface to bridge
sudo brctl addif $gns3bridge $gns3tap
fi
echo "Starting GNS3 server..."
qemu-system-x86_64 -name "GNS3 server" -m $gns3mem,maxmem=$gns3maxmem -cpu host \
-smp cores=$gns3cores -enable-kvm -machine smm=off -boot order=c \
-drive file=$gns3path"GNS3 VM-disk001.qcow2",if=virtio,index=0,media=disk \
-drive file=$gns3path"GNS3 VM-disk002.qcow2",if=virtio,index=1,media=disk \
-device virtio-net-pci,netdev=nic0 \
-netdev tap,id=nic0,ifname=$gns3tap,script=no,downscript=no \
-display none -daemonize ; sleep 1
fi
echo "Checking reachability..."
i=8
while :
do
sleep 1
echo "."
i=$(($i-1))
ping -q -c 1 $gns3ip > /dev/null
if [ $? -eq 0 ];
then
break
fi
if [ $i -eq 0 ];
then
echo "GNS3 server is unreachable"
exit 1
fi
done
echo "Login to GNS3 server via ssh..."
ssh -A gns3@$gns3ip