Skip to content

Instantly share code, notes, and snippets.

@lindhe
Last active July 2, 2017 17:56
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 lindhe/3079b01c78cad42564c6db1fced85383 to your computer and use it in GitHub Desktop.
Save lindhe/3079b01c78cad42564c6db1fced85383 to your computer and use it in GitHub Desktop.
Checks for authorized Wi-Fi SSID or connected Ethernet before performing backup.
#!/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