/
pause-backup-on-specific-wifi
48 lines (39 loc) · 1.78 KB
/
pause-backup-on-specific-wifi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Pashua, the utility Alfred Cron uses to add/edit jobs, doesn't like tabs in
# the textbox, so there are no tabs here.
# Example use-case for Alfred Cron: "Pause Backblaze backups when connected to specific network."
# Rationale: at home, my ISP seems to punish me when I'm backing up to Backblaze, and I have my
# setup Backblaze to backup continuously (ever since the Great Harddrive Crash of 2010).
# So, when I'm connected to my home network, I want to pause the backups so that I can still use
# the Internet.
# My list of home networks. This can be expanded to anything. And, yes, these
# are my home networks. Don't judge. I'm sure yours are just as bad.
blacklist=()
blacklist+=("Shark Week")
blacklist+=("Shark Week 5")
blacklist+=("Shark Week Mobile")
# Step 1: check if Backblaze is trying to back up.
if [[ ! $(ps aux | grep bztransmit | grep -v grep) ]]; then
# Backblaze isn't trying to back up, so exit.
exit 0
fi
# Step 2: check to make sure that the airport card is actually on.
# Get the Wifi Hardware Name
wifi=$(networksetup -listallhardwareports | grep -A 2 -E "AirPort|Wi-Fi" | grep -m 1 -o -e en[0-9]);
if [[ $(networksetup -getairportpower $wifi | grep -c On) = "0" ]]; then
# It's not on, so exit.
exit 0
fi
# Step 3: get the name of the network we're connected to.
# Get the current SSID (network name) that I'm connected to.
network=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep SSID | grep -v BSSID | sed -e 's|^ *||' -e 's|^SSID: ||' -e 's| *$||'`
# Go through all the network names in the blacklist and see if we're on one.
for ssid in "${blacklist[@]}";
do
if [ "$ssid" == "$network" ]; then
# Yup, we're on a blacklisted network, so pause Backblaze.
/Library/Backblaze/bztransmit -pausebackup
exit 0
fi
done
exit 0