forked from milos85vasic/Server-Factory-Qemu-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_and_get_bridge.sh
executable file
·42 lines (32 loc) · 908 Bytes
/
create_and_get_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
#!/bin/sh
tap=$1
shared_Scripts_path="/tmp"
bridge_script_path="$shared_Scripts_path/qemu_bridge.sh"
scripts_path=$(sh "$shared_Scripts_path/qemu_scripts_path.sh")
if test -e "$bridge_script_path"; then
bridge=$(sh "$bridge_script_path")
echo "$bridge"
exit 0
else
END=100
for ITER in $(seq 0 $END);
do
bridge="bridge$ITER"
if ! ifconfig "$bridge" >/dev/null 2>&1; then
if sh "$scripts_path/create_bridge.sh" "$bridge" "$tap" >/dev/null 2>&1 && \
echo """
#!/bin/sh
echo $bridge
""" | tee "$bridge_script_path" >/dev/null 2>&1 && \
chmod 750 "$bridge_script_path"; then
echo "$bridge"
exit 0
else
echo "ERROR: Could not create bridge [2]"
sh "$scripts_path/fail_and_cleanup.sh" "$tap"
fi
fi
done
fi
echo "ERROR: Could not obtain bridge candidate"
sh "$scripts_path/fail_and_cleanup.sh" "$tap"