-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqemu_ctl.sh
98 lines (87 loc) · 2.45 KB
/
qemu_ctl.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
96
97
98
#!/usr/bin/bash
# Copyright (c) [2022] Huawei Technologies Co.,Ltd.ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
####################################
# @Author : saarloos
# @email : [email protected]
# @Date : 2022-05-20 15:41:00
# @License : Mulan PSL v2
# @Version : 1.0
# @Desc :
#####################################
OET_PATH=$(
cd "$(dirname "$0")" || exit 1
pwd
)
export OET_PATH
con_op=""
br_name="testbr0"
rem_br=0
for i in $*; do
if [ $rem_br -eq 1 ]; then
br_name="$i"
rem_br=0
fi
if [[ $i == "--br_name" ]]; then
rem_br=1
fi
if [[ $i == "start" || $i == "stop" && -z con_op ]]; then
con_op=$i
fi
done
br_conf="/etc/qemu/bridge.conf"
br_conf1="/usr/local/etc/qemu/bridge.conf"
br_conf2=""
br_conf_bak="/etc/qemu/bridge.conf.bak"
br_conf1_bak="/usr/local/etc/qemu/bridge.conf.bak"
br_conf2_bak=""
if [[ -n $MUGEN_QEMU_ACL_DIR ]]; then
mkdir -p $MUGEN_QEMU_ACL_DIR
br_conf2="$MUGEN_QEMU_ACL_DIR/bridge.conf"
br_conf2_bak="$MUGEN_QEMU_ACL_DIR/bridge.conf.bak"
fi
if [[ $con_op == "start" ]]; then
if [[ ! -e $con_op ]]; then
mkdir -p /etc/qemu/
mkdir -p /usr/local/etc/qemu/
fi
if [ -e $br_conf ]; then
cp $br_conf $br_conf_bak
fi
if [ -e $br_conf1 ]; then
cp $br_conf1 $br_conf1_bak
fi
echo "allow ${br_name}" >> $br_conf
echo "allow ${br_name}" >> $br_conf1
if [[ -n ${br_conf2} ]]; then
if [ -e $br_conf2 ]; then
cp $br_conf2 $br_conf2_bak
fi
echo "allow ${br_name}" >> $br_conf2
fi
brctl addbr ${br_name}
ifconfig ${br_name} up
fi
python3 ${OET_PATH}/libs/locallibs/qemu_ctl.py "$@"
if [[ $con_op == "stop" ]]; then
if [ -e $br_conf_bak ]; then
cp $br_conf_bak $br_conf
rm -rf $br_conf_bak
fi
if [ -e $br_conf1_bak ]; then
cp $br_conf1_bak $br_conf1
rm -rf $br_conf1_bak
fi
if [[ -n ${br_conf2} ]]; then
if [ -e $br_conf2_bak ]; then
cp $br_conf2_bak $br_conf2
rm -rf $br_conf2_bak
fi
fi
fi