diff --git a/scripts/install-dev.sh b/scripts/install-dev.sh index e15e6e0b..19d4e4dd 100755 --- a/scripts/install-dev.sh +++ b/scripts/install-dev.sh @@ -31,7 +31,7 @@ while getopts "v:d" flag; do SLACK_CLI_DEV_VERSION=$OPTARG else echo "Slack CLI requires a valid semver version number." >&2 - exit 1 + return 1 fi ;; d) @@ -102,8 +102,8 @@ install_slack_cli() { 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\n" - exit 1 + echo -e "curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s your-preferred-alias" + return 1 fi else if [ "$SLACK_CLI_DEV_VERSION" == "dev" ]; then @@ -140,7 +140,7 @@ install_slack_cli() { echo "šŸ›‘ Error: This installer is only supported on Linux and macOS" echo "šŸ”– Try using a different installation method:" echo "šŸ”— https://tools.slack.dev/slack-cli" - exit 1 + return 1 fi slack_cli_install_dir="$HOME/.slack/dev-build" @@ -169,15 +169,15 @@ install_slack_cli() { if [ ! -d /usr/local/bin ]; then echo -e "āš ļø The /usr/local/bin directory does not exist!" echo -e "šŸ” Please create /usr/local/bin directory first and try again..." - exit 1 + return 1 fi if [ -w /usr/local/bin ]; then ln -sf "$slack_cli_bin_path" "/usr/local/bin/$SLACK_CLI_NAME" else echo -e "āš ļø Failed to create a symbolic link!" delay 0.1 "šŸ”– The installer doesn't have write access to /usr/local/bin" - echo -e "šŸ” Please check the permission and try again..." - exit 1 + echo -e "šŸ” Please check permission and try again..." + return 1 fi if [ $(command -v $SLACK_CLI_NAME) ]; then @@ -272,7 +272,7 @@ maybe_update_deno_version() { [Yy]*) deno upgrade --version $MIN_DENO_VERSION ;; *) echo "Please upgrade deno manually to at least $MIN_DENO_VERSION and re-run this script." - exit + return ;; esac ;; @@ -323,7 +323,7 @@ install_deno() { ln -sf "$deno_path" /usr/local/bin/deno else echo -e "Installer doesn't have write access to /usr/local/bin to create a symbolic link. Please check permission and try again" - exit 1 + return 1 fi fi fi @@ -349,9 +349,15 @@ install_deno_vscode_extension() { } feedback_message() { - if [ $(command -v $SLACK_CLI_NAME) ]; then + CODE=$? + if [ $CODE -eq 0 ] && [ $(command -v $SLACK_CLI_NAME) ]; then echo -e "\nšŸ’Œ We would love to know how things are going. Really. All of it." echo -e " Survey your development experience with \`$SLACK_CLI_NAME feedback\`" + else + echo -e "\x1b[0m" + echo -e "šŸ’Œ We would love to know how things are going. Really. All of it." + echo -e " Submit installation issues: https://github.com/slackapi/slack-cli/issues" + exit $CODE fi } @@ -369,8 +375,11 @@ next_step_message() { } main() { - set -e + trap 'feedback_message' ERR + + set -eE install_slack_cli "$@" + sleep 0.1 install_deno diff --git a/scripts/install-windows-dev.ps1 b/scripts/install-windows-dev.ps1 index c2ecd047..e29d9c46 100644 --- a/scripts/install-windows-dev.ps1 +++ b/scripts/install-windows-dev.ps1 @@ -70,7 +70,7 @@ function check_slack_binary_exist() { Write-Host "`nTry using an alias when installing to avoid name conflicts:" Write-Host "`nirm https://downloads.slack-edge.com/slack-cli/install-windows.ps1 -Alias your-preferred-alias | iex" - Exit; + throw } } $message = "It is the same Slack CLI! Upgrading to the latest version..." @@ -116,7 +116,8 @@ function install_slack_cli { } } catch { - throw "`nInstaller cannot find latest Slack CLI release version" + Write-Error "Installer cannot find latest Slack CLI release version" + throw } $slack_cli_dir = "${Home}\AppData\Local\slack-cli" @@ -133,14 +134,16 @@ function install_slack_cli { $slack_cli_dir = $alternative_slack_cli_dir } catch { - throw "`nInstaller cannot create folder in $($alternative_slack_cli_dir). `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + Write-Error "Installer cannot create folder in $($alternative_slack_cli_dir). `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + throw } } } } } catch { - throw "`nInstaller cannot create folder for Slack CLI, `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + Write-Error "Installer cannot create folder for Slack CLI, `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + throw } if ($Version -eq "dev") { @@ -153,7 +156,8 @@ function install_slack_cli { Invoke-WebRequest -Uri "https://downloads.slack-edge.com/slack-cli/slack_cli_$($SLACK_CLI_VERSION)_windows_64-bit.zip" -OutFile "$($slack_cli_dir)\slack_cli.zip" } catch { - throw "`nInstaller cannot download Slack CLI" + Write-Error "Installer cannot download Slack CLI" + throw } $slack_cli_bin_dir = "$($slack_cli_dir)\bin" @@ -243,7 +247,8 @@ function install_deno { Write-Host "Comparing the currently installed Deno version... Found: v$deno_version_local" } else { - throw "Deno is not installed! Please install Deno to at least v$MIN_DENO_VERSION and try again." + Write-Error "Deno is not installed! Please install Deno to at least v$MIN_DENO_VERSION and try again." + throw } if ($deno_version_latest -eq "v$deno_version_local") { @@ -262,7 +267,8 @@ function install_deno { Write-Host "Nice! Your Deno version has been updated and is ready!" } catch { - throw "`nDeno is not installed, please install deno manually to at least $MIN_DENO_VERSION and re-run this script." + Write-Error "Deno is not installed, please install deno manually to at least $MIN_DENO_VERSION and re-run this script." + throw } } else { @@ -280,7 +286,8 @@ function install_deno { Write-Host "Your Deno version is compatible with the Slack CLI!" } catch { - throw "`nDeno is not installed, please install Deno manually to at least $MIN_DENO_VERSION and re-run this script." + Write-Error "Deno is not installed, please install Deno manually to at least $MIN_DENO_VERSION and re-run this script." + throw } } } @@ -339,11 +346,19 @@ function next_step_message { Write-Host " Then, authorize your CLI in your workspace with ``$confirmed_alias login``.`n" } catch { - throw "`nSlack CLI is not installed.`nPlease reach out to feedback@slack.com to share the issues you are facing.`nMeanwhile you can try the manual installation: https://tools.slack.dev/slack-cli.`n" + Write-Error "Slack CLI was not installed." + Write-Host "`nFind help troubleshooting: https://tools.slack.dev/slack-cli" + throw } } } +trap { + Write-Host "`nWe would love to know how things are going. Really. All of it." + Write-Host "Submit installation issues: https://github.com/slackapi/slack-cli/issues" + exit 1 +} + install_slack_cli $Alias $Version install_deno $SkipDeno Write-Host "`nAdding developer tooling for an enhanced experience..." diff --git a/scripts/install-windows.ps1 b/scripts/install-windows.ps1 index 99bea95f..18f28370 100644 --- a/scripts/install-windows.ps1 +++ b/scripts/install-windows.ps1 @@ -67,7 +67,7 @@ function check_slack_binary_exist() { Write-Host "`nTry using an alias when installing to avoid name conflicts:" Write-Host "`nirm https://downloads.slack-edge.com/slack-cli/install-windows.ps1 -Alias your-preferred-alias | iex" - Exit; + throw } } $message = "It is the same Slack CLI! Upgrading to the latest version..." @@ -113,7 +113,8 @@ function install_slack_cli { } } catch { - throw "`nInstaller cannot find latest Slack CLI release version" + Write-Error "Installer cannot find latest Slack CLI release version" + throw } $slack_cli_dir = "${Home}\AppData\Local\slack-cli" @@ -131,20 +132,23 @@ function install_slack_cli { $slack_cli_dir = $alternative_slack_cli_dir } catch { - throw "`nInstaller cannot create folder in $($alternative_slack_cli_dir). `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + Write-Error "Installer cannot create folder in $($alternative_slack_cli_dir). `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + throw } } } } } catch { - throw "`nInstaller cannot create folder for Slack CLI, `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + Write-Error "Installer cannot create folder for Slack CLI, `nPlease manually create $($slack_cli_dir) folder and re-run the installation script" + throw } try { Invoke-WebRequest -Uri "https://downloads.slack-edge.com/slack-cli/slack_cli_$($SLACK_CLI_VERSION)_windows_64-bit.zip" -OutFile "$($slack_cli_dir)\slack_cli.zip" } catch { - throw "`nInstaller cannot download Slack CLI" + Write-Error "Installer cannot download Slack CLI" + throw } $slack_cli_bin_dir = "$($slack_cli_dir)\bin" @@ -234,7 +238,8 @@ function install_deno { Write-Host "Comparing the currently installed Deno version... Found: v$deno_version_local" } else { - throw "Deno is not installed! Please install Deno to at least v$MIN_DENO_VERSION and try again." + Write-Error "Deno is not installed! Please install Deno to at least v$MIN_DENO_VERSION and try again." + throw } if ($deno_version_latest -eq "v$deno_version_local") { @@ -253,7 +258,8 @@ function install_deno { Write-Host "Nice! Your Deno version has been updated and is ready!" } catch { - throw "`nDeno is not installed, please install deno manually to at least $MIN_DENO_VERSION and re-run this script." + Write-Error "Deno is not installed, please install deno manually to at least $MIN_DENO_VERSION and re-run this script." + throw } } else { @@ -271,7 +277,8 @@ function install_deno { Write-Host "Your Deno version is compatible with the Slack CLI!" } catch { - throw "`nDeno is not installed, please install Deno manually to at least $MIN_DENO_VERSION and re-run this script." + Write-Error "Deno is not installed, please install Deno manually to at least $MIN_DENO_VERSION and re-run this script." + throw } } } @@ -330,11 +337,19 @@ function next_step_message { Write-Host " Then, authorize your CLI in your workspace with ``$confirmed_alias login``.`n" } catch { - throw "`nSlack CLI is not installed.`nPlease reach out to feedback@slack.com to share the issues you are facing.`nMeanwhile you can try the manual installation: https://tools.slack.dev/slack-cli`n" + Write-Error "Slack CLI was not installed." + Write-Host "`nFind help troubleshooting: https://tools.slack.dev/slack-cli" + throw } } } +trap { + Write-Host "`nWe would love to know how things are going. Really. All of it." + Write-Host "Submit installation issues: https://github.com/slackapi/slack-cli/issues" + exit 1 +} + install_slack_cli $Alias $Version install_deno $SkipDeno Write-Host "`nAdding developer tooling for an enhanced experience..." diff --git a/scripts/install.sh b/scripts/install.sh index fdd0511f..0e50806a 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -28,7 +28,7 @@ while getopts "v:d" flag; do SLACK_CLI_VERSION=$OPTARG else echo "Slack CLI requires a valid semver version number." >&2 - exit 1 + return 1 fi ;; d) @@ -88,8 +88,8 @@ install_slack_cli() { 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\n" - exit 1 + 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 @@ -110,7 +110,7 @@ install_slack_cli() { 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" - exit 1 + return 1 fi echo -e "šŸ’¾ Release v$LATEST_SLACK_CLI_VERSION was found! Downloading now..." SLACK_CLI_VERSION=$LATEST_SLACK_CLI_VERSION @@ -142,7 +142,7 @@ install_slack_cli() { echo "šŸ›‘ Error: This installer is only supported on Linux and macOS" echo "šŸ”– Try using a different installation method:" echo "šŸ”— https://tools.slack.dev/slack-cli" - exit 1 + return 1 fi slack_cli_install_dir="$HOME/.slack" @@ -167,7 +167,7 @@ install_slack_cli() { if [ ! -d /usr/local/bin ]; then echo -e "āš ļø The /usr/local/bin directory does not exist!" echo -e "šŸ” Please create /usr/local/bin directory first and try again..." - exit 1 + return 1 fi if [ -w /usr/local/bin ]; then ln -sf "$slack_cli_bin_path" "/usr/local/bin/$SLACK_CLI_NAME" @@ -175,7 +175,7 @@ install_slack_cli() { echo -e "āš ļø Failed to create a symbolic link!" delay 0.1 "šŸ”– The installer doesn't have write access to /usr/local/bin" echo -e "šŸ” Please check permission and try again..." - exit 1 + return 1 fi if [ $(command -v $SLACK_CLI_NAME) ]; then @@ -271,7 +271,7 @@ maybe_update_deno_version() { [Yy]*) deno upgrade --version $MIN_DENO_VERSION ;; *) echo "Please upgrade deno manually to at least $MIN_DENO_VERSION and re-run this script." - exit + return ;; esac ;; @@ -322,7 +322,7 @@ install_deno() { ln -sf "$deno_path" /usr/local/bin/deno else echo -e "Installer doesn't have write access to /usr/local/bin to create a symbolic link. Please check permission and try again" - exit 1 + return 1 fi fi fi @@ -348,9 +348,15 @@ install_deno_vscode_extension() { } feedback_message() { - if [ $(command -v $SLACK_CLI_NAME) ]; then + CODE=$? + if [ $CODE -eq 0 ] && [ $(command -v $SLACK_CLI_NAME) ]; then echo -e "\nšŸ’Œ We would love to know how things are going. Really. All of it." echo -e " Survey your development experience with \`$SLACK_CLI_NAME feedback\`" + else + echo -e "\x1b[0m" + echo -e "šŸ’Œ We would love to know how things are going. Really. All of it." + echo -e " Submit installation issues: https://github.com/slackapi/slack-cli/issues" + exit $CODE fi } @@ -368,7 +374,9 @@ next_step_message() { } main() { - set -e + trap 'feedback_message' ERR + + set -eE install_slack_cli "$@" sleep 0.1