-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·103 lines (77 loc) · 2.98 KB
/
install.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
#!/usr/bin/env bash
baseDir=${1:-/Applications/Slack.app}
DEV_MODE=${DEV_MODE:-false}
if [ "$baseDir" == "-h" ] || [ "$baseDir" == "--help" ]; then
echo "Usage $0 [/path/to/Slack.app]"
echo ''
echo 'If /path/to/Slack.app is not provided, then we will look in /Applications/Slack.app'
exit
fi
function patch_js_file() {
local jsFile="${1}"
local baseDir="${2:-/Applications/Slack.app}"
local snippet=""
local cacheBuster=$(date +'%s')
local startPattern='// START MASHUPMILL/SLACK-THEMES -- DO NOT MODIFY'
local endPattern='// END MASHUPMILL/SLACK-THEMES -- DO NOT MODIFY'
if [ ! -f "$jsFile" ]; then
echo "Could not find ${jsFile} in ${baseDir}"
exit 1
fi
if [ ! -w "$jsFile" ]; then
echo "Write permission not granted to ${jsFile}. Try sudo $0 $1"
exit 1
fi
if [[ $DEV_MODE == "true" ]]; then
cacheBuster='${Date.now()}'
fi
if [ -f ./snippet.js ] && grep -q "$startPattern" ./snippet.js ; then
# load snippet locally
snippet=$(cat ./snippet.js | sed s/BUST_A_CACHE/$cacheBuster/g)
else
# load snippet remotely
snippet=$(curl -s 'https://raw.githubusercontent.com/MashupMill/slack-themes/master/snippet.js' | sed s/BUST_A_CACHE/$cacheBuster/g)
fi
# strip out the existing snippet
local jsWithoutTheme=$(sed -e "\\|${startPattern}|,\\|${endPattern}|d" "$jsFile")
# write out the js file without the snippet
echo "${jsWithoutTheme}" > "$jsFile"
if [[ $DEV_MODE == "true" ]]; then
# add the snippet to the js file replacing the baseurl with localhost
echo "$snippet" | sed 's|https://raw.githubusercontent.com/MashupMill/slack-themes/master/|http://localhost:8164/|g' >> "$jsFile"
else
# add the snippet to the js file
echo "${snippet}" >> "$jsFile"
fi
}
jsFile=$(find "$baseDir" -name ssb-interop.js)
asarFile=$(find "$baseDir" -name app.asar)
if [ -f "$jsFile" ]; then
patch_js_file "$jsFile" "$baseDir"
else
if [ ! -f "$asarFile" ]; then
echo "Could not find app.asar in ${baseDir}"
exit 1
fi
if [ ! -f "${asarFile}.bak" ]; then
cp "${asarFile}" "${asarFile}.bak" || exit 1
fi
# new format ... need to extract the asar file
## extract to temporary directory
tmpDir=$(mktemp -d -t slackhackXXXXXXXXXXX)
npx asar extract "$asarFile" "$tmpDir"
## patch the js file
jsFile=$(find "$tmpDir" -name ssb-interop.bundle.js)
patch_js_file "$jsFile" "$tmpDir"
## re-pack the archive and move it into place
npx asar pack "$tmpDir" "${tmpDir}/app.asar"
mv -f "${tmpDir}/app.asar" "$asarFile"
## clean-up the tmp dir ... note: currently this doesn't get cleaned up if we exit with an error
rm -fr "tmpDir"
echo "Please restart Slack if it is open."
if [[ $DEV_MODE == "true" ]]; then
# start up a little server
npx http-server --cors -p 8164
echo "Please re-run without dev mode to keep the changes"
fi
fi