Box Edit Woes

Box Edit Woes

2015, Jul 23    

Box released a new version of Box Edit that unfortunately is the furthest thing from "deployable" in an enterprise environment. The package by default installs to the user's profile in ~/Library/Application Support/Box/Box Edit. This presents an issue to those of us who provide Box Edit through a software deployment solution such as Munki. Below the break I explain how I was able to change the package using AutoPKG and some basic scripting to make this software somewhat "deployable".

In order to get started with Box Edit we needed to determine what Box is actually installing and where it was installing them. Since we knew that items were being installed in ~/Library/Application Support/Box/Box Edit, I checked there first. There are only two files used for Box Edit which are as follows:

  • Box Edit.app
  • Box Local Com Server.app

These two applications are installed and then called using login items for each user. These login items are not created once but for each user that logs in and installs the Application which could become very messy. So what we want to do is copy these two files that Box Edit uses in a central location so every user can use them and multiple installs for each user are not required. This is actually accomplished with an AutoPKG recipe which will do the work for you as the files themselves are located in the Box Edit Installer.app in the following locations:

  • Install Box Edit.app/Contents/Resources/Box Edit.app
  • Install Box Edit.app/Contents/Resources/Box Local Server.app

You can synchronize my AutoPKG recipe repo which is located at https://github.com/autopkg/joshua-d-miller-recipes. Now on to the additional customization.

Since Box likes to make login items for each user even if we install it in a central location the method I used to keep this from happening was creating a LaunchAgent that launches a script that will perform the following:

  • Launch Box Edit.app from our central install location /Library/Application Support/Box/Box/Edit
  • Once completed it checks to see if the login items were created for the user and using OSAScript removes them

So when using Munki we use postinstall_script to perform this. I also make use of preinstall_script due to the fact that the removal of the old version which had an Internet Plugin and an Application bundle in /Applications is not performed when copying just these two files over. I have gone ahead and attached my pkginfo below which you can use for your reference or if you are using Munki you can use my AutoPKG recipe which has all this fun stuff built right in.  Your mileage may vary on how this works for you but it seems to work well for me. We are in the final stages of QA and will be deploying it to our users very soon.

This is a great example of a software vendor who claims to have an "enterprise" ready product that misses the mark. Systems Administrators should not have to code this kind of logic to deploy a piece of software in an enterprise environment. I have gone ahead and submitted a ticket to Box with my finding and detailing what needed to be done to deploy this application.  I suggest those of you who use this product also submit a ticket as they will be more likely to take action if more people are reporting the issue. If you have any questions please be sure to leave a comment or you can contact me in the MacAdmins Slack channel.

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
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version='1.0'>
<dict>
	<key>_metadata</key>
	<dict>
		<key>created_by</key>
		<string>sadmin</string>
		<key>creation_date</key>
		<date>2015-07-09T15:55:01Z</date>
		<key>munki_version</key>
		<string>2.2.4.2431</string>
		<key>os_version</key>
		<string>10.10.4</string>
	</dict>
	<key>autoremove</key>
	<false/>
	<key>blocking_applications</key>
	<array/>
	<key>catalogs</key>
	<array>
		<string>production</string>
	</array>
	<key>category</key>
	<string>Social</string>
	<key>description</key>
	<string>Box Edit is an add-on feature that allows you to edit or create files directly on Box. Designed for all file types, browsers, and platforms, Box Edit uses the default application installed on your computer to edit or create simple and centralized content: DOC files open in Microsoft Word, PPT files open in Microsoft PowerPoint, images open in Photoshop (if installed), CAD files open in AutoCAD, and so forth.</string>
	<key>developer</key>
	<string>Box</string>
	<key>display_name</key>
	<string>Box Edit</string>
	<key>installer_item_hash</key>
	<string>2b6f193c5b7b07bbc219e7b037dafa4843cfc737d4aae0ee0ab0d852fa708507</string>
	<key>installer_item_location</key>
	<string>Social/Box Edit-3.0.18.dmg</string>
	<key>installer_item_size</key>
	<integer>3023</integer>
	<key>installer_type</key>
	<string>copy_from_dmg</string>
	<key>installs</key>
	<array>
		<dict>
			<key>CFBundleIdentifier</key>
			<string>box.com.Box-Edit</string>
			<key>CFBundleName</key>
			<string>Box Edit</string>
			<key>CFBundleShortVersionString</key>
			<string>3.0.18(584)</string>
			<key>CFBundleVersion</key>
			<string>3.0.18(584)</string>
			<key>minosversion</key>
			<string>10.6</string>
			<key>path</key>
			<string>/Library/Application Support/Box/Box Edit/Box Edit.app</string>
			<key>type</key>
			<string>application</string>
			<key>version_comparison_key</key>
			<string>CFBundleVersion</string>
		</dict>
		<dict>
			<key>CFBundleIdentifier</key>
			<string>com.box.Box-Local-Com-Server</string>
			<key>CFBundleName</key>
			<string>Box Local Com Server</string>
			<key>CFBundleShortVersionString</key>
			<string>3.0.18(584)</string>
			<key>CFBundleVersion</key>
			<string>3.0.18(584)</string>
			<key>minosversion</key>
			<string>10.6</string>
			<key>path</key>
			<string>/Library/Application Support/Box/Box Edit/Box Local Com Server.app</string>
			<key>type</key>
			<string>application</string>
			<key>version_comparison_key</key>
			<string>CFBundleVersion</string>
		</dict>
	</array>
	<key>items_to_copy</key>
	<array>
		<dict>
			<key>destination_path</key>
			<string>/Library/Application Support/Box/Box Edit</string>
			<key>source_item</key>
			<string>Install Box Edit.app/Contents/Resources/Box Edit.app</string>
		</dict>
		<dict>
			<key>destination_path</key>
			<string>/Library/Application Support/Box/Box Edit</string>
			<key>source_item</key>
			<string>Install Box Edit.app/Contents/Resources/Box Local Com Server.app</string>
		</dict>
	</array>
	<key>minimum_os_version</key>
	<string>10.7</string>
	<key>name</key>
	<string>Box Edit</string>
	<key>postinstall_script</key>
	<string>#!/bin/bash
# This script will create the LaunchAgent and script needed
# to make this application somewhat enterprise ready - Joshua D. Miller
# [email protected] - July 22, 2015 - The Pennsylvania State University
# Check if College of Education Script Directory exists and if not make it
/bin/test -d /Library/Scripts/EDUC || /bin/mkdir /Library/Scripts/EDUC
# Create Box Edit Fix Script if it doesn't exist
if [ ! -e '/Library/Scripts/EDUC/Box Edit' ]
then
	/bin/echo '#!/bin/bash
# This simple bash script runs at login and determines if Box is Running
# If not it will launch it and remove the user login agents it attempts to
# create.  Used with the login agent - Joshua D. Miller - [email protected]
# July 22, 2015 - They Pennsylvania State University
if /bin/ps -ax | /usr/bin/grep \'Box Edit\' | /usr/bin/grep -v grep | /usr/bin/grep -v bash
then
	if /usr/bin/osascript -e 'tell application \'System Events\' to get the name of login items whose name contains \'Box Edit\''
	then
		/usr/bin/osascript -e 'tell application \'System Events\' to delete login item \'Box Edit\''
		/usr/bin/osascript -e 'tell application \'System Events\' to delete login item \'Box Local Com Server\''
	else
		exit 0
	fi
else
	/usr/bin/open \'/Library/Application Support/Box/Box Edit/Box Edit.app\'
	/bin/sleep 5
	if /usr/bin/osascript -e 'tell application \'System Events\' to get the name of login items whose name contains \'Box Edit\''
	then
		/usr/bin/osascript -e 'tell application \'System Events\' to delete login item \'Box Edit\''
		/usr/bin/osascript -e 'tell application \'System Events\' to delete login item \'Box Local Com Server\''
	else
		exit 0
	fi
fi
	' &amp;gt; '/Library/Scripts/EDUC/Box Edit'
else
	/bin/echo 'Script exists.  Creation not needed.'
fi
# Set Box Edit Script as Executable
/bin/chmod 755 '/Library/Scripts/EDUC/Box Edit'
# Allow all users to modify the Box Edit Folder
# This is required so that Box Edit can function from its new location
/bin/chmod 777 -R '/Library/Application Support/Box/Box Edit/'
# Create Box Edit LaunchAgent
if [ ! -e /Library/LaunchAgents/edu.psu.educ.boxedit.plist ]
then
	/bin/echo '&amp;lt;?xml version='1.0' encoding='UTF-8'?&amp;gt;
&amp;lt;!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'&amp;gt;
&amp;lt;plist version='1.0'&amp;gt;
&amp;lt;dict&amp;gt;
	&amp;lt;key&amp;gt;KeepAlive&amp;lt;/key&amp;gt;
	&amp;lt;false/&amp;gt;
	&amp;lt;key&amp;gt;Label&amp;lt;/key&amp;gt;
	&amp;lt;string&amp;gt;edu.psu.educ.boxedit&amp;lt;/string&amp;gt;
	&amp;lt;key&amp;gt;ProgramArguments&amp;lt;/key&amp;gt;
	&amp;lt;array&amp;gt;
		&amp;lt;string&amp;gt;/Library/Scripts/EDUC/Box Edit&amp;lt;/string&amp;gt;
	&amp;lt;/array&amp;gt;
	&amp;lt;key&amp;gt;RunAtLoad&amp;lt;/key&amp;gt;
	&amp;lt;true/&amp;gt;
&amp;lt;/dict&amp;gt;
&amp;lt;/plist&amp;gt;
	' &amp;gt; /Library/LaunchAgents/edu.psu.educ.boxedit.plist
else
	/bin/echo 'LaunchAgent exists.  Creation not needed.'
fi
exit 0
	</string>
	<key>preuninstall_script</key>
	<string>#!/bin/bash
# Kill Box Edit Processes
if /bin/ps -ax | /usr/bin/grep \'Box Edit\' | /usr/bin/grep -v grep | /usr/bin/grep -v bash
then
	/usr/bin/killall 'Box Edit'
	/usr/bin/killall 'Box Local Com Server'
else
	/bin/echo 'Processes not running.  Continuing...'
fi
	</string>
	<key>postuninstall_script</key>
	<string>#!/bin/bash
# This script will remove all the pieces of Box Edit that were
# installed - Joshua D. Miller - [email protected] - July 22, 2015
# The Pennsylvania State University
# Remove LaunchAgent
if [ -e '/Library/LaunchAgents/edu.psu.educ.boxedit.plist' ]
then
	/bin/launchctl unload '/Library/LaunchAgents/edu.psu.educ.boxedit.plist'
	/bin/rm -f '/Library/LaunchAgents/edu.psu.educ.boxedit.plist'
else
	/bin/echo 'LaunchAgent not installed.  Continuing...'
fi
# Remove Script
if [ -e '/Library/Scripts/EDUC/BoxEdit' ]
then
	/bin/rm -f '/Library/Scripts/EDUC/Box Edit'
else
	/bin/echo 'Script not installed.  Continuing...'
fi
# Remove EDUC Directory if empty
if /usr/bin/find /Library/Scripts/EDUC -maxdepth 0 -empty | read;
then
	/bin/rm -rf /Library/Scripts/EDUC
else
	/bin/echo 'Directory not empty.  Continuing...'
fi
# Remove Box Edit Directory from /Library/Application Support
/bin/rm -rf '/Library/Application Support/Box/Box Edit'
if /usr/bin/find '/Library/Application Support/Box' -maxdepth 0 -empty | read;
then
	/bin/rm -rf '/Library/Application Support/Box'
else
	/bin/echo 'Directory not empty.  Continuing...'
fi
	</string>
	<key>preinstall_script</key>
	<string>#!/bin/bash
# This preinstall script will basically do what the Box
# Edit Installer Application does and remove the remnants
# of version 1.0+ - Joshua D. Miller - [email protected]
# July 22, 2015 - The Pennsylvania State University
# Remove Box Edit Internet Plugin file
if [ -e '/Library/Internet Plug-Ins/Box Edit.plugin' ]
then
	/bin/rm -rf '/Library/Internet Plug-Ins/Box Edit.plugin'
else
	/bin/echo 'Plugin Not Present.  Continuing...'
fi
# Remove old Box Edit application
if [ -e '/Applications/Box Edit.app' ]
then
	/bin/rm -rf '/Applications/Box Edit.app'
else
	/bin/echo 'Old Version not present.  Continuing...'
fi
# If the new Box Edit application is running stop it
if /bin/ps -ax | /usr/bin/grep 'Box Edit' | grep -v grep
then
	/usr/bin/killall 'Box Edit'
	/usr/bin/killall 'Box Local Com Server'
else
	/bin/echo 'Box Edit is not running.  Proceeding with Install...'
fi
	</string>
	<key>unattended_install</key>
	<true/>
	<key>unattended_uninstall</key>
	<true/>
	<key>uninstall_method</key>
	<string>remove_copied_items</string>
	<key>uninstallable</key>
	<true/>
	<key>version</key>
	<string>3.0.18</string>
</dict>
</plist>