-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjamfuploader-run.sh
More file actions
executable file
·204 lines (180 loc) · 7.45 KB
/
jamfuploader-run.sh
File metadata and controls
executable file
·204 lines (180 loc) · 7.45 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
#!/bin/bash
# --------------------------------------------------------------------------------
# A wrapper script for running the jamf-upload.sh script
# --------------------------------------------------------------------------------
# set instance list type
instance_list_type="mac"
# define autopkg_prefs
autopkg_prefs="${HOME}/Library/Preferences/com.github.autopkg.plist"
# --------------------------------------------------------------------------------
# ENVIRONMENT CHECKS
# --------------------------------------------------------------------------------
# source the _common-framework.sh file
DIR=$(dirname "$0")
source "$DIR/_common-framework.sh"
if [[ ! -d "${this_script_dir}" ]]; then
echo "ERROR: path to repo ambiguous. Aborting."
exit 1
fi
# --------------------------------------------------------------------------------
# FUNCTIONS
# --------------------------------------------------------------------------------
usage() {
echo "
# JamfUploader-Run
A script for uploading items to a Jamf Pro instance using the AutoPkg framework and JamfUploader processors, without having to write AutoPkg recipes.
# Requirements
- AutoPkg must be installed and configured
- JamfUploader processors must be available (e.g. by running 'autopkg repo-add grahampugh/jamf-upload')
- Credentials for the Jamf Pro instance must be set in the AutoPkg preferences or in the Keychain (the script will prompt you to run the set_credentials.sh script if not found)
- The jamf-upload.sh script must be available (the script will look for it in ~/Library/AutoPkg/RecipeRepos/com.github.grahampugh.jamf-upload/jamf-upload.sh or in ../jamf-upload/jamf-upload.sh)
# Usage
UPLOADTYPE - type of upload (e.g. pkg, policy, script, etc.
Exactly one value must be provided)
-il | --instance-list FILENAME - provide an instance list filename (without .txt)
(must exist in the instance-lists folder)
-i | --instance JSS_URL - perform action on a specific instance
(must exist in the relevant instance list)
(multiple values can be provided)
-a | -ai | --all-instances - perform action on ALL instances in the instance list
-x | --nointeraction - run without checking instance is in an instance list
(prevents interactive mode)
--user | --client-id CLIENT_ID - use the specified client ID or username
--dp - filter fileshare distribution points on DP name
--prefs <path> - Inherit AutoPkg prefs file provided by the full path to the file
-v[vvv] - Set value of verbosity (default is -v)
-q - Quiet mode (verbosity 0)
-j <path> - Alternative path to jamf-upload.sh script
(default is ~/Library/AutoPkg/RecipeRepos/
com.github.grahampugh.jamf-upload/jamf-upload.sh)
(if not found, will look in ../jamf-upload/jamf-upload.sh)
-h | --help - Show this help message
--[args] - Pass through required arguments for jamf-upload.sh.
Scroll up for a full list of valid arguments.
# Notes
Credentials set in the AutoPkg preferences file will be used if they exist. If not, the keychain will be used. If there is no keychain entry, the script will prompt for you to run the set_credentials.sh script.
The --dp argument can be bypassed by setting the environment variable 'dp_url_filter' to the desired value in the AutoPkg preferences.
"
}
# --------------------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------------------
if [[ ! -f "$jamf_upload_path" ]]; then
# default path to jamf-upload.sh
jamf_upload_path="$HOME/Library/AutoPkg/RecipeRepos/com.github.grahampugh.jamf-upload/jamf-upload.sh"
fi
# ensure the path exists, revert to defaults otherwise
if [[ ! -f "$jamf_upload_path" ]]; then
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
jamf_upload_path="../jamf-upload/jamf-upload.sh"
fi
# get command line args
args=()
chosen_instances=()
while test $# -gt 0 ; do
case "$1" in
-il|--instance-list)
shift
chosen_instance_list_file="$1"
;;
-i|--instance)
shift
chosen_instances+=("$1")
;;
-a|-ai|--all-instances)
all_instances=1
;;
--id|--client-id|--user|--username)
shift
chosen_id="$1"
;;
-x|--nointeraction)
no_interaction=1
;;
-s|--share)
shift
smb_url="$1"
;;
-d|--dp)
shift
dp_url_filter="$1"
;;
-j|--jamf-upload-path)
shift
jamf_upload_path="$1"
if [[ ! -f "$jamf_upload_path" ]]; then
echo "ERROR: jamf-upload.sh not found. Please either run 'autopkg repo-add grahampugh/jamf-upload' or clone the grahampugh/jamf-upload repo to the parent folder of this repo"
exit 1
fi
;;
--prefs)
shift
autopkg_prefs="$1"
if [[ ! -f "$autopkg_prefs" ]]; then
echo "ERROR: prefs file not found"
exit 1
fi
;;
-q)
quiet_mode="yes"
;;
-v*)
verbosity_mode="$1"
;;
-h|--help)
echo "Outputting the help sheet for jamf-upload.sh"
echo
echo "==========================================="
echo
"$jamf_upload_path" --help
echo
echo "==========================================="
echo
usage
exit 0
;;
*)
args+=("$1")
;;
esac
shift
done
echo
# fail if no valid path found
if [[ ! -f "$jamf_upload_path" ]]; then
echo "ERROR: jamf-upload.sh not found. Please either run 'autopkg repo-add grahampugh/jamf-upload' or clone the grahampugh/jamf-upload repo to the parent folder of this repo"
exit 1
fi
if [[ ! $verbosity_mode && ! $quiet_mode ]]; then
# default verbosity
args+=("-v")
elif [[ ! $quiet_mode ]]; then
args+=("$verbosity_mode")
fi
echo "This script will run grahampugh/jamf-upload/jamf-upload.sh on the instance(s) you choose."
if [[ ${#chosen_instances[@]} -eq 1 ]]; then
chosen_instance="${chosen_instances[0]}"
echo "Running on instance: $chosen_instance"
elif [[ ${#chosen_instances[@]} -gt 1 ]]; then
echo "Running on instances: ${chosen_instances[*]}"
fi
# select the instances that will be changed
choose_destination_instances
# run on specified instances
for instance in "${instance_choice_array[@]}"; do
jss_instance="$instance"
# get token
if [[ "$chosen_id" ]]; then
set_credentials "$jss_instance" "$chosen_id"
echo " [request] Using provided Client ID and stored secret for $jss_instance ($jss_api_user)"
else
set_credentials "$jss_instance"
echo " [request] Using stored credentials for $jss_instance ($jss_api_user)"
fi
echo "Running on $jss_instance..."
echo "jamf-upload.sh ${args[*]}"
run_jamfupload
done
echo
echo "Finished"
echo