Last active
July 2, 2017 17:56
-
-
Save lindhe/3079b01c78cad42564c6db1fced85383 to your computer and use it in GitHub Desktop.
Checks for authorized Wi-Fi SSID or connected Ethernet before performing backup.
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/bash | |
# Checks for authorized Wi-Fi SSID or connected Ethernet before performing | |
# backup. | |
RUN=false; | |
AUTHFILE=~/.config/authorized_netwoks.txt; | |
WIFI=$(iwgetid --raw); | |
ETH_IF=eth0; | |
ETH=$(ip link show $ETH_IF | perl -n -e'/state (\w+)/ && print $1'); | |
if [ "$ETH" = "UP" ]; then | |
echo "Performing backup over Ethernet"; | |
RUN=true; | |
elif [ -f $AUTHFILE ]; then | |
if [ ! -z "^$WIFI$" ]; then | |
if [ ! -z $(grep "$WIFI" "$AUTHFILE") ]; then | |
echo "Performing backup over Wi-fi: $WIFI"; | |
RUN=true; | |
else | |
echo "Prohibited backup due to unauthorized Wi-fi: $WIFI"; | |
fi | |
else | |
echo "Not connected to a network." | |
exit 1; | |
fi | |
else | |
echo "No AUTHFILE found!"; | |
exit 1; | |
fi | |
if $RUN; then | |
echo "Starting backup..." | |
# Do stuff here | |
fi | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment