add shortcut for args --addbridge to -a and --rmbridge to -r
This commit is contained in:
parent
81519e7d8d
commit
ad2995ed87
1 changed files with 42 additions and 32 deletions
|
@ -12,29 +12,27 @@ This script will use either doas or sudo to access the root user and do some tem
|
|||
Please do not name your bridge the saùe as an already existed interface.
|
||||
|
||||
PARAMETTER available
|
||||
-h, --help Print this help message and quit
|
||||
-v, --version Print the version of this program and quit
|
||||
-h, --help Print this help message and quit
|
||||
-v, --version Print the version of this program and quit
|
||||
|
||||
|
||||
OPTION available
|
||||
--addbridge=<bridge-id> Set the name for the new bridge interface, usually it is br0, br1, etc
|
||||
--rmbridge=<bridge-id> Remove a bridge interface. Be carefull, it do no verification wheither bridge-id is a real interface or a bridge interface.
|
||||
--addr=<address> Set an external address on the bridge. The external is the one accessible from the host.
|
||||
-a <br-id>, --addbridge=<br-id> Set the name for the new bridge interface, usually it is br0, br1, etc
|
||||
-r <br-id>, --rmbridge=<br-id> Remove a bridge interface. Be carefull, it do no verification wheither br-id is a real interface or a bridge interface.
|
||||
--addr=<address> Set an external address on the bridge. The external is the one accessible from the host.
|
||||
"
|
||||
Version="1.1.1"
|
||||
Version="1.2.0"
|
||||
unset action
|
||||
|
||||
|
||||
add_bridge() {
|
||||
echo "add bridge interface ${bridge}"
|
||||
${rooter} ip link add ${bridge} type bridge
|
||||
|
||||
#echo "no interface to link with bridge ${bridge}"
|
||||
#$rooter ip link set dev wlan0 master br0
|
||||
|
||||
echo "authorise qemu to use as interface ${bridge} as bridge"
|
||||
# authorise qemu to use as interface ${bridge} as bridge
|
||||
if cat /etc/qemu/bridge.conf | grep -q "${bridge}"
|
||||
then
|
||||
echo "pass, bridge already authorised"
|
||||
echo "bridge already authorised by qemu"
|
||||
else
|
||||
echo "allow ${bridge}" | doas tee -a /etc/qemu/bridge.conf
|
||||
echo "entry added to /etc/qemu/bridge.conf"
|
||||
|
@ -74,55 +72,67 @@ done
|
|||
# check if sudo is installed
|
||||
if which doas &> /dev/null
|
||||
then
|
||||
echo "use doas"
|
||||
rooter=$(which doas)
|
||||
elif which sudo &> /dev/null
|
||||
then
|
||||
echo "use sudo"
|
||||
rooter=$(which sudo)
|
||||
else
|
||||
echo "no command to give access to root is given. Abandon" >&2
|
||||
exit
|
||||
fi
|
||||
|
||||
# detect options 2 parametters (-a, -r)
|
||||
for (( arg=1; arg< $#; arg++)); do
|
||||
value="$((arg+1))"
|
||||
case "${!arg}" in
|
||||
"-a")
|
||||
bridge="${!value}"
|
||||
action="add"
|
||||
;;
|
||||
"-r")
|
||||
bridge="${!value}"
|
||||
action="rm"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
# detect the options
|
||||
for i in $@; do
|
||||
case "${i%=*}" in
|
||||
"--addbridge")
|
||||
bridge="${i#*=}"
|
||||
echo "${bridge}"
|
||||
add_bridge
|
||||
action="add"
|
||||
;;
|
||||
"--rmbridge")
|
||||
bridge="${i#*=}"
|
||||
echo "${bridge}"
|
||||
rm_bridge
|
||||
exit 0
|
||||
action="rm"
|
||||
;;
|
||||
"--addr")
|
||||
address="${i#*=}"
|
||||
echo "${address}"
|
||||
;;
|
||||
"--replace")
|
||||
echo "--replace not yet supported, program stopped." >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "parametter ${i%=*} not recognised" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${bridge}" == "" ]
|
||||
then
|
||||
echo "Error, --bridge have to be specified to make the bridge" >&2
|
||||
exit
|
||||
fi
|
||||
|
||||
case "${action}" in
|
||||
"add")
|
||||
add_bridge
|
||||
;;
|
||||
"rm")
|
||||
rm_bridge
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Error, bridge have to setup the bridge" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
if [ ! "${address}" == "" ]
|
||||
then
|
||||
echo "add ${address} to bridge ${bridge}"
|
||||
${rooter} ip a add dev ${bridge} ${address}
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in a new issue