Skip to content

Commit 60596b5

Browse files
committed
Automated Push
1 parent 779a9f7 commit 60596b5

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/zsh
2+
3+
################################################################################################
4+
# Created by Nicholas McDonald (DTNB) | [email protected] | Kandji, Inc. | Solutions Engineering
5+
################################################################################################
6+
# Created on 06/08/2020
7+
# Updated on 03/06/2023
8+
################################################################################################
9+
# Software Information
10+
################################################################################################
11+
# Converts a plist to a mobileconfig profile by extracting the main dictionary
12+
################################################################################################
13+
# License Information
14+
################################################################################################
15+
# Copyright 2023 Kandji, Inc.
16+
#
17+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
18+
# software and associated documentation files (the "Software"), to deal in the Software
19+
# without restriction, including without limitation the rights to use, copy, modify, merge,
20+
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
21+
# to whom the Software is furnished to do so, subject to the following conditions:
22+
#
23+
# The above copyright notice and this permission notice shall be included in all copies or
24+
# substantial portions of the Software.
25+
#
26+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
27+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
28+
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
29+
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
30+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31+
# DEALINGS IN THE SOFTWARE.
32+
#
33+
################################################################################################
34+
35+
36+
currentUser=$(ls -la /dev/console | cut -d' ' -f4)
37+
38+
plistPath="$1"
39+
40+
if [ "${plistPath}" = "" ]; then
41+
echo "No File Loaded"
42+
exit 1
43+
fi
44+
45+
PayloadUUID=$(/usr/bin/uuidgen)
46+
PayloadID=$(/usr/bin/uuidgen)
47+
ProfileUUID=$(/usr/bin/uuidgen)
48+
ProfileID=$(/usr/bin/uuidgen)
49+
50+
collectPlistDictionary=$(/usr/libexec/PlistBuddy ${plistPath} -x -c print | /usr/bin/xpath -e '/plist[@version="1.0"]/dict/child::node()' 2>/dev/null | /usr/bin/awk NF)
51+
fullPlistName=$(/usr/bin/basename -- "${plistPath}")
52+
prefDomain="${fullPlistName%.*}"
53+
54+
mobileConfigOut="/Users/${currentUser}/Downloads/${prefDomain}.mobileconfig"
55+
56+
/bin/cat > ${mobileConfigOut} <<EOF
57+
<?xml version="1.0" encoding="UTF-8"?>
58+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
59+
<plist version="1.0">
60+
<dict>
61+
<key>PayloadContent</key>
62+
<array>
63+
<dict>
64+
${collectPlistDictionary}
65+
<key>PayloadDescription</key>
66+
<string>${prefDomain}</string>
67+
<key>PayloadDisplayName</key>
68+
<string>${prefDomain}</string>
69+
<key>PayloadIdentifier</key>
70+
<string>io.se.kandji.${PayloadID}</string>
71+
<key>PayloadOrganization</key>
72+
<string>Kandji, Inc.</string>
73+
<key>PayloadType</key>
74+
<string>${prefDomain}</string>
75+
<key>PayloadUUID</key>
76+
<string>${PayloadUUID}</string>
77+
<key>PayloadVersion</key>
78+
<integer>1</integer>
79+
</dict>
80+
</array>
81+
<key>PayloadDescription</key>
82+
<string>${prefDomain}</string>
83+
<key>PayloadDisplayName</key>
84+
<string>${prefDomain}</string>
85+
<key>PayloadIdentifier</key>
86+
<string>io.kandji.customprofile.${ProfileID}</string>
87+
<key>PayloadOrganization</key>
88+
<string>Kandji, Inc.</string>
89+
<key>PayloadScope</key>
90+
<string>System</string>
91+
<key>PayloadType</key>
92+
<string>Configuration</string>
93+
<key>PayloadUUID</key>
94+
<string>${ProfileUUID}</string>
95+
<key>PayloadVersion</key>
96+
<integer>1</integer>
97+
</dict>
98+
</plist>
99+
EOF
100+
101+
102+
/usr/bin/plutil -convert xml1 ${mobileConfigOut}
103+
104+
validateMobileConfig=$(/usr/bin/plutil -lint ${mobileConfigOut} | /usr/bin/awk '{print $NF}')
105+
106+
107+
if [ "$validateMobileConfig" = "OK" ]; then
108+
echo "Plist to MobileConfig coversion Succeeded the MobileConfig file has been placed in your downloads folder."
109+
exit 0
110+
else
111+
echo "Plist to MobileConfig coversion Failed"
112+
echo "DETAILS:"
113+
echo "-----------"
114+
echo "$validateMobileConfig"
115+
exit 1
116+
fi
117+
118+
exit 0

Plist2MobileConfig/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Intructions
2+
3+
Simply download the raw .zsh file to your Mac. Then run the following command
4+
5+
zsh /path/to/downloaded/script/Plist2MobileConfig.zsh /path/to/plist/to/convert/myplist.plist
6+
7+
The script will place a new .mobileconfig file in your downloads folder.
8+
9+
10+
# Description
11+
The Plist2MobileConfig allows you to convert a standard .plist file, into a mobile config file that will manage the preference domain leveraging managed preferences. App vendors must have implemented UserDefaults (https://developer.apple.com/documentation/foundation/userdefaults) within their app correctly for a profile to appropriately work this way.

0 commit comments

Comments
 (0)