-
Notifications
You must be signed in to change notification settings - Fork 2
/
GYoSTemplate.sh
335 lines (280 loc) · 7.71 KB
/
GYoSTemplate.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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pashLoc="/Applications/Utilities/"
pashuaApp="Pashua.app"
pashBinLoc="/Applications/Utilities/Pashua.app/Contents/MacOS/Pashua"
SENDGRID_API_KEY="$8"
itemName="$4"
itemURL="$5"
itemApproval="$6"
itemCost="$7"
userName="$3"
fullTitle="Welcome to the $itemName Store."
if [[ $itemApproval == "1" ]]
then
displayMessage="This item requires approval; it will be ordered when approved.[return][return]$itemName - Cost \$$itemCost[return][return]Please complete this form to finalize the order.[return][return]If in a local office, we will contact you when the item is ready for pickup from the Help Desk. If remote, we will order the item for delivery to be shipped to your location."
else
displayMessage="$itemName - Cost \$$itemCost[return][return]Please complete this form to finalize the order.[return][return]If in a local office, we will contact you when the item is ready for pickup from the Help Desk. If remote, we will order the item for delivery to be shipped to your location."
fi
if [[ ! -a "$pashLoc$pashuaApp" ]]
then
echo "Pashua Not Found."
sudo jamf policy -event installPashua
else
echo "Pashua Found."
fi
############
#Functions from the pashua.sh script
locate_pashua() {
local bundlepath="Pashua.app/Contents/MacOS/Pashua"
local mypath=`dirname "$0"`
pashuapath=""
if [ ! "$1" = "" ]
then
searchpaths[0]="$1/$bundlepath"
fi
searchpaths[1]="$mypath/Pashua"
searchpaths[2]="$mypath/$bundlepath"
searchpaths[3]="./$bundlepath"
searchpaths[4]="/Applications/$bundlepath"
searchpaths[5]="$HOME/Applications/$bundlepath"
searchpaths[6]="/Applications/Utilities/Pashua"
for searchpath in "${searchpaths[@]}"
do
if [ -f "$searchpath" -a -x "$searchpath" ]
then
pashuapath=$searchpath
return 0
fi
done
return 1
}
pashua_run() {
# Write config file
local pashua_configfile=`/usr/bin/mktemp /tmp/pashua_XXXXXXXXX`
echo "$1" > "$pashua_configfile"
locate_pashua "$2"
if [ "" = "$pashuapath" ]
then
>&2 echo "Error: Pashua could not be found"
exit 1
fi
# Get result
local result=$("$pashuapath" "$pashua_configfile")
# Remove config file
rm "$pashua_configfile"
oldIFS="$IFS"
IFS=$'\n'
# Parse result
for line in $result
do
local name=$(echo $line | sed 's/^\([^=]*\)=.*$/\1/')
local value=$(echo $line | sed 's/^[^=]*=\(.*\)$/\1/')
eval $name='$value'
done
IFS="$oldIFS"
}
function sendEmail(){
emailBody=$(cat /tmp/itemOrder.conf)
emailContent=$(cat << EOF
{
"personalizations": [
{
"to": [
{
"email": "[email protected]"
}
],
"subject": "Item needs order"
}
],
"from": {
"email": "[email protected]"
},
"content": [
{
"type": "text/plain",
"value": '"$emailBody"'
}
]
}
EOF
)
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header 'Content-Type: application/json' \
-d "$emailContent"
}
# Define what the dialog should be like
# Take a look at Pashua's Readme file for more info on the syntax
conf="
# Set window title
*.title = $fullTitle
# Introductory text
txt.type = text
txt.default = $displayMessage
txt.height = 276
txt.width = 325
txt.x = 340
txt.y = 44
txt.tooltip =
# Add a text field
fullName.type = textfield
fullName.label = Full Name:
fullName.default =
fullName.width = 310
fullName.x = 0
fullName.y = 275
fullName.mandatory = 1
fullName.tooltip = Please Enter Your Full Name.
# Add a text field
userID.type = textfield
userID.label = User ID:
userID.default = $userName
userID.width = 310
userID.x = 0
userID.y = 230
userID.mandatory = 1
userID.tooltip = Please Enter Your Associate ID.
# Add a text field
email.type = textfield
email.label = Email Address:
email.default =
email.width = 310
email.x = 0
email.y = 185
email.mandatory = 1
email.tooltip = Please Enter Your Email Address.
# Add a popup menu
workLoc.type = popup
workLoc.label = Delivery Location:
workLoc.width = 310
workLoc.option = Headquarters
workLoc.option = Remote (Address Required)
workLoc.default = Headquarters
workLoc.x = 0
workLoc.y = 135
workLoc.tooltip = Please Select Your Location.
# Add a text field menu
workAddress.type = textfield
workAddress.label = If Remote, Please Enter Shipping Address:
workAddress.width = 310
workAddress.default =
workAddress.x = 0
workAddress.y = 90
workAddress.tooltip = Shipping address only needed if a remote employee.
# Add a text field menu
city.type = textfield
city.label = City:
city.width = 150
city.default =
city.x = 0
city.y = 45
city.tooltip = Please Enter Your City.
# Add a text field menu
state.type = textfield
state.label = State:
state.width = 75
state.default =
state.x = 151
state.y = 45
state.tooltip = Please Enter Your State.
# Add a text field menu
zipCode.type = textfield
zipCode.label = Zip:
zipCode.width = 50
zipCode.default =
zipCode.x = 227
zipCode.y = 45
zipCode.tooltip = Please Enter Your Zip.
# Add a cancel button with default label
cancel.type = cancelbutton
cancel.tooltip = Cancel
db.type = defaultbutton
db.tooltip = This is an element of type “defaultbutton” (which is automatically added to each window, if not included in the configuration)
"
if [ -d '/Volumes/Pashua/Pashua.app' ]
then
# Looks like the Pashua disk image is mounted. Run from there.
customLocation='/Volumes/Pashua'
else
# Search for Pashua in the standard locations
customLocation="$pashLoc"
fi
# Get the icon from the application bundle
locate_pashua "$customLocation"
bundlecontents=$(dirname $(dirname "$pashuapath"))
if [ -e "/Applications/Utilities/Pashua.app/Contents/Resources/pingIdentity.png" ]
then
conf="$conf
img.type = image
img.x = 435
img.y = 248
img.maxwidth = 128
img.tooltip = This is an element of type “image”
img.path = /Applications/Utilities/Pashua.app/Contents/Resources/pingIdentity.png"
fi
#This function will write the conf file to be used for the email template
#The delimiter to get information out of this file should be " - "
#For example `awk -F' - ' '{print $2}'`
function createConf() {
cat >/tmp/itemOrder.conf <<EOL
Full Name - $fullName\n User ID - $userID\n Email Address - $email\n Work Location - $workLoc\n Work Address - $workAddress\n City - $city\n State - $state\n Zip = $zipCode\n Item Selected - $itemName\n Item Cost - $itemCost\n Item URL - $itemURL\n Approval Needed - $itemApproval\n
EOL
}
#Run Pashua with the config.
function main()
{
fullName=""
userID=""
email=""
workLoc=""
workAddress=""
city=""
state=""
zipCode=""
pashua_run "$conf" "$customLocation"
if [[ "$workLoc" == "Headquarters" ]]
then
if [[ $workAddress == "" ]]
then
workAddress="N/a"
fi
if [[ $city == "" ]]
then
city="N/a"
fi
if [[ $state == "" ]]
then
state="N/a"
fi
if [[ $zipCode == "" ]]
then
zipCode="N/a"
fi
elif [[ "$workLoc" == "Remote (Address Required)" ]]
then
if [[ $workAddress == "" ]] || [[ $city == "" ]] || [[ $state == "" ]] || [[ $zipCode == "" ]]
then
#Re-Run Pashua
main
fi
fi
}
#kick off Pashua via Function
main
#Create Conf File
createConf
#Send the email
sendEmail
echo "Pashua created the following variables:"
echo " Full Name = $fullName"
echo " User ID = $userID"
echo " Email Address = $email"
echo " Work Location = $workLoc"
echo " Work Address = $workAddress"
echo " City = $city"
echo " State = $state"
echo " Zip = $zipCode"
echo ""