-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.sh
More file actions
62 lines (52 loc) · 1.3 KB
/
interfaces.sh
File metadata and controls
62 lines (52 loc) · 1.3 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
#!/bin/bash
add_interfaces() {
local team_count=$1
for ((i = 1; i <= team_count; i++)); do
if [[ "$i" -eq 10 ]]; then
continue
fi
pvesh create /nodes/$(hostname)/network \
-iface "ctf$i" \
-type bridge \
-cidr "10.10.$i.255/24" \
-comments "CTF NAT team$i" \
-autostart 1
done
pvesh create /nodes/$(hostname)/network \
-iface "ctf_org" \
-type bridge \
-cidr "10.10.10.255/24" \
-comments "CTF NAT org" \
-autostart 1
ifreload -a
}
delete_interfaces() {
local team_count=$1
for ((i = 1; i <= team_count; i++)); do
if [[ "$i" -eq 10 ]]; then
continue
fi
pvesh delete "/nodes/$(hostname)/network/ctf$i"
done
pvesh delete /nodes/$(hostname)/network/ctf_org
ifreload -a
}
team_count=$2
if [[ -z "$team_count" ]]; then
echo -e "Incorrect team count.\nexample: $0 <command> 10"
exit 1
fi
if ! [[ "$team_count" =~ ^[0-9]+$ ]]; then
echo -e "Team count must be positive.\nexample: $0 <command> 10"
exit 2
fi
if [[ "$1" == "create" ]]; then
echo "Adding $team_count interfaces and ctf_org..."
add_interfaces "$team_count"
elif [[ "$1" == "delete" ]]; then
echo "Deleting ctf1..ctf$team_count and ctf_org..."
delete_interfaces "$team_count"
else
echo "usage: $0 <create|delete> <team_count>"
exit 3
fi