add shortcut for args --addbridge to -a and --rmbridge to -r

This commit is contained in:
primardj 2024-02-05 00:59:35 +00:00
parent 81519e7d8d
commit ad2995ed87

View file

@ -17,24 +17,22 @@ PARAMETTER available
OPTION available OPTION available
--addbridge=<bridge-id> Set the name for the new bridge interface, usually it is br0, br1, etc -a <br-id>, --addbridge=<br-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. -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. --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() { add_bridge() {
echo "add bridge interface ${bridge}" echo "add bridge interface ${bridge}"
${rooter} ip link add ${bridge} type bridge ${rooter} ip link add ${bridge} type bridge
#echo "no interface to link with bridge ${bridge}" # authorise qemu to use as interface ${bridge} as bridge
#$rooter ip link set dev wlan0 master br0
echo "authorise qemu to use as interface ${bridge} as bridge"
if cat /etc/qemu/bridge.conf | grep -q "${bridge}" if cat /etc/qemu/bridge.conf | grep -q "${bridge}"
then then
echo "pass, bridge already authorised" echo "bridge already authorised by qemu"
else else
echo "allow ${bridge}" | doas tee -a /etc/qemu/bridge.conf echo "allow ${bridge}" | doas tee -a /etc/qemu/bridge.conf
echo "entry added to /etc/qemu/bridge.conf" echo "entry added to /etc/qemu/bridge.conf"
@ -74,55 +72,67 @@ done
# check if sudo is installed # check if sudo is installed
if which doas &> /dev/null if which doas &> /dev/null
then then
echo "use doas"
rooter=$(which doas) rooter=$(which doas)
elif which sudo &> /dev/null elif which sudo &> /dev/null
then then
echo "use sudo"
rooter=$(which sudo) rooter=$(which sudo)
else else
echo "no command to give access to root is given. Abandon" >&2 echo "no command to give access to root is given. Abandon" >&2
exit exit
fi 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 # detect the options
for i in $@; do for i in $@; do
case "${i%=*}" in case "${i%=*}" in
"--addbridge") "--addbridge")
bridge="${i#*=}" bridge="${i#*=}"
echo "${bridge}" action="add"
add_bridge
;; ;;
"--rmbridge") "--rmbridge")
bridge="${i#*=}" bridge="${i#*=}"
echo "${bridge}" action="rm"
rm_bridge
exit 0
;; ;;
"--addr") "--addr")
address="${i#*=}" address="${i#*=}"
echo "${address}"
;;
"--replace")
echo "--replace not yet supported, program stopped." >&2
exit 1
;;
*)
echo "parametter ${i%=*} not recognised" >&2
exit 1
;; ;;
esac esac
done done
if [ "${bridge}" == "" ]
then case "${action}" in
echo "Error, --bridge have to be specified to make the bridge" >&2 "add")
exit add_bridge
fi ;;
"rm")
rm_bridge
exit 0
;;
*)
echo "Error, bridge have to setup the bridge" >&2
exit 1
;;
esac
if [ ! "${address}" == "" ] if [ ! "${address}" == "" ]
then then
echo "add ${address} to bridge ${bridge}"
${rooter} ip a add dev ${bridge} ${address} ${rooter} ip a add dev ${bridge} ${address}
fi fi