Skip to content

Commit 4f4d779

Browse files
zimeglukegalbraithrussellmwbrooks
authored
feat: install to $HOME/.local/bin if writes to /usr/local/bin fail (#188)
Co-authored-by: lukegalbraithrussell <31357343+lukegalbraithrussell@users.noreply.github.com> Co-authored-by: Michael Brooks <mbrooks@slack-corp.com>
1 parent ff22405 commit 4f4d779

File tree

4 files changed

+113
-61
lines changed

4 files changed

+113
-61
lines changed

docs/guides/installing-the-slack-cli-for-mac-and-linux.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Runtime installations are left to the developer and depend on the app being buil
2525
- [Deno Slack SDK](/tools/deno-slack-sdk/guides/getting-started)
2626

2727
<details>
28-
<summary>Optional: Use an alias for the Slack CLI binary</summary>
28+
<summary>Optional: use an alias for the Slack CLI binary</summary>
2929

3030
If you have another CLI tool in your path called `slack`, you can rename this `slack` binary to a different name to avoid errors during installation. The Slack CLI won't overwrite the existing one!
3131

@@ -44,7 +44,7 @@ curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s -- -v
4444
</details>
4545

4646
<details>
47-
<summary>Optional: Download a specific version</summary>
47+
<summary>Optional: download a specific version</summary>
4848

4949
The latest Slack CLI version is installed by default, but a particular version can be pinned using the `-v` flag:
5050

@@ -55,21 +55,39 @@ curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s -- -v
5555
</details>
5656

5757
<details>
58-
<summary>Troubleshooting: Failed to create a symbolic link</summary>
58+
<summary>Troubleshooting: command not found</summary>
5959

60-
The automated installer attempts to add the Slack CLI to a known directory in the path: `/usr/local/bin`.
60+
After running the Slack CLI installation script the `slack` command might not be available in the current shell. The download has often succeeded but a symbolic link to the command needs to be added to your path.
6161

62-
Some machines protect this directory and elevated access might be needed for updated permissions. We do not recommend using `sudo` with the automated installer since unexpected side effects might place downloads in the wrong spot.
63-
64-
If root access is available, create a symbolic link to the downloaded Slack CLI with the following command:
62+
Determine which shell you're using then update your shell profile with the following commands:
6563

6664
```sh
67-
sudo ln -s "$HOME/.slack/bin/slack" "/usr/local/bin/slack"
65+
basename "$SHELL"
6866
```
6967

70-
We recommend using an alias if another `slack` binary exists. To do this, change the alias used at the end of the symbolic link to something else that makes sense.
68+
- `bash`:
69+
70+
```sh
71+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
72+
source ~/.bashrc
73+
```
74+
75+
- `fish`:
76+
77+
```sh
78+
mkdir -p $HOME/.config/fish
79+
echo 'fish_add_path $HOME/.local/bin' >> $HOME/.config/fish/config.fish
80+
source $HOME/.config/fish/config.fish
81+
```
82+
83+
- `zsh`:
84+
85+
```sh
86+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
87+
source ~/.zshrc
88+
```
7189

72-
For users without root permissions, please follow the **Manual Installation** steps.
90+
Once the profile is sourced, or a new shell is opened, the `slack` command should be available.
7391

7492
</details>
7593
</TabItem>
@@ -97,7 +115,7 @@ In the following example we download the Slack CLI to the `.slack` directory and
97115
ln -s "$HOME/.slack/bin/slack" "$HOME/.local/bin/slack"
98116
```
99117

100-
We recommend using an alias if another `slack` binary exists. To do this, change the alias used at the end of the symbolic link to something else that makes sense.
118+
We recommend using an alias if another `slack` binary exists. To do this, change the alias used at the end of the symbolic link to something else that makes sense, or rename the moved download to something special.
101119

102120
**4\. Verify that** `slack` **is installed and in your path.**
103121

docs/guides/installing-the-slack-cli-for-windows.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Runtime installations are left to the developer and depend on the app being buil
2929
- [Deno Slack SDK](/tools/deno-slack-sdk/guides/getting-started)
3030

3131
<details>
32-
<summary>Optional: Use an alias for the Slack CLI binary</summary>
32+
<summary>Optional: use an alias for the Slack CLI binary</summary>
3333

3434
If you have another CLI tool in your path called `slack`, you can rename this `slack` binary to a different name to avoid errors during installation. The Slack CLI won't overwrite the existing one!
3535

@@ -38,7 +38,7 @@ To do this, use the `-Alias` flag as described within the **Optional: Customize
3838
</details>
3939

4040
<details>
41-
<summary>Optional: Customize installation using flags</summary>
41+
<summary>Optional: customize installation using flags</summary>
4242

4343
There are several flags available to customize the installation. Since flags cannot be passed to remote scripts, you must first download the automated installer to a local file:
4444

scripts/install-dev.sh

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ if [ $(($# - $OPTIND)) -lt 1 ]; then
4343
fi
4444
fi
4545

46+
# Emphasize text in a string
47+
bold() {
48+
echo -en "\x1b[1m$1\x1b[0m"
49+
}
50+
4651
# Print a message then pause for an amount of time
4752
delay() {
4853
local options="-e"
@@ -53,7 +58,7 @@ delay() {
5358
fi
5459

5560
echo $options "$2"
56-
sleep $1
61+
sleep "$1"
5762
}
5863

5964
# Replace /home/username/folder/file with ~/folder/file
@@ -72,12 +77,12 @@ version_lt() {
7277
install_slack_cli() {
7378
delay 0.6 "🥁 Hello and welcome! Now beginning to install the..."
7479

75-
delay 0.1 "\x1b[1m ________ _ _ _____ _ __ _____ _ ________\x1b[0m"
76-
delay 0.1 "\x1b[1m / ______/ | / \ / ____/ | / / / ____/ | /___ __/\x1b[0m"
77-
delay 0.1 "\x1b[1m /______ | | / _ \ | | / | | | | | | \x1b[0m"
78-
delay 0.1 "\x1b[1m ____ / | |___ __ \ |____ |\ \ | |____ |__ _| |___\x1b[0m"
79-
delay 0.1 "\x1b[1m /_______ /|______/ \_\ ____/_| \__\ _____/______/_____/\x1b[0m"
80-
delay 0.2 "\x1b[0m"
80+
delay 0.1 "$(bold " ________ _ _ _____ _ __ _____ _ ________")"
81+
delay 0.1 "$(bold " / ______/ | / \ / ____/ | / / / ____/ | /___ __/")"
82+
delay 0.1 "$(bold " /______ | | / _ \ | | / | | | | | | ")"
83+
delay 0.1 "$(bold " ____ / | |___ __ \ |____ |\ \ | |____ |__ _| |___")"
84+
delay 0.1 "$(bold " /_______ /|______/ \_\ ____/_| \__\ _____/______/_____/")"
85+
delay 0.2 ""
8186

8287
sleep 0.6
8388

@@ -171,24 +176,14 @@ install_slack_cli() {
171176
delay 0.1 "📠 Removing packaged download files from $(home_path "$slack_cli_install_dir/slack-cli.tar.gz")"
172177
rm "$slack_cli_install_dir/slack-cli.tar.gz"
173178

174-
delay 0.1 "🔗 Adding a symbolic link from /usr/local/bin/$SLACK_CLI_NAME to $(home_path "$slack_cli_bin_path")"
175-
if [ ! -d /usr/local/bin ]; then
176-
echo -e "⚠️ The /usr/local/bin directory does not exist!"
177-
echo -e "🔐 Please create /usr/local/bin directory first and try again..."
178-
return 1
179-
fi
180-
if [ -w /usr/local/bin ]; then
181-
ln -sf "$slack_cli_bin_path" "/usr/local/bin/$SLACK_CLI_NAME"
179+
if [ -d "/usr/local/bin" ] && [ -w "/usr/local/bin" ]; then
180+
local_bin_path="/usr/local/bin"
182181
else
183-
echo -e "⚠️ Failed to create a symbolic link!"
184-
delay 0.1 "🔖 The installer doesn't have write access to /usr/local/bin"
185-
echo -e "🔐 Please check permission and try again..."
186-
return 1
187-
fi
188-
if ! command -v "$SLACK_CLI_NAME" >/dev/null 2>&1; then
189-
echo "📁 Manually add the Slack CLI command directory to your shell profile"
190-
echo " export PATH=\"$slack_cli_install_bin_dir:\$PATH\""
182+
local_bin_path="$HOME/.local/bin"
183+
mkdir -p "$local_bin_path"
191184
fi
185+
delay 0.1 "🔗 Adding a symbolic link from $(home_path "$local_bin_path/$SLACK_CLI_NAME") to $(home_path "$slack_cli_bin_path")"
186+
ln -sf "$slack_cli_bin_path" "$local_bin_path/$SLACK_CLI_NAME"
192187
}
193188

194189
terms_of_service() {
@@ -215,8 +210,30 @@ next_step_message() {
215210
echo -e ""
216211
if command -v "$SLACK_CLI_NAME" >/dev/null 2>&1; then
217212
echo -e "📺 Success! The Slack CLI (build: $SLACK_CLI_DEV_VERSION) is now installed!"
218-
echo -e "🔐 Next, authorize your CLI in your workspace with \`$SLACK_CLI_NAME login\`"
213+
else
214+
echo -e "📚 Required manual setup"
215+
echo -e "📝 Run the following commands to add the Slack CLI to your shell path:"
216+
case "$(basename "$SHELL")" in
217+
bash)
218+
echo -e "$(bold " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc")"
219+
echo -e "$(bold " source ~/.bashrc")"
220+
;;
221+
fish)
222+
echo -e "$(bold " mkdir -p \$HOME/.config/fish")"
223+
echo -e "$(bold " echo 'fish_add_path \$HOME/.local/bin' >> \$HOME/.config/fish/config.fish")"
224+
echo -e "$(bold " source \$HOME/.config/fish/config.fish")"
225+
;;
226+
zsh)
227+
echo -e "$(bold " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc")"
228+
echo -e "$(bold " source ~/.zshrc")"
229+
;;
230+
*)
231+
echo -e "$(bold " export PATH=\"$local_bin_path:\$PATH\"")"
232+
;;
233+
esac
219234
fi
235+
echo -e "🔐 Next, authorize your CLI in your workspace with \`$(bold "$SLACK_CLI_NAME login")\`"
236+
sleep 0.2
220237
}
221238

222239
main() {

scripts/install.sh

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ if [ $(($# - $OPTIND)) -lt 1 ]; then
4040
fi
4141
fi
4242

43+
# Emphasize text in a string
44+
bold() {
45+
echo -en "\x1b[1m$1\x1b[0m"
46+
}
47+
4348
# Print a message then pause for an amount of time
4449
delay() {
4550
local options="-e"
@@ -50,7 +55,7 @@ delay() {
5055
fi
5156

5257
echo $options "$2"
53-
sleep $1
58+
sleep "$1"
5459
}
5560

5661
# Replace /home/username/folder/file with ~/folder/file
@@ -69,12 +74,12 @@ version_lt() {
6974
install_slack_cli() {
7075
delay 0.6 "🥁 Hello and welcome! Now beginning to install the..."
7176

72-
delay 0.1 "\x1b[1m ________ _ _ _____ _ __ _____ _ ________\x1b[0m"
73-
delay 0.1 "\x1b[1m / ______/ | / \ / ____/ | / / / ____/ | /___ __/\x1b[0m"
74-
delay 0.1 "\x1b[1m /______ | | / _ \ | | / | | | | | | \x1b[0m"
75-
delay 0.1 "\x1b[1m ____ / | |___ __ \ |____ |\ \ | |____ |__ _| |___\x1b[0m"
76-
delay 0.1 "\x1b[1m /_______ /|______/ \_\ ____/_| \__\ _____/______/_____/\x1b[0m"
77-
delay 0.2 "\x1b[0m"
77+
delay 0.1 "$(bold " ________ _ _ _____ _ __ _____ _ ________")"
78+
delay 0.1 "$(bold " / ______/ | / \ / ____/ | / / / ____/ | /___ __/")"
79+
delay 0.1 "$(bold " /______ | | / _ \ | | / | | | | | | ")"
80+
delay 0.1 "$(bold " ____ / | |___ __ \ |____ |\ \ | |____ |__ _| |___")"
81+
delay 0.1 "$(bold " /_______ /|______/ \_\ ____/_| \__\ _____/______/_____/")"
82+
delay 0.2 ""
7883

7984
# Check if slack binary is already in user's system
8085
if [ -x "$(command -v "$SLACK_CLI_NAME")" ]; then
@@ -169,24 +174,14 @@ install_slack_cli() {
169174
delay 0.1 "📠 Removing packaged download files from $(home_path "$slack_cli_install_dir/slack-cli.tar.gz")"
170175
rm "$slack_cli_install_dir/slack-cli.tar.gz"
171176

172-
delay 0.1 "🔗 Adding a symbolic link from /usr/local/bin/$SLACK_CLI_NAME to $(home_path "$slack_cli_bin_path")"
173-
if [ ! -d /usr/local/bin ]; then
174-
echo -e "⚠️ The /usr/local/bin directory does not exist!"
175-
echo -e "🔐 Please create /usr/local/bin directory first and try again..."
176-
return 1
177-
fi
178-
if [ -w /usr/local/bin ]; then
179-
ln -sf "$slack_cli_bin_path" "/usr/local/bin/$SLACK_CLI_NAME"
177+
if [ -d "/usr/local/bin" ] && [ -w "/usr/local/bin" ]; then
178+
local_bin_path="/usr/local/bin"
180179
else
181-
echo -e "⚠️ Failed to create a symbolic link!"
182-
delay 0.1 "🔖 The installer doesn't have write access to /usr/local/bin"
183-
echo -e "🔐 Please check permission and try again..."
184-
return 1
185-
fi
186-
if ! command -v "$SLACK_CLI_NAME" >/dev/null 2>&1; then
187-
echo "📁 Manually add the Slack CLI command directory to your shell profile"
188-
echo " export PATH=\"$slack_cli_install_bin_dir:\$PATH\""
180+
local_bin_path="$HOME/.local/bin"
181+
mkdir -p "$local_bin_path"
189182
fi
183+
delay 0.1 "🔗 Adding a symbolic link from $(home_path "$local_bin_path/$SLACK_CLI_NAME") to $(home_path "$slack_cli_bin_path")"
184+
ln -sf "$slack_cli_bin_path" "$local_bin_path/$SLACK_CLI_NAME"
190185
}
191186

192187
terms_of_service() {
@@ -213,8 +208,30 @@ next_step_message() {
213208
echo -e ""
214209
if command -v "$SLACK_CLI_NAME" >/dev/null 2>&1; then
215210
echo -e "📺 Success! The Slack CLI is now installed!"
216-
echo -e "🔐 Next, authorize your CLI in your workspace with \`$SLACK_CLI_NAME login\`"
211+
else
212+
echo -e "📚 Required manual setup"
213+
echo -e "📝 Run the following commands to add the Slack CLI to your shell path:"
214+
case "$(basename "$SHELL")" in
215+
bash)
216+
echo -e "$(bold " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc")"
217+
echo -e "$(bold " source ~/.bashrc")"
218+
;;
219+
fish)
220+
echo -e "$(bold " mkdir -p \$HOME/.config/fish")"
221+
echo -e "$(bold " echo 'fish_add_path \$HOME/.local/bin' >> \$HOME/.config/fish/config.fish")"
222+
echo -e "$(bold " source \$HOME/.config/fish/config.fish")"
223+
;;
224+
zsh)
225+
echo -e "$(bold " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc")"
226+
echo -e "$(bold " source ~/.zshrc")"
227+
;;
228+
*)
229+
echo -e "$(bold " export PATH=\"$local_bin_path:\$PATH\"")"
230+
;;
231+
esac
217232
fi
233+
echo -e "🔐 Next, authorize your CLI in your workspace with \`$(bold "$SLACK_CLI_NAME login")\`"
234+
sleep 0.2
218235
}
219236

220237
main() {

0 commit comments

Comments
 (0)