-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCocoaDialogFunctions.sh
More file actions
executable file
·263 lines (255 loc) · 7.66 KB
/
CocoaDialogFunctions.sh
File metadata and controls
executable file
·263 lines (255 loc) · 7.66 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# CocoaDialogFunctions.config
#
# This script should be sourced into any other scripts needing CocoaDialogFunctions
#
# Created by andrewws on 06/30/14.
# Updated by andrewws on 10/17/2018
## Variables
####################################################################################################
PathToRepo=""
CocoaDialog="$PathToRepo/cocoaDialog 3.0-beta7/cocoaDialog.app/Contents/MacOS/cocoaDialog"
CocoaDialogIcon="$PathToRepo/cocoaDialog 3.0-beta7/cocoaDialog.app/Contents/Resources/AppIcon.icns"
button=""
StandardInputbox_Output=""
SecureStandardInputBox_Output=""
DropDown_Output=""
Checkbox_Output=""
## CocoaDialog Functions
####################################################################################################
function StartProgressBar () {
# $1=Title $2=Text $3=IconPath $4=Percent(Yes No) $5=Float(Yes No)
# Percentage Example: echo "10 We are at 10%" > /tmp/hpipe
title=$1
text=$2
icon=$3
if [ "$4" == "Yes" ]; then
percent="--percent"
else
percent='--indeterminate'
fi
if [ "$5" == "Yes" ]; then
float='--float'
elif [ "$5" == "No" ]; then
float='--no-float'
elif [ "$5" != "No" ] && [ "$5" != "Yes" ]; then
float=''
fi
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
"$CocoaDialog" progressbar --title "$title" --text "$text" --icon-file "$icon" --icon-height 90 --icon-width 90 --width 512 --height 128 --debug "$percent" "$float" < /tmp/hpipe &
exec 5<> /tmp/hpipe
echo -n . >&5
}
function TerminateProgressBar () {
exec 5>&-
rm -f /tmp/hpipe
}
function PromptUser () {
# $1=Title $2=Text $3=IconPath $4=Informative_Text
# $5=Button1 $6=Button2
CocoaDialogIcon="/private/var/gne/gInstall/bin/cocoaDialog.app/Contents/Resources/cocoadialog.icns"
button=""
title=$1
text=$2
if [ "$3" == "" ]; then
icon="$CocoaDialogIcon"
else
icon=$3
fi
informative_text="$4"
if [ "$5" != "" ]; then
button1="$5"
else
button1=""
fi
if [ "$6" != "" ]; then
button2="$6"
else
button2=""
fi
user_dialog=`"$CocoaDialog" msgbox --title "$title" --text "$text" --icon-file "$icon" --informative-text "$informative_text" --float --button1 "$button1" --button2 "$button2" --debug --icon-size 128 --width 524 --string-output`
button=`echo "${user_dialog}" | awk 'NR>0{print $0}' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
}
function StandardInputbox () {
# $1=Title $2=informative_text $3=IconPath
StandardInputbox_Output=""
button=""
title=$1
informative_text=$2
icon=$3
user_dialog=`"$CocoaDialog" standard-inputbox --title "$title" --informative-text "$informative_text" --float --icon-file "$icon" --debug --string-output`
button=`echo "${user_dialog}" | awk 'NR>0{print $0}' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
StandardInputbox_Output=`echo "${user_dialog}" | awk 'NR>1{print $1}' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
}
function SecureStandardInputBox () {
# $1=Title $2=informative_text $3=IconPath
SecureStandardInputBox_Output=""
button=""
title=$1
informative_text=$2
icon=$3
user_dialog=`"$CocoaDialog" secure-standard-inputbox --title "$title" --informative-text "$informative_text" --string-output --float --icon-file "$icon" --debug`
button=`echo "${user_dialog}" | awk 'NR>0{print $0}' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
SecureStandardInputBox_Output=`echo "${user_dialog}" | awk 'NR>1{print $1}' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
}
function PromptDropDown () {
# $1=Title $2=Text $3=IconPath $4=Informative_Text
# $5=Button1 $6=Button2
button=""
DropDown_Output=""
title=$1
text=$2
if [ "$3" == "" ]; then
icon="$CocoaDialogIcon"
else
icon=$3
fi
if [ "$4" != "" ]; then
button1="$4"
else
button1=""
fi
if [ "$5" != "" ]; then
button2="$5"
else
button2=""
fi
if [ "$6" != "" ]; then
button3="$6"
else
button3=""
fi
item1=$7
item2=$8
item3=$9
item4=${10}
item5=${11}
item6=${12}
item7=${13}
item8=${14}
user_dialog=`"$CocoaDialog" dropdown --title "$title" --text "$text" --float --icon-file "$icon" --button1 "$button1" --button2 "$button2" --button3 "$button3" --items $item1 $item2 $item3 $item4 $item5 $item6 $item7 $item8--debug --string-output --icon-size 128 --width 512 --height 160`
button=`echo "${user_dialog}" | awk 'NR==1' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
DropDown_Output=`echo "${user_dialog}" | awk 'NR==2' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
}
function StartDownloadProgressBar () {
# $1=Title $2=Text $3=IconPath $4=Float(Yes No) $5=ManualTrigger $6=DownloadFileSize $7=DownloadFileName $8=DownloadFilePath
# Percentage Example: echo "10 We are at 10%" > /tmp/hpipe
title=$1
text=$2
if [ "$3" == "" ]; then
icon="$CocoaDialogIcon"
else
icon=$3
fi
if [ "$4" == "Yes" ]; then
float='--float'
elif [ "$4" == "No" ]; then
float='--no-float'
elif [ "$4" != "No" ] && [ "$4" != "Yes" ]; then
float=''
fi
ManualTrigger=$5
DownloadFileSize=$6
DownloadFileName=$7
if [ "$8" == "" ]; then
DownloadFilePath="/Library/Application Support/JAMF/Downloads"
else
DownloadFilePath="$8"
fi
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
"$CocoaDialog" progressbar --title "$title" --text "$text" --icon-file "$icon" --icon-size 128 --width 512 --height 160 --debug --stoppable "$float" < /tmp/hpipe > /private/var/tmp/.progressOutput &
exec 6<> /tmp/hpipe
echo -n . >&6
$jamf_binary policy -event "$ManualTrigger" &
while [[ `ps -ae | grep "$jamf_binary policy -event $ManualTrigger" | grep -v grep | awk '{print$4}'` = "$jamf_binary" ]] && [[ `cat /private/var/tmp/.progressOutput` != "stopped" ]]; do
downloadProgress=`du -k "$DownloadFilePath"/"$DownloadFileName" | awk '{print$1}'`
precent=`echo "$downloadProgress" "$DownloadFileSize" | awk '{print$1/$2*100}' | cut -d "." -f1`
progressBarOutput=`cat /private/var/tmp/.progressOutput`
if [ "$precent" = "100" ]; then
echo "$precent Please Wait Verifying Download.... $precent%" >&6
else
echo "$precent Download in Progress.... $precent%" >&6
fi
sleep .5
done
exec 6>&-
rm -f /tmp/hpipe
if [[ `cat /private/var/tmp/.progressOutput` == "stopped" ]]; then
killall $jamf_binary
killall $jamf_binary
rm /private/var/tmp/.progressOutput
exit 0
else
rm /private/var/tmp/.progressOutput
fi
}
function PromptCheckbox () {
# $1=Title $2=Text $3=IconPath $4=Informative_Text
# $5=Button1 $6=Button2
button=""
Checkbox_Output=""
title=$1
text=$2
if [ "$3" == "" ]; then
icon="$CocoaDialogIcon"
else
icon=$3
fi
if [ "$4" != "" ]; then
button1="$4"
else
button1=""
fi
if [ "$5" != "" ]; then
button2="$5"
else
button2=""
fi
if [ "$6" != "" ]; then
button3="$6"
else
button3=""
fi
item1=$7
item2=$8
item3=$9
item4=${10}
item5=${11}
item6=${12}
item7=${13}
item8=${14}
user_dialog=`"$CocoaDialog" checkbox --title "$title" --label "$text" --float --icon-file "$icon" --button1 "$button1" --button2 "$button2" --button3 "$button3" --items "$item1" $item2 $item3 $item4 $item5 $item6 $item7 $item8--debug --string-output --icon-size 128 --width 512 --height 160`
button=`echo "${user_dialog}" | awk 'NR==1' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
Checkbox_Output=`echo "${user_dialog}" | awk 'NR==2' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
}
function PromptTextbox () {
# $1=Title $2=TextFile Path $3=IconPath $4=Text
# $5=Button1 $6=Button2 $7=Button3
button=""
title=$1
TextFile=$2
if [ "$3" == "" ]; then
icon="$CocoaDialogIcon"
else
icon=$3
fi
text="$4"
if [ "$5" != "" ]; then
button1="$5"
else
button1=""
fi
if [ "$6" != "" ]; then
button2="$6"
else
button2=""
fi
if [ "$7" != "" ]; then
button3="$7"
else
button3=""
fi
user_dialog=`"$CocoaDialog" textbox --title "$title" --text-from-file "$TextFile" --label "$text" --float --icon-file "$icon" --button1 "$button1" --button2 "$button2" --button3 "$button3" --debug --string-output`
button=`echo "${user_dialog}" | awk 'NR==1' | sed -e 's,.*(\([^<]*\)).*,\1,g'`;
}