Created
September 6, 2019 12:48
-
-
Save zkxs/21440cb347d144fb87e416bf5e15e153 to your computer and use it in GitHub Desktop.
Injects some arbitrary javascript into Slack for theme installation reasons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if ! uname | grep -iq darwin; then | |
echo "This script is designed for Mac OSX use" >&2 | |
exit 1 | |
fi | |
if ! [ -e "patch.js" ]; then | |
echo "Place your javascript to inject in patch.js" >&2 | |
exit 1 | |
fi | |
cleanup() { | |
rm *.manifest 2>/dev/null | |
rm *.list 2>/dev/null | |
rm -rf app.asar* 2>/dev/null | |
rm -rf app_extracted* 2>/dev/null | |
rm ssb-interop.bundle.js 2>/dev/null | |
} | |
cleanup | |
if [ -a "Slack.app" ]; then | |
echo "Slack.app already exists... skipping backup" | |
else | |
echo "Backing up Slack.app" | |
cp -a /Applications/Slack.app Slack.app | |
fi | |
# Grab app.asar | |
cp Slack.app/Contents/Resources/app.asar . | |
cp -R /Applications/Slack.app/Contents/Resources/app.asar.unpacked/ app.asar.unpacked | |
find app.asar.unpacked -type f | sed 's/^app\.asar\.unpacked//' > unpacked.manifest | |
# extract | |
asar extract app.asar app_extracted | |
find app_extracted -type f | sed 's/^app_extracted//' > all.manifest | |
cat all.manifest unpacked.manifest | sort | uniq -u > only-packed.manifest | |
# do scketchy things | |
echo -ne "\n\n" >> app_extracted/dist/ssb-interop.bundle.js | |
cat patch.js >> app_extracted/dist/ssb-interop.bundle.js | |
# pack | |
asar pack --unpack "{*.node,*.woff2,*.svg,*.less,*.ico,emoji_2017_12_06_sheet_apple_64_indexed_256.webp,emoji_2017_12_06_sheet_google_64_indexed_256.webp,logo_spinner.gif,no_connection.webp}" --unpack-dir "{dist/static/extensions/react-devtools,dist/static/fonts}" app_extracted app.asar.2 | |
find app.asar.2.unpacked -type f | sed 's/^app\.asar\.2\.unpacked//' > unpacked.2.manifest | |
# sanity checks | |
asar list app.asar > app.asar.list | |
asar list app.asar.2 > app.asar.2.list | |
diff app.asar app.asar.2 | |
if [ "$(diff -y --suppress-common-lines unpacked.manifest unpacked.2.manifest | grep '^' | wc -l | sed 's/^ *//')" != "0" ]; then | |
echo "Excluded files differ" >&2 | |
exit 1 | |
fi | |
if [ "$(diff -y --suppress-common-lines app.asar.list app.asar.2.list | grep '^' | wc -l | sed 's/^ *//')" != "0" ]; then | |
echo "Packed files differ" >&2 | |
exit 1 | |
fi | |
# Install | |
echo "root privilege is required to install the patch" | |
sudo mv app.asar.2 /Applications/Slack.app/Contents/Resources/app.asar | |
sudo chown root:wheel /Applications/Slack.app/Contents/Resources/app.asar | |
sudo chmod 644 /Applications/Slack.app/Contents/Resources/app.asar | |
cleanup | |
echo "A copy of the patched ssb-interop.bundle.js has been placed in this folder so you can validate" | |
asar extract-file /Applications/Slack.app/Contents/Resources/app.asar dist/ssb-interop.bundle.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment