-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinventory-collection-settings.sh
executable file
·116 lines (100 loc) · 3.04 KB
/
inventory-collection-settings.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
#!/bin/bash
: <<'DOC'
Script for setting Inventory Collection Settings on all instances
DOC
# source the _common-framework.sh file
# TIP for Visual Studio Code - Add Custom Arg '-x' to the Shellcheck extension settings
source "_common-framework.sh"
# set instance list type
instance_list_type="ios"
usage() {
cat <<'USAGE'
Usage:
./set_credentials.sh - set the Keychain credentials
[no arguments] - interactive mode
--template /path/to/Template.json - template to use (must be a json file)
--il FILENAME (without .txt) - provide a server-list filename
(must exist in the instance-lists folder)
--i JSS_URL - perform action on a single instance
(must exist in the relevant instance list)
--all - perform action on ALL instances in the instance list
-v - add verbose curl output
USAGE
}
set_inventory_collection() {
# determine jss_url
set_credentials "$jss_instance"
jss_url="${jss_instance}"
# send request
curl_url="$jss_url/api/v1/computer-inventory-collection-settings"
curl_args=("--request")
curl_args+=("PATCH")
curl_args+=("--header")
curl_args+=("Content-Type: application/json")
curl_args+=("--header")
curl_args+=("Accept: application/json")
curl_args+=("--data-binary")
curl_args+=(@"$settings_file")
send_curl_request
}
if [[ ! -d "${this_script_dir}" ]]; then
echo "ERROR: path to repo ambiguous. Aborting."
exit 1
fi
## MAIN BODY
# -------------------------------------------------------------------------
# Command line options (presets to avoid interaction)
# -------------------------------------------------------------------------
# Command line override for the above settings
while [[ "$#" -gt 0 ]]; do
key="$1"
case $key in
-t|--template)
shift
template="$1"
;;
-il|--instance-list)
shift
instance_list_file="$1"
;;
-i|--instance)
shift
chosen_instance="$1"
;;
-a|--all)
all_instances=1
;;
-v|--verbose)
verbose=1
;;
-h|--help)
usage
exit
;;
esac
# Shift after checking all the cases to get the next option
shift
done
echo
# Set default instance list
default_instance_list="prd"
# get template (must be a json file)
filetype="json"
choose_template_file
# select the instances that will be changed
choose_destination_instances
# get specific instance if entered
if [[ $chosen_instance ]]; then
jss_instance="$chosen_instance"
echo "Setting Inventory Collection settings on $jss_instance..."
set_inventory_collection
else
for instance in "${instances_list[@]}"; do
jss_instance="$instance"
echo "Setting Inventory Collection settings on $jss_instance..."
set_inventory_collection
done
fi
echo
echo "Finished"
echo