-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUpdate Proxy Bypass Domain.sh
65 lines (42 loc) · 1.78 KB
/
Update Proxy Bypass Domain.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# shellcheck disable=SC2086
###
#
# Name: Update Proxy Bypass Domain.sh
# Description: For each network interface with a proxy bypass domain entry
# of "*.local", changes to the target domain entry.
########## variable-ing ##########
# Jamf Pro script parameter "Proxy Bypass Domain".
# Should be in the format "*.domain".
targetDomain="$4"
networkInterfaces=$(/usr/sbin/networksetup -listallnetworkservices | "/usr/bin/sed" 1d)
########## function-ing ##########
# Exits if any required Jamf Pro arguments are undefined.
function check_jamf_pro_arguments {
jamfArguments=(
"$targetDomain"
)
for argument in "${jamfArguments[@]}"; do
if [[ "$argument" = "" ]]; then
echo "❌ ERROR: Undefined Jamf Pro argument, unable to proceed."
exit 74
fi
done
}
########## main process ##########
# Exit if any required Jamf Pro arguments are undefined.
check_jamf_pro_arguments
# Replace all instances of "*.local" in each network interface with "$targetDomain".
while IFS= read -r interface; do
bypassDomainsCurrent=$(/usr/sbin/networksetup -getproxybypassdomains "$interface")
if [[ "$bypassDomainsCurrent" = *"$targetDomain"* ]]; then
echo "$interface already inclues $targetDomain as proxy bypass domain, no action required."
elif [[ "$bypassDomainsCurrent" = *"There aren't any bypass domains set on"* ]]; then
echo "No proxy bypass domains defined for $interface, no action required."
else
bypassDomainsUpdate=$(echo "$bypassDomainsCurrent" | /usr/bin/sed "s/*.local/$targetDomain/" | /usr/bin/tr "\n" " ")
/usr/sbin/networksetup -setproxybypassdomains "$interface" $bypassDomainsUpdate
echo "Updated proxy bypass domains for $interface: $bypassDomainsUpdate"
fi
done <<< "$networkInterfaces"
exit 0