Created
July 27, 2017 07:18
-
-
Save Nosskirneh/c19d2da415fb6312672482eba112b156 to your computer and use it in GitHub Desktop.
Automatically update theos device settings and kill/open Dropbox on network change (macOS)
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \ | |
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>networkchange</string> | |
<key>LowPriorityIO</key> | |
<true/> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/andeh/Dropbox/bin/updateIP.sh</string> | |
</array> | |
<key>WatchPaths</key> | |
<array> | |
<string>/etc/resolv.conf</string> | |
<string>/var/run/resolv.conf</string> | |
<string>/private/var/run/resolv.conf</string> | |
</array> | |
<key>RunAtLoad</key> | |
<true/> | |
</dict> | |
</plist> |
This file contains hidden or 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
# Get IP | |
IP=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` | |
echo "IP is $IP" | |
# Get SSID - Only works on Mac | |
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'` | |
echo "SSID is $SSID" | |
case $IP in | |
"192.168.0."*) # Home | |
open -a "Dropbox" | |
DEVICE_IP="192.168.0.96" | |
DEVICE_PORT="22";; | |
"192.168.1."*) # CH | |
open -a "Dropbox" | |
DEVICE_IP="192.168.1.96" | |
DEVICE_PORT="22";; | |
"192.168.32."*) # 4G-router | |
osascript -e 'tell application "Dropbox" to quit' | |
DEVICE_IP="192.168.32.151" | |
DEVICE_PORT="22";; | |
"172.20.10."*) # Tethering | |
osascript -e 'tell application "Dropbox" to quit' | |
DEVICE_IP="172.20.10.1" | |
DEVICE_PORT="22";; | |
*) | |
case $SSID in | |
"Comentor") | |
open -a "Dropbox" | |
DEVICE_IP="10.0.1.5" | |
DEVICE_PORT="22";; | |
*) # USB, eduroam does not allow SSH | |
open -a "Dropbox" | |
DEVICE_IP="localhost" | |
DEVICE_PORT="2222";; | |
esac;; | |
esac | |
echo "Setting the device IP to $DEVICE_IP" | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
echo "export THEOS_DEVICE_IP=${DEVICE_IP}" > "$DIR/theos.sh" | |
echo "export THEOS_DEVICE_PORT=${DEVICE_PORT}" >> "$DIR/theos.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapt the script to your liking.
Simply run
afterwards. Remember to change the directory to the shell script in the plist.