This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_latest_slack_osx_app.sh
executable file
·59 lines (50 loc) · 1.89 KB
/
install_latest_slack_osx_app.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
#!/bin/bash
# your funeral
# seriously use autopkg or something
DOWNLOAD_URL="https://slack.com/ssb/download-osx"
APP_NAME="Slack.app"
APP_PATH="/Applications/$APP_NAME"
APP_VERSION_KEY="CFBundleShortVersionString"
SLACK_UNZIP_DIRECTORY="/tmp"
SLACK_APP_UNZIPPED_PATH="/tmp/Slack.app/"
currentSlackVersion=$(/usr/bin/curl -s 'https://downloads.slack-edge.com/mac_releases/releases.json' | grep -o "[0-9]\.[0-9]\.[0-9]" | tail -1)
if [ -d "$APP_PATH" ]; then
localSlackVersion=$(defaults read "$APP_PATH/Contents/Info.plist" "$APP_VERSION_KEY")
if [ "$currentSlackVersion" = "$localSlackVersion" ]; then
printf "Slack is already up-to-date. Version: %s" "$localSlackVersion"
exit 0
fi
fi
# OS X major release version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
if [ "$osvers" -lt 7 ]; then
printf "Slack is not available for Mac OS X 10.6 or earlier\n"
exit 403
elif [ "$osvers" -ge 7 ]; then
finalDownloadUrl=$(curl "$DOWNLOAD_URL" -s -L -I -o /dev/null -w '%{url_effective}')
else
printf "Unable to read OS version"
exit 404
fi
zipName=$(printf "%s" "${finalDownloadUrl[@]}" | sed 's@.*/@@')
slackZipPath="/tmp/$zipName"
rm -rf "$slackZipPath" "$SLACK_APP_UNZIPPED_PATH"
/usr/bin/curl --retry 3 -L "$finalDownloadUrl" -o "$slackZipPath"
/usr/bin/unzip -o -q "$slackZipPath" -d "$SLACK_UNZIP_DIRECTORY"
rm -rf "$slackZipPath"
if pgrep 'Slack'; then
printf "Error: Slack is currently running!\n"
exit 409
else
if [ -d "$APP_PATH" ]; then
rm -rf "$APP_PATH"
fi
mv -f "$SLACK_APP_UNZIPPED_PATH" "$APP_PATH"
# Slack permissions are stupid
chown -R root:admin "$APP_PATH"
localSlackVersion=$(defaults read "$APP_PATH/Contents/Info.plist" "$APP_VERSION_KEY")
if [ "$currentSlackVersion" = "$localSlackVersion" ]; then
printf "Slack is now updated/installed. Version: %s" "$localSlackVersion"
exit 0
fi
fi