237 lines
8.2 KiB
Bash
237 lines
8.2 KiB
Bash
#!/bin/bash
|
|
# Erstellt von Peter Hasselbach am 17.5.2018
|
|
#Quelle: https://www.jamf.com/jamf-nation/discussions/17887/script-question-creating-network-locations-and-settings-depending-on-interface
|
|
|
|
####################################################################################################
|
|
|
|
#hardcoded variables
|
|
usb="USB Ethernet"
|
|
display="Display Ethernet"
|
|
tbolt="Thunderbolt Ethernet"
|
|
dell="Dell Universal Dock D6000"
|
|
wired="Ethernet"
|
|
wireless="Wi-Fi"
|
|
|
|
####################################################################################################
|
|
|
|
#detect network interfaces
|
|
Thunderbolt Ethernet Slot 1, Port 1=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt Ethernet Slot 1, Port 1"`
|
|
Thunderbolt_1=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt 1"`
|
|
Thunderbolt_2=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt 2"`
|
|
Thunderbolt_3=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt 3"`
|
|
Thunderbolt_4=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt 4"`
|
|
Thunderbolt_Bridge=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt Bridge"`
|
|
## TODO Wird nicht benutzt ist das gewollt?/
|
|
wifiAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Wi-Fi"`
|
|
firewireAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: FireWire"`
|
|
|
|
|
|
####################################################################################################
|
|
|
|
#######
|
|
#Create new Location LAN
|
|
#######
|
|
|
|
/usr/sbin/networksetup -createlocation "LAN" populate
|
|
|
|
#Switch to Location LAN
|
|
|
|
/usr/sbin/networksetup -switchtolocation "LAN"
|
|
|
|
|
|
##############
|
|
## Thunderbolt Ethernet Slot 1, Port 1 ##
|
|
##############
|
|
|
|
if [ "$Thunderbolt Ethernet Slot 1, Port 1" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$Thunderbolt Ethernet Slot 1, Port 1"
|
|
/usr/sbin/networksetup -setv6off "$Thunderbolt Ethernet Slot 1, Port 1"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$Thunderbolt Ethernet Slot 1, Port 1" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$Thunderbolt Ethernet Slot 1, Port 1" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$Thunderbolt Ethernet Slot 1, Port 1" on
|
|
fi
|
|
|
|
|
|
##################
|
|
## Thunderbolt 1 ##
|
|
##################
|
|
|
|
if [ "$Thunderbolt_1" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$Thunderbolt_1"
|
|
/usr/sbin/networksetup -setv6off "$Thunderbolt_1"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$Thunderbolt_1" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$Thunderbolt_1" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$Thunderbolt_1" on
|
|
fi
|
|
|
|
|
|
##################
|
|
## Thunderbolt 2 ##
|
|
##################
|
|
|
|
if [ "$Thunderbolt_2" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$Thunderbolt_2"
|
|
/usr/sbin/networksetup -setv6off "$Thunderbolt_2"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$Thunderbolt_2" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$Thunderbolt_2" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$Thunderbolt_2" on
|
|
fi
|
|
|
|
##################
|
|
## Thunderbolt 3 ##
|
|
##################
|
|
|
|
if [ "$Thunderbolt_3" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$Thunderbolt_3"
|
|
/usr/sbin/networksetup -setv6off "$Thunderbolt_3"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$Thunderbolt_3" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$Thunderbolt_3" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$Thunderbolt_3" on
|
|
fi
|
|
|
|
##################
|
|
## Thunderbolt 4 ##
|
|
##################
|
|
|
|
if [ "$Thunderbolt_4" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$Thunderbolt_4"
|
|
/usr/sbin/networksetup -setv6off "$Thunderbolt_4"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$Thunderbolt_4" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$Thunderbolt_4" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$Thunderbolt_4" on
|
|
fi
|
|
|
|
|
|
##################
|
|
## Thunderbolt Bridge ##
|
|
##################
|
|
|
|
if [ "$Thunderbolt_Bridge" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$Thunderbolt_Bridge"
|
|
/usr/sbin/networksetup -setv6off "$Thunderbolt_Bridge"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$Thunderbolt_Bridge" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$Thunderbolt_Bridge" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$Thunderbolt_Bridge" on
|
|
fi
|
|
|
|
|
|
#####################
|
|
## Display Adapter ##
|
|
#####################
|
|
|
|
if [ "$display" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$display"
|
|
/usr/sbin/networksetup -setv6off "$display"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$display" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$display" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$display" on
|
|
fi
|
|
|
|
|
|
#########################
|
|
## Thunderbolt Adapter ##
|
|
#########################
|
|
|
|
if [ "$tbolt" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$tbolt"
|
|
/usr/sbin/networksetup -setv6off "$tbolt"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$tbolt" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$tbolt" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$tbolt" on
|
|
fi
|
|
|
|
|
|
|
|
################################
|
|
## Disable non-wired adapters ##
|
|
################################
|
|
|
|
if [ "$tbolt" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$tbolt" off
|
|
fi
|
|
|
|
## TODO Unsed Variable Wird diese von aussen gesetzt?
|
|
if [ "$btDUNAdapter" != "" ]; then
|
|
## TODO Unsed Variable Wird diese von aussen gesetzt?
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$btDUN" off
|
|
fi
|
|
|
|
## TODO Unsed Variable Wird diese von aussen gesetzt?
|
|
if [ "$btPANAdapter" != "" ]; then
|
|
## TODO Unsed Variable Wird diese von aussen gesetzt?
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$btPAN" off
|
|
fi
|
|
|
|
if [ "$firewireAdapter" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$firewireAdapter" off
|
|
fi
|
|
|
|
|
|
####################################################################################################
|
|
|
|
#######
|
|
#Create new Location WIFI
|
|
#######
|
|
|
|
/usr/sbin/networksetup -createlocation "WIFI" populate
|
|
|
|
#Switch to Location WIFI
|
|
|
|
/usr/sbin/networksetup -switchtolocation "WIFI"
|
|
|
|
##################
|
|
## wifiAdapter ##
|
|
##################
|
|
|
|
if [ "$wifiAdapter" != "" ]; then
|
|
/usr/sbin/networksetup -setdhcp "$wifiAdapter"
|
|
/usr/sbin/networksetup -setv6off "$wifiAdapter"
|
|
/usr/sbin/networksetup -setproxybypassdomains "$wifiAdapter" *.local 169.254/16
|
|
/usr/sbin/networksetup -setsearchdomains "$wifiAdapter" diba.corp.int corp.int diba.int entwicklung.corp.int test.corp.int at.corp.int
|
|
/usr/sbin/networksetup -setpassiveftp "$wifiAdapter" on
|
|
fi
|
|
|
|
################################
|
|
## Disable Wired adapters ##
|
|
################################
|
|
|
|
|
|
if [ "$Thunderbolt_Bridge" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$Thunderbolt_Bridge" off
|
|
fi
|
|
|
|
if [ "$Thunderbolt_1" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$Thunderbolt_1" off
|
|
fi
|
|
|
|
if [ "$Thunderbolt_2" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$Thunderbolt_2" off
|
|
fi
|
|
|
|
if [ "$Thunderbolt_3" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$Thunderbolt_3" off
|
|
fi
|
|
|
|
if [ "$Thunderbolt_4" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$Thunderbolt_4" off
|
|
fi
|
|
|
|
if [ "$Thunderbolt Ethernet Slot 1, Port 1" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$Thunderbolt Ethernet Slot 1, Port 1" off
|
|
fi
|
|
if [ "$firewireAdapter" != "" ]; then
|
|
/usr/sbin/networksetup -setnetworkserviceenabled "$firewireAdapter" off
|
|
fi
|
|
# Adapter settings as above, with desired adjustments
|
|
|
|
|
|
####################################################################################################
|
|
####################################################################################################
|
|
|
|
#Switch back to Location LAN
|
|
|
|
/usr/sbin/networksetup -switchtolocation "LAN"
|
|
|
|
exit 0
|
|
|