forked from milos85vasic/Server-Factory-Qemu-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_bridge.sh
executable file
·59 lines (42 loc) · 1.37 KB
/
delete_bridge.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
#!/bin/sh
tap=$1
script_path="/tmp"
bridge_script_path="$script_path/qemu_bridge.sh"
scripts_path=$(sh "$script_path/qemu_scripts_path.sh")
log=$(sh "$scripts_path/get_machine_log_name.sh" "$tap")
count=$(sh "$scripts_path/get_running_machines_count.sh")
if [ "$count" = "0" ] || [ "$count" = "" ]; then
echo "No running qemu machines detected"
else
echo "Running qemu machines detected: $count"
fi
if sudo test -e "$log"; then
if sudo rm -f "$log"; then
echo "Log removed: $log"
else
echo "WARNING: Log not removed: $log"
fi
fi
if [ "$count" = "1" ] || [ "$count" = "0" ]; then
if test -e "$bridge_script_path"; then
bridge=$(sh "$bridge_script_path")
if sudo sysctl -w net.inet.ip.forwarding=0 >/dev/null 2>&1 &&
sudo sysctl -w net.link.ether.inet.proxyall=0 >/dev/null 2>&1 &&
if ! sh "$scripts_path/is_macos.sh"; then sudo sysctl -w net.inet.ip.fw.enable=1 >/dev/null 2>&1; fi &&
sudo ifconfig "$bridge" destroy &&
sudo rm -f "$bridge_script_path"; then
echo "$bridge: Network bridge deleted"
else
echo "ERROR: $bridge Network bridge was not deleted"
fi
else
echo "No network bridge to delete"
fi
sh "$scripts_path/delete_dependencies.sh" "$tap"
else
if [ "$count" = "" ]; then
echo "Removing scripts is skipped"
else
echo "Removing scripts is skipped, qemu instances still running"
fi
fi