-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·250 lines (219 loc) · 10.8 KB
/
install.sh
File metadata and controls
executable file
·250 lines (219 loc) · 10.8 KB
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
#!/bin/bash
# Copyright 2022-2026 Salesforce, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SLACK_CLI_NAME="slack"
FINGERPRINT="d41d8cd98f00b204e9800998ecf8427e"
SLACK_CLI_VERSION=
rx='^([0-9]+\.){2}(\*|[0-9]+)(-.*)?$'
while getopts "v:d" flag; do
case "$flag" in
v)
if [[ $OPTARG =~ $rx ]]; then
SLACK_CLI_VERSION=$OPTARG
else
echo "Slack CLI requires a valid semver version number." >&2
exit 1
fi
;;
*)
>&2 echo -e "\x1b[1m⚠️ Warning: An unknown flag '$1' was passed to the Slack CLI installation script!\x1b[0m"
;;
esac
done
if [ $(($# - $OPTIND)) -lt 1 ]; then
if [ ! -z ${@:$OPTIND:1} ]; then
SLACK_CLI_NAME=${@:$OPTIND:1}
fi
fi
# Emphasize text in a string
bold() {
echo -en "\x1b[1m$1\x1b[0m"
}
# Print a message then pause for an amount of time
delay() {
local options="-e"
# Prevent trailing newlines if "-n" is included
if [[ "$3" == "-n" ]]; then
options="-en"
fi
echo $options "$2"
sleep "$1"
}
# Replace /home/username/folder/file with ~/folder/file
home_path() {
local input_string="$1"
echo "${input_string//$HOME/~}"
}
# Originally from https://gist.github.com/jonlabelle/6691d740f404b9736116c22195a8d706
# Echos the inputs, breaks them into separate lines, then sort by semver descending,
# then takes the first line. If that is not the first param, that means $1 < $2
version_lt() {
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"
}
install_slack_cli() {
delay 0.6 "🥁 Hello and welcome! Now beginning to install the..."
delay 0.1 "$(bold " ________ _ _ _____ _ __ _____ _ ________")"
delay 0.1 "$(bold " / ______/ | / \ / ____/ | / / / ____/ | /___ __/")"
delay 0.1 "$(bold " /______ | | / _ \ | | / | | | | | | ")"
delay 0.1 "$(bold " ____ / | |___ __ \ |____ |\ \ | |____ |__ _| |___")"
delay 0.1 "$(bold " /_______ /|______/ \_\ ____/_| \__\ _____/______/_____/")"
delay 0.2 ""
# Check if slack binary is already in user's system
if [ -x "$(command -v "$SLACK_CLI_NAME")" ]; then
delay 0.3 "🔍 Checking if \`$SLACK_CLI_NAME\` already exists on this system..."
delay 0.2 "⚠️ Heads up! A binary called \`$SLACK_CLI_NAME\` was found!"
delay 0.3 "🔍 Now checking if it's the same Slack CLI..."
# Check if command is used for Slack CLI, for Slack CLI with version >= 1.18.0, the fingerprint needs to be matched to proceed installation
if [[ ! $($SLACK_CLI_NAME _fingerprint) == "$FINGERPRINT" ]] &>/dev/null; then
# For Slack CLI with version < 1.18.0, we check with `slack --version` for backwards compatibility
if [[ ! $($SLACK_CLI_NAME --version) == *"Using $SLACK_CLI_NAME v"* ]]; then
echo -e "🛑 Error: Your existing \`$SLACK_CLI_NAME\` command is different from this Slack CLI!"
echo -e "🛑 Halting the install to avoid accidentally overwriting it.\n"
echo -e "🔖 Try using an alias when installing to avoid name conflicts:\n"
echo -e "curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s your-preferred-alias"
return 1
fi
else
if [ -z "$SLACK_CLI_VERSION" ]; then
delay 0.3 "🍀 It is the same Slack CLI! Upgrading to the latest version..."
else
delay 0.3 "🍀 It is the same Slack CLI! Switching over to v$SLACK_CLI_VERSION..."
fi
fi
fi
if [ -z "$SLACK_CLI_VERSION" ]; then
#
# Get the latest published Slack CLI release, the latest release is the most recent non-prerelease, non-draft release, sorted by the created_at attribute.
# Using grep and sed to parse the semver (excluding "v" to ensure consistence of binaries' filenames ) instead of jq to avoid extra dependencies requirement
#
echo -e "🔍 Searching for the latest version of the Slack CLI..."
LATEST_SLACK_CLI_VERSION=$(curl --silent "https://docs.slack.dev/tools/metadata.json" | grep -o '"version": "[^"]*' | grep -o '[^"]*$' | head -1)
if [ -z "$LATEST_SLACK_CLI_VERSION" ]; then
echo "🛑 Error: Installer cannot find the latest Slack CLI version!"
echo "🔖 Check the status of https://slack-status.com/ and try again"
return 1
fi
echo -e "💾 Release v$LATEST_SLACK_CLI_VERSION was found! Downloading now..."
SLACK_CLI_VERSION=$LATEST_SLACK_CLI_VERSION
fi
#
# Install Slack CLI
#
if [ "$(uname)" == "Darwin" ]; then
if version_lt "$SLACK_CLI_VERSION" "3.3.0"; then
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_64-bit.tar.gz"
else
case "$(uname -m)" in
x86_64)
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_amd64.tar.gz"
;;
arm64 | aarch64)
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_arm64.tar.gz"
;;
*)
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_64-bit.tar.gz"
;;
esac
fi
elif [ "$(expr substr "$(uname -s)" 1 5)" == "Linux" ]; then
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_linux_64-bit.tar.gz"
else
echo "🛑 Error: This installer is only supported on Linux and macOS"
echo "🔖 Try using a different installation method:"
echo "🔗 https://docs.slack.dev/tools/slack-cli"
return 1
fi
slack_cli_install_dir="$HOME/.slack"
slack_cli_install_bin_dir="$slack_cli_install_dir/bin"
slack_cli_bin_path="$slack_cli_install_bin_dir/slack"
if [ ! -d "$slack_cli_install_dir" ]; then
mkdir -p "$slack_cli_install_dir"
fi
echo -e "\x1b[2m\n$slack_cli_url"
curl -# -fLo "$slack_cli_install_dir/slack-cli.tar.gz" "$slack_cli_url"
echo -e "\x1b[0m"
delay 0.2 "💾 Successfully downloaded Slack CLI v$LATEST_SLACK_CLI_VERSION to $(home_path "$slack_cli_install_dir/slack-cli.tar.gz")"
delay 0.3 "📦 Extracting the Slack CLI command binary to $(home_path "$slack_cli_bin_path")"
tar -xf "$slack_cli_install_dir/slack-cli.tar.gz" -C "$slack_cli_install_dir"
chmod +x "$slack_cli_bin_path"
delay 0.1 "📠 Removing packaged download files from $(home_path "$slack_cli_install_dir/slack-cli.tar.gz")"
rm "$slack_cli_install_dir/slack-cli.tar.gz"
if [ -d "/usr/local/bin" ] && [ -w "/usr/local/bin" ]; then
local_bin_path="/usr/local/bin"
else
local_bin_path="$HOME/.local/bin"
mkdir -p "$local_bin_path"
fi
delay 0.1 "🔗 Adding a symbolic link from $(home_path "$local_bin_path/$SLACK_CLI_NAME") to $(home_path "$slack_cli_bin_path")"
ln -sf "$slack_cli_bin_path" "$local_bin_path/$SLACK_CLI_NAME"
}
terms_of_service() {
echo -e ""
echo -e "📄 Use of the Slack CLI should comply with the Slack API Terms of Service:"
echo -e "🏛️ https://slack.com/terms-of-service/api"
}
feedback_message() {
CODE=$?
echo -e "\x1b[0m"
echo -e "💌 We would love to know how things are going. Really. All of it."
if command -v "$SLACK_CLI_NAME" >/dev/null 2>&1; then
echo -e "✨ Survey your development experience with \`$SLACK_CLI_NAME feedback\`"
else
echo -e "✨ Submit installation issues: https://github.com/slackapi/slack-cli/issues"
fi
if [ $CODE -ne 0 ]; then
exit $CODE
fi
}
next_step_message() {
echo -e ""
if command -v "$SLACK_CLI_NAME" >/dev/null 2>&1; then
echo -e "📺 Success! The Slack CLI is now installed!"
else
echo -e "📚 Required manual setup"
echo -e "📝 Run the following commands to add the Slack CLI to your shell path:"
case "$(basename "$SHELL")" in
bash)
echo -e "$(bold " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc")"
echo -e "$(bold " source ~/.bashrc")"
;;
fish)
echo -e "$(bold " mkdir -p \$HOME/.config/fish")"
echo -e "$(bold " echo 'fish_add_path \$HOME/.local/bin' >> \$HOME/.config/fish/config.fish")"
echo -e "$(bold " source \$HOME/.config/fish/config.fish")"
;;
zsh)
echo -e "$(bold " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc")"
echo -e "$(bold " source ~/.zshrc")"
;;
*)
echo -e "$(bold " export PATH=\"$local_bin_path:\$PATH\"")"
;;
esac
fi
echo -e "🔐 Next, authorize your CLI in your workspace with \`$(bold "$SLACK_CLI_NAME login")\`"
sleep 0.2
}
main() {
trap 'feedback_message' ERR
set -eE
install_slack_cli "$@"
sleep 0.2
terms_of_service
sleep 0.1
feedback_message
sleep 0.2
next_step_message
}
main "$@"