forked from xzjt/EVE-NG-RVO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
137 lines (115 loc) · 3.29 KB
/
deploy.sh
File metadata and controls
137 lines (115 loc) · 3.29 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# This scirpt is made by Pete.
# It is used for deploy new code to EVE-NG Community 203.110 platform
# DO NOT USE IT ON ANY OTHER VERSION OF EVE-NG
# Email pete19890813@gmail.com
# Feel free to contact me if you have any problem.
ciscokeygen='/opt/unetlab/scripts/CiscoKeyGen.py'
user=$(whoami)
if [ "$user" != "root" ]; then
echo '[!] Current user not root, please change user as root to exceute this script.'
exit 1
fi
sudo dpkg -l | grep eve > /dev/null
if [ $? -ne 0 ]; then
echo '[!] eve-ng is not installed on current system, exit.'
exit 1
fi
if [ -d ./html ] && [ -d /opt/unetlab ]; then
cp -r ./html /opt/unetlab
if [ $? -ne 0 ]; then
echo '[-] Copy folder "html" to "/opt/unetlab" failed'
htmlcp='failed'
else
echo '[+] Copy folder "html" to "/opt/unetlab" success!'
fi
fi
if [ -d ./wrappers ] && [ -d /opt/unetlab ]; then
cp -r ./wrappers /opt/unetlab
if [ $? -ne 0 ]; then
echo '[-] Copy folder "wrappers" to "/opt/unetlab" failed'
wrappers='failed'
else
echo '[+] Copy folder "wrappers" to "/opt/unetlab" success!'
fi
fi
if [ -d ./scripts ] && [ -d /opt/unetlab ]; then
cp -r ./scripts /opt/unetlab
if [ $? -ne 0 ]; then
echo '[-] Copy folder "scripts" to "/opt/unetlab" failed'
scrptscp='failed'
else
echo '[+] Copy folder "scripts" to "/opt/unetlab" success!'
fi
fi
grep -P 'www-data.*ALL=' /etc/sudoers > /dev/null
if [ $? -ne 0 ]; then
sed -i 's#root\t\+.\+ALL$#&\nwww-data ALL=(ALL:ALL) NOPASSWD:ALL#' /etc/sudoers
grep -P '^root\t+ALL=' /etc/sudoers > /dev/null
if [ $? -ne 0 ]; then
echo '[-] Add user www-data to sudoers failed'
sudoers='failed'
else
echo '[+] Add user www-data to sudoers success!'
fi
else
echo '[-] User www-data is alreay in sudoers!'
fi
if [ ! -x $ciscokeygen ]; then
chmod +x $ciscokeygen
if [ $? -ne 0 ]; then
echo '[-] Change CiscoKeygen.py to excutable failed.'
else
echo '[+] Change CiscokeyGen.py to excuteable success!'
ln -s $ciscokeygen /usr/bin/CiscoKeyGen
fi
fi
if [ "$wrappers" != "failed" ]; then
sudo /opt/unetlab/wrappers/unl_wrapper -exia fixpermissions
if [ $? -ne 0 ]; then
echo '[-] fix permissions failed.'
exit 1
else
echo '[+] fix permissions success!'
fi
fi
sudo apt update -y > /dev/null
sudo apt install php7.0-gd dnsmasq iptables > /dev/null
cat > /opt/unetlab/dhcp_nat_autoconfig.sh <<EOF
#!/bin/bash
checkpnetnat=$(ip link | grep pnet1)
if [[ "$checkpnetnat" = "" ]]; then
brctl addbr pnet1;
fi
ip link set dev pnet1 up
ip addr add 10.0.137.1/24 dev pnet1 > /dev/null 2>&1
iptables -t nat -D POSTROUTING -o pnet0 -s 10.0.137.1/24 -j MASQUERADE > /dev/null 2>&1
iptables -t nat -A POSTROUTING -o pnet0 -s 10.0.137.1/24 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
exit 0
EOF
sudo chmod +x /opt/unetlab/dhcp_nat_autoconfig.sh
cat > /etc/rc.local <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/opt/unetlab/dhcp_nat_autoconfig.sh
/usr/local/sbin/dkms_install_fastlinq.sh
exit 0
EOF
cat > /etc/dnsmasq.conf <<EOF
interface=pnet1
dhcp-range=10.0.137.10,10.0.137.254,255.255.255.0
dhcp-option=3,10.0.137.1
EOF
sudo systemctl restart dnsmasq > /dev/null
exit 0