-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjamfAssistant.sh
executable file
·106 lines (86 loc) · 4.37 KB
/
jamfAssistant.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
####################################################################################################
# This is designed to be used from Jamf Self Service on computers that have Standard accounts.
# v1.0 created by mjerome 07252024
####################################################################################################
function dialogInstall() {
# Get the URL of the latest PKG From the Dialog GitHub repo
dialogURL=$(curl -L --silent --fail "https://api.github.com/repos/swiftDialog/swiftDialog/releases/latest" | awk -F '"' "/browser_download_url/ && /pkg\"/ { print \$4; exit }")
# Expected Team ID of the downloaded PKG
expectedDialogTeamID="PWA5E9TQ59"
echo "Installing swiftDialog..."
# Create a temporary working directory
workDirectory=$( basename "$0" )
tempDirectory=$( mktemp -d "/private/tmp/$workDirectory.XXXXXX" )
# Download the installer package
curl --location --silent "$dialogURL" -o "$tempDirectory/Dialog.pkg"
# Verify the download
teamID=$(spctl -a -vv -t install "$tempDirectory/Dialog.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()')
# Install the package if Team ID validates
if [[ "$expectedDialogTeamID" == "$teamID" ]]; then
/usr/sbin/installer -pkg "$tempDirectory/Dialog.pkg" -target /
sleep 2
dialogVersion=$( /usr/local/bin/dialog --version )
preFlight "swiftDialog version ${dialogVersion} installed; proceeding..."
else
# Display a so-called "simple" dialog if Team ID fails to validate
osascript -e 'display dialog "Please advise your Support Representative of the following error:\r\r• Dialog Team ID verification failed\r\r" with title "'"${scriptFunctionalName}"': Error" buttons {"Close"} with icon caution'
exitCode="1"
quitScript
fi
# Remove the temporary working directory when done
rm -Rf "$tempDirectory"
}
function dialogCheck() {
# Check for Dialog and install if not found
if [ ! -e "/Library/Application Support/Dialog/Dialog.app" ]; then
echo "swiftDialog not found. Installing..."
dialogInstall
else
dialogVersion=$(/usr/local/bin/dialog --version)
if [[ "${dialogVersion}" < "${swiftDialogMinimumRequiredVersion}" ]]; then
echo "swiftDialog version ${dialogVersion} found but swiftDialog ${swiftDialogMinimumRequiredVersion} or newer is required; updating..."
dialogInstall
else
echo "swiftDialog version ${dialogVersion} found; proceeding..."
fi
fi
}
dialogCheck
iconPath="${4:-"/Library/Fanatics/Fanatics_icon.png"}"
appTitle="${5:-"Jamf Assistant"}"
logFile="${6:-"/var/log/commandResults.log"}"
while [[ $selection != 4 ]]; do
selection=$(dialog --icon ${iconPath} --title ${appTitle} --message "Use the selections below to run the most common Jamf tasks." --selecttitle "Select a function",radio --selectvalues "Collect Inventory, Policy by ID, Policy by Custom Trigger, General Policy Check, Exit" | grep "SelectedIndex" | awk -F ": " '{print $NF}')
echo $selection
case $selection in
0)
command="jamf recon"
# Execute the command and capture its output
${command} > "$logFile" | /usr/local/bin/dialog --big --title "Gathering Jamf Inventory Results" --message " " --displaylog "$logFile" --icon $iconPath
;;
1)
id=$(dialog --icon ${iconPath} --title ${appTitle} --message "Enter the desired policy number" --textfield "Policy ID" | grep "Policy ID" | awk -F ": " '{print $NF}' )
command="/usr/local/bin/jamf policy -id ${id}"
# Execute the command and capture its output
${command} > "$logFile" | /usr/local/bin/dialog --big --title "Policy ${id} Log Results" --message " " --displaylog "$logFile" --icon $iconPath
;;
2)
customTrigger=$(dialog --icon ${iconPath} --title ${appTitle} --message "Enter the desired custom trigger" --textfield "Custom Trigger"| grep "Custom Trigger" | awk -F ": " '{print $NF}')
command="/usr/local/bin/jamf policy -trigger ${customTrigger}"
# Execute the command and capture its output
${command} > "$logFile" | /usr/local/bin/dialog --big --title "Policy Trigger ${customTrigger} Log Results" --message " " --displaylog "$logFile" --icon $iconPath
;;
3)
command="/usr/local/bin/jamf policy "
# Execute the command and capture its output
${command} > "$logFile" | /usr/local/bin/dialog --big --title "Policy Log Results" --message " " --displaylog "$logFile" --icon $iconPath
;;
4)
exit 0
;;
*)
dialog --icon ${iconPath} --title ${appTitle} --message "ERROR"
;;
esac
done