Skip to content

Instantly share code, notes, and snippets.

@reidstidolph
Created December 18, 2018 16:33
Show Gist options
  • Save reidstidolph/84910517a4a0d5baeba01558b143439d to your computer and use it in GitHub Desktop.
Save reidstidolph/84910517a4a0d5baeba01558b143439d to your computer and use it in GitHub Desktop.
128T network plugin scripts for moving a specified interface ($INTNAME) to a specified bridge ($BRNAME). Logging of these scripts is to systemd journal, and can be view with `journalctl -t kni-attach`.
#!/usr/bin/env bash
########################################################
# #
# This script attaches a network interface a network #
# bridge. Output is logged to system journal, and can #
# be viewed with the following: #
# #
# $ journalctl -t kni-attach #
# #
########################################################
# vars
INTNAME="lan-gw"
BRNAME="lan-br"
RETRYCOUNT="0"
MAXTRIES="5"
# functions
function add2bridge(){
systemd-cat -t kni-attach brctl addif $BRNAME $INTNAME
if [ $? -ne 0 ] ; then
RETRYCOUNT=$[$RETRYCOUNT+1]
echo "failed to add interface $INTNAME to bridge $BRNAME" | systemd-cat -t kni-attach
if [ "$RETRYCOUNT" -lt "$MAXTRIES" ] ; then
sleep 10
echo "retry $RETRYCOUNT" | systemd-cat -t kni-attach
add2bridge
else
echo "retry $RETRYCOUNT, giving up" | systemd-cat -t kni-attach
fi
else
echo "sucessfully added interface $INTNAME to bridge $BRNAME" | systemd-cat -t kni-attach
fi
}
#start
echo "$INTNAME gateway ADDED. Moving to $BRNAME" | systemd-cat -t kni-attach
add2bridge
#!/usr/bin/env bash
INTNAME="lan-gw"
echo "$INTNAME gateway REMOVED" | systemd-cat -t kni-attach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment