Skip to content

Instantly share code, notes, and snippets.

@magcks
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magcks/10677038 to your computer and use it in GitHub Desktop.
Save magcks/10677038 to your computer and use it in GitHub Desktop.
A script that handles backups of your local bridge settings.
#!/bin/sh
FILE="$2"
if ( [ "$1" = "backup" ] && [ "$FILE" != "" ] ); then
# backup
brctl show | awk 'NR > 1 && $4 != "" { print $1 " " $4; last=$1; } NR > 1 && $2 == "" { print last " " $1; }' > "$FILE"
echo "Done"
elif ( [ "$1" = "restore" ] && [ "$FILE" != "" ] ); then
# restore
if [ ! -f "$FILE" ]; then
echo "No such file."
exit 1
fi
echo "Executing:"
cat "$FILE" | awk '{ print "echo brctl addif " $1 " " $2 | "sh" }'
do_exec=""
while ( [ "$do_exec" != "y" ] && [ "$do_exec" != "n" ] ); do
echo "[y]es [n]o?"
read do_exec
if ( [ "$do_exec" != "y" ] && [ "$do_exec" != "n" ] ); then
echo "Invalid input"
fi
done
if [ "$do_exec" = "n" ]; then
echo "I will do noting"
exit 0
fi
cat "$FILE" | awk '{ print "brctl addif " $1 " " $2 | "sh" }'
echo "Done"
else
# error
echo "Usage: $0 [backup|restore] [file]"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment