-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall
executable file
·250 lines (199 loc) · 7.64 KB
/
install
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
#!/usr/bin/env bash
shopt -s expand_aliases
set -e
# Usage info
# dev-mode-only -t switch omitted from printed help:
# -t Download image file to CWD instead of a tmp dir (the default behavior).
show_help() {
cat << EOF
Usage: ${0##*/} [-hd]
Install the Jupyter.app
-h Display this help and exit.
-d Dry run. For debug purposes, echo commands instead of running them.
EOF
}
# if set to -d, perform a dryrun
dryrun=
# for internal dev purposes.
devmode=
OPTIND=1
# Resetting OPTIND is necessary if getopts was used previously in the script.
# It is a good idea to make OPTIND local if you process options in a function.
# set up command line parsing via getopts
while getopts hdtr opt; do
case $opt in
h) show_help
exit 0
;;
d) dryrun=-d
;;
t) devmode=-t
;;
*) show_help >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Discard the options and sentinel --
# define the dryrun echo command as appropriate
alias dryecho=
if [ "$dryrun" = "-d" ]; then
alias dryecho='echo'
fi
# read a single string val from a .plist file
plget() {
key=$1
pth=$2
dryecho plutil -extract $1 xml1 -o - $pth | grep "<string>.*</string>" | sed -e "s/<string>\(.*\)<\/string>/\1/g"
}
# helper function(s)
sedvar() {
fname=$1
shift 1
for var in $@; do
# the \$[{]* ... [}]* part will match vars with or without curly braces.
# The -i.bak flag ensures that this command is osx/linux universal
dryecho sed -i.bak "s#\$[{]*$var[}]*#${!var}#g" ${fname}
done
# clean up sed backup
dryecho rm "${fname}.bak"
}
# replace the value for a key in a .strings file
sedStringsFile() {
key=$1
val=$2
shift 2
for pth in $@; do
dryecho sed -i '' "s/${key}.*/${key} = \"${val}\";/g" ${pth}
done
}
# get some user-defined and project-wide vars
reldir=$(dirname "$(stat -f "$0")")
globals_src="${reldir}"/resource/globals
source ${globals_src}
# make a temporary dir
temp=$TMPDIR$(uuidgen)
dryecho mkdir -p "${temp}/mount"
# figure out what the download's extension will be
if [ "${APP_BASE}" = "chromium" ]; then
downloadExt=".zip"
else
downloadExt=".dmg"
fi
# decide where to save the chrome app download
if [ "$devmode" = "-t" ]; then
downloadName="./${APP_BASE}"
else
downloadName="${temp}/${APP_BASE}"
fi
downloadPath="${downloadName}${downloadExt}"
# download the app
if ! [ "$devmode" = "-t" -a -f ${downloadPath} ]; then
"${reldir}"/script/download/${APP_BASE}.sh $downloadPath $dryrun
fi
# clean up any existing app
if [ -e "${ABS_APP_PATH}" ]; then
printf "cleaning up existing app...\n"
dryecho rm -rf "${ABS_APP_PATH}"
printf "removed ${ABS_APP_PATH}\n\n"
fi
# install the app. Use cp -R to preserve symlinks
printf "installing base browser app...\n"
if [ "$downloadExt" = ".zip" ]; then
# existing unzip dir can cause problems, get rid of it
dryecho rm -rf ${downloadName}
if [ "$dryrun" = "-d" ]; then
# special dryrun handling is required here due to the > and | characters
dryecho unzip ${downloadPath} -d ${downloadName} \> /dev/null 2\>\&1
appDownloadPath="Chromium.app"
dryecho mv "${appDownloadPath}" "${ABS_APP_PATH}"
dryecho rm -rf ${downloadName}
else
unzip ${downloadPath} -d ${downloadName} > /dev/null 2>&1
appDownloadPath=$(find ${downloadName} -name "Chromium.app" | head -n 1)
mv "${appDownloadPath}" "${ABS_APP_PATH}"
rm -rf ${downloadName}
fi
else
# for now assume this is a .dmg
if [ "$dryrun" = "-d" ]; then
# special dryrun handling is required here due to all of the > and | characters
dryecho yes \| hdiutil attach -noverify -nobrowse -mountpoint "${temp}/mount" ${downloadPath} \> /dev/null 2\>\&1
dryecho rm -rf "${ABS_APP_PATH}"
dryecho cp -R "$temp"/mount/*.app "${ABS_APP_PATH}"
dryecho hdiutil detach "${temp}/mount" \> /dev/null 2\>\&1
else
yes | hdiutil attach -noverify -nobrowse -mountpoint "${temp}/mount" ${downloadPath} > /dev/null 2>&1
rm -rf "${ABS_APP_PATH}"
cp -R "$temp"/mount/*.app "${ABS_APP_PATH}"
hdiutil detach "${temp}/mount" > /dev/null 2>&1
fi
fi
printf "done\n\n"
# clean up the temp dir
printf "cleaning up base browser install files...\n"
dryecho rm -r "${temp}"
printf "done\n\n"
# rename the actual exe
printf "renaming app executable...\n"
dryecho mv "${ABS_APP_BIN_SRC}" "${ABS_APP_BIN}"
printf "done\n\n"
# modify the app's plist's bundle name
printf "Modifying app's Info.plist...\n"
dryecho plutil -replace CFBundleDisplayName -string "${APP_NAME}" "${ABS_CONTENTS}/Info.plist"
dryecho plutil -replace CFBundleIdentifier -string "${BUNDLE_ID}" "${ABS_CONTENTS}/Info.plist"
dryecho plutil -replace CFBundleName -string "${APP_NAME}" "${ABS_CONTENTS}/Info.plist"
dryecho plutil -replace KSBrandID -string "${BRAND_ID}" "${ABS_CONTENTS}/Info.plist"
dryecho plutil -replace KSProductID -string "${BUNDLE_ID}" "${ABS_CONTENTS}/Info.plist"
printf "done\n\n"
# modify the localization strings. Fixes visible name in finder
printf "Modifying app's localized .strings resources...\n"
if [ "$dryrun" = "-d" ]; then
INFO_PLIST_STRINGS="InfoPlist.strings"
else
INFO_PLIST_STRINGS=$(find "${ABS_RESOURCES}" -name "InfoPlist.strings")
fi
dryecho sedStringsFile CFBundleDisplayName "${APP_NAME}" ${INFO_PLIST_STRINGS}
dryecho sedStringsFile CFBundleName "${APP_NAME}" ${INFO_PLIST_STRINGS}
printf "done\n\n"
# modify the app's plist's exe to point to the script we just copied over
printf "Modifying app's Info.plist to point to executable scripts...\n"
dryecho plutil -replace CFBundleExecutable -string "${APP_NAME}" "${ABS_CONTENTS}/Info.plist"
printf "done\n\n"
if [ "$JUPYTER_WRAP" = true ]; then
# change the icon for some good jupyter style
printf "changing app icon to jupyter...\n"
dryecho cp "${ABS_ICONS_SRC}" "${ABS_ICONS}"
printf "done\n\n"
# copy over the outer wrapper script, which handles the terminal window
printf "copying outer wrapper script over to app...\n"
dryecho cp "${ABS_OUTER_WRAP_SRC}" "${ABS_OUTER_WRAP}"
printf "setting vars in outer wrapper script...\n"
sedvar "${ABS_OUTER_WRAP}" TERM_NAME ABS_MID_WRAP
printf "done\n\n"
# copy over the mid wrapper script, which launches the jupyter server
printf "copying mid wrapper script over to app...\n"
dryecho cp "${ABS_MID_WRAP_SRC}" "${ABS_MID_WRAP}"
printf "setting vars in mid wrapper script...\n"
sedvar "${ABS_MID_WRAP}" VIRTUAL_ENV JUPYTER_BIN JUPYTER_CMD JUPYTER_NOTEBOOK_DIR ABS_INNER_WRAP BROWSER_CMD
printf "done\n\n"
# copy over the inner wrapper script, which automatically passes certain arguments to the chrome bin
printf "copying inner wrapper script over to app...\n"
dryecho cp "${ABS_INNER_WRAP_SRC}" "${ABS_INNER_WRAP}"
printf "setting vars in inner wrapper script...\n"
sedvar "${ABS_INNER_WRAP}" ABS_APP_SUPPORT_PATH ABS_APP_BIN
printf "done\n\n"
fi
# optionally install any extension manifests to the new Chrome instance's 'Application Support' dir
if [ "$EXTENSIONS" = true ]; then
printf "Adding extension manifests to \"${ABS_EXTENSION_JSON}\"...\n"
# create the External Extensions dir if it doesn't exist
dryecho mkdir -p "${ABS_EXTENSION_JSON}"
for extjson in ${ABS_EXTENSION_JSON_SRC}; do
dryecho cp "${extjson}" "${ABS_EXTENSION_JSON}"
done
printf "done\n\n"
fi
## possible extra commands needed for chrome_canary install
# xattr -lr /Applications/Chrome-canary.app/
# sudo codesign -f -s - /Applications/Chrome-canary.app/Contents/MacOS/Chrome-canary