Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New dep-assign-profile script and multiple serial number support #20

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions docs/operations-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,31 @@ $ ./dep-define-profile.sh ../docs/dep-profile.example.json
}
```

#### dep-assign-profile.sh

For the DEP "MDM server" in the environment variable $DEP_NAME (see above) this script calls to the Apple DEP API [Assign a Profile](https://developer.apple.com/documentation/devicemanagement/assign_a_profile) endpoint to assign a DEP profile UUID to one or more serial numbers.

This is the same task that `depsyncer` performs, in a script that can be used to assign different DEP profiles to specific devices for testing or varying use cases.

**At least two arguments are required**, with the first argument being the DEP profile UUID obtained when the profile was defined (see above) and the second and any subsequent arguments being the serial number(s) the DEP profile should be assigned to.

##### Example usage

```bash
$ ./dep-assign-profile.sh 43277A13FBCA0CFC 07AAD449616F566C12
{
"profile_uuid": "43277A13FBCA0CFC",
"devices": {
"07AAD449616F566C12": "SUCCESS"
}
}
```

#### dep-device-details.sh

For the DEP "MDM server" in the environment variable $DEP_NAME (see above) this script queries the Apple DEP API [Get Device Details](https://developer.apple.com/documentation/devicemanagement/get_device_details) endpoint for a given serial number.

**The first argument is required** and specifies the serial number of the device you want to query.

Note that the API itself supports querying multiple devices at a time if you're able to assemble the appropriate JSON. This script only supports one serial number, however.
**At least one argument is required** and specifies the serial number(s) of the device(s) you want to query.

##### Example usage

Expand All @@ -281,7 +299,7 @@ For the DEP "MDM server" in the environment variable $DEP_NAME (see above) this

**The first argument is required** and specifies the UUID of the profile that was previously defined via the API.

#####
##### Example usage

```bash
$ ./dep-get-profile.sh 43277A13FBCA0CFC
Expand All @@ -307,9 +325,7 @@ $ ./cfg-set-assigner.sh 43277A13FBCA0CFC

For the DEP "MDM server" in the environment variable $DEP_NAME (see above) this script calls to the Apple DEP API [Remove a Profile](https://developer.apple.com/documentation/devicemanagement/remove_a_profile-c2c) endpoint to remove a serial number from being assigned to a DEP profile UUID. Note this is **NOT** the [disown](https://developer.apple.com/documentation/devicemanagement/disown_devices) endpoint and profiles can be re-assigned at any time after using this script.

**The first argument is required** and specifies the serial number of the device to remove DEP profile assignment from.

Note that the API itself supports un-assigning multiple devices at a time if you're able to assemble the appropriate JSON. This script only supports one serial number, however.
**At least one argument is required** and specifies the serial number(s) of the device(s) to remove DEP profile assignment(s) from.

##### Example usage

Expand Down
19 changes: 19 additions & 0 deletions tools/dep-assign-profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# See https://developer.apple.com/documentation/devicemanagement/assign_a_profile

DEP_ENDPOINT=/profile/devices
URL="${BASE_URL}/proxy/${DEP_NAME}${DEP_ENDPOINT}"

PROFILE_UUID="$1"
shift

jq -n --arg profile_uuid "$PROFILE_UUID" --arg devices "$*" '{profile_uuid: $profile_uuid, devices: ($devices|split(" "))}' \
| curl \
$CURL_OPTS \
-u "depserver:$APIKEY" \
-X POST \
-H 'Content-type: application/json;charset=UTF8' \
--data-binary @- \
-A "nanodep-tools/0" \
"$URL"
2 changes: 1 addition & 1 deletion tools/dep-device-details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DEP_ENDPOINT=/devices
URL="${BASE_URL}/proxy/${DEP_NAME}${DEP_ENDPOINT}"

jq -n --arg device "$1" '.devices = [$device]' \
jq -n --arg devices "$*" '{devices: ($devices|split(" "))}' \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! TIL jq has a split! Too bad it doesn't trim surrounding whitespace, too.

| curl \
$CURL_OPTS \
-u "depserver:$APIKEY" \
Expand Down
2 changes: 1 addition & 1 deletion tools/dep-remove-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DEP_ENDPOINT=/profile/devices
URL="${BASE_URL}/proxy/${DEP_NAME}${DEP_ENDPOINT}"

jq -n --arg device "$1" '.devices = [$device]' \
jq -n --arg devices "$*" '{devices: ($devices|split(" "))}' \
| curl \
$CURL_OPTS \
-u "depserver:$APIKEY" \
Expand Down