Last active
August 29, 2015 13:59
-
-
Save magcks/10677038 to your computer and use it in GitHub Desktop.
A script that handles backups of your local bridge settings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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