2024-02-01 01:13:38 +01:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set global variables
|
|
|
|
|
|
|
|
Usage="
|
2024-02-03 01:47:28 +01:00
|
|
|
$(basename $0) [PARAMETTER] [OPTION]
|
2024-02-01 01:13:38 +01:00
|
|
|
|
2024-02-03 01:47:28 +01:00
|
|
|
set up a bridge interface. Use either doas or sudo to get the root access. Please make sure that you account have access to theses commands.
|
|
|
|
This script will use either doas or sudo to access the root user and do some temporary modifications. You will be able to see it with 'ip a' command
|
|
|
|
Please do not name your bridge the saùe as an already existed interface.
|
2024-02-01 01:13:38 +01:00
|
|
|
|
|
|
|
PARAMETTER available
|
|
|
|
-h, --help Print this help message and quit
|
|
|
|
-v, --version Print the version of this program and quit
|
|
|
|
|
|
|
|
|
|
|
|
OPTION available
|
2024-02-04 12:53:20 +01:00
|
|
|
--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.
|
2024-02-01 16:41:55 +01:00
|
|
|
--addr=<address> Set an external address on the bridge. The external is the one accessible from the host.
|
2024-02-01 01:13:38 +01:00
|
|
|
"
|
2024-02-04 12:53:20 +01:00
|
|
|
Version="1.1.1"
|
2024-02-01 01:22:37 +01:00
|
|
|
|
|
|
|
|
2024-02-01 04:34:41 +01:00
|
|
|
add_bridge() {
|
2024-02-01 02:14:01 +01:00
|
|
|
echo "add bridge interface ${bridge}"
|
|
|
|
${rooter} ip link add ${bridge} type bridge
|
|
|
|
|
2024-02-01 04:34:41 +01:00
|
|
|
#echo "no interface to link with bridge ${bridge}"
|
2024-02-01 02:14:01 +01:00
|
|
|
#$rooter ip link set dev wlan0 master br0
|
2024-02-01 03:45:49 +01:00
|
|
|
|
|
|
|
echo "authorise qemu to use as interface ${bridge} as bridge"
|
|
|
|
if cat /etc/qemu/bridge.conf | grep -q "${bridge}"
|
|
|
|
then
|
|
|
|
echo "pass, bridge already authorised"
|
|
|
|
else
|
|
|
|
echo "allow ${bridge}" | doas tee -a /etc/qemu/bridge.conf
|
|
|
|
echo "entry added to /etc/qemu/bridge.conf"
|
|
|
|
fi
|
2024-02-01 02:14:01 +01:00
|
|
|
|
2024-02-01 03:45:49 +01:00
|
|
|
echo "activate bridge ${bridge}"
|
|
|
|
${rooter} ip link set dev ${bridge} up
|
2024-02-01 02:14:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-02-01 04:34:41 +01:00
|
|
|
rm_bridge() {
|
|
|
|
echo "rm bridge interface ${bridge}"
|
|
|
|
${rooter} ip link del ${bridge}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-02-01 02:14:01 +01:00
|
|
|
|
2024-02-01 01:22:37 +01:00
|
|
|
# detect the parametters
|
|
|
|
for i in $@; do
|
|
|
|
case "$i" in
|
|
|
|
"-h" | "--help")
|
|
|
|
echo "$Usage"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
"-v" | "--version")
|
|
|
|
echo "$(basename $0) $Version"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2024-02-01 04:34:41 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2024-02-01 01:58:30 +01:00
|
|
|
# detect the options
|
|
|
|
for i in $@; do
|
|
|
|
case "${i%=*}" in
|
2024-02-04 12:53:20 +01:00
|
|
|
"--addbridge")
|
2024-02-01 04:34:41 +01:00
|
|
|
bridge="${i#*=}"
|
|
|
|
echo "${bridge}"
|
|
|
|
add_bridge
|
|
|
|
;;
|
2024-02-04 12:53:20 +01:00
|
|
|
"--rmbridge")
|
2024-02-01 01:58:30 +01:00
|
|
|
bridge="${i#*=}"
|
|
|
|
echo "${bridge}"
|
2024-02-01 04:34:41 +01:00
|
|
|
rm_bridge
|
2024-02-01 16:41:55 +01:00
|
|
|
exit 0
|
2024-02-01 01:58:30 +01:00
|
|
|
;;
|
|
|
|
"--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
|
2024-02-01 01:22:37 +01:00
|
|
|
|
2024-02-01 03:45:49 +01:00
|
|
|
if [ "${bridge}" == "" ]
|
2024-02-01 02:14:01 +01:00
|
|
|
then
|
2024-02-01 04:34:41 +01:00
|
|
|
echo "Error, --bridge have to be specified to make the bridge" >&2
|
2024-02-01 01:58:30 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2024-02-01 16:41:55 +01:00
|
|
|
if [ ! "${address}" == "" ]
|
|
|
|
then
|
|
|
|
${rooter} ip a add dev ${bridge} ${address}
|
|
|
|
fi
|
|
|
|
|
2024-02-01 01:58:30 +01:00
|
|
|
|
2024-02-01 01:22:37 +01:00
|
|
|
|
|
|
|
|
2024-02-01 02:14:01 +01:00
|
|
|
|