|
3 | 3 | set -eu |
4 | 4 | IFS=$(printf '\n\t') |
5 | 5 |
|
| 6 | +exists() { |
| 7 | + command -v "$1" >/dev/null 2>&1 |
| 8 | +} |
| 9 | + |
6 | 10 | COLORS_SUPPORTED=false |
7 | | -if command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then |
| 11 | +if exists tput && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then |
8 | 12 | COLORS_SUPPORTED=true |
9 | 13 | fi |
10 | 14 |
|
@@ -44,16 +48,6 @@ renderCommand() { |
44 | 48 | # Constants |
45 | 49 | ASTRA_CLI_VERSION="1.0.1" |
46 | 50 |
|
47 | | -get_astra_dir() { |
48 | | - if [ -n "${ASTRA_HOME:-}" ]; then |
49 | | - echo "$ASTRA_HOME/cli" |
50 | | - elif [ -n "${XDG_DATA_HOME:-}" ]; then |
51 | | - echo "$XDG_DATA_HOME/astra/cli" |
52 | | - else |
53 | | - echo "$HOME/.astra/cli" |
54 | | - fi |
55 | | -} |
56 | | - |
57 | 51 | if [ -n "${ASTRA_HOME:-}" ]; then |
58 | 52 | ASTRA_CLI_DIR_RESOLVER="custom" |
59 | 53 | ASTRA_CLI_DIR="$ASTRA_HOME/cli" |
@@ -98,11 +92,11 @@ echo " Installer: $ASTRA_CLI_VERSION" |
98 | 92 | echo "$RESET" |
99 | 93 |
|
100 | 94 | # Required tools check |
101 | | -if ! command -v curl >/dev/null 2>&1; then |
| 95 | +if ! exists curl; then |
102 | 96 | error "Error: curl is not installed. Please install curl and try again." |
103 | 97 | fi |
104 | 98 |
|
105 | | -if ! command -v tar >/dev/null 2>&1; then |
| 99 | +if ! exists tar; then |
106 | 100 | error "Error: tar is not installed. Please install tar and try again." |
107 | 101 | fi |
108 | 102 |
|
@@ -190,7 +184,7 @@ mk_print_next_steps_str() { |
190 | 184 | echo "$1" |
191 | 185 | echo "" |
192 | 186 |
|
193 | | - if [ $os = "macos" ] && command -v xattr >/dev/null 2>&1 && xattr -l "$EXE_PATH" | grep -q "com.apple.quarantine"; then |
| 187 | + if [ $os = "macos" ] && exists xattr && xattr -l "$EXE_PATH" | grep -q "com.apple.quarantine"; then |
194 | 188 | renderComment "Run the following to remove the quarantine label from the binary" |
195 | 189 | renderCommand "xattr -d com.apple.quarantine \"$(tildify "$EXE_PATH")\"" |
196 | 190 | echo "" |
@@ -243,21 +237,82 @@ print_append_to_shell_profile() { |
243 | 237 | echo "" |
244 | 238 | } |
245 | 239 |
|
246 | | -# Existing installation checks |
247 | | -existing_install_path=$(command -v astra 2>/dev/null || { [ -f "$ASTRA_CLI_DIR/astra" ] && echo "$ASTRA_CLI_DIR/astra"; } || { [ -f "${ASTRA_DIR:-}/astra" ] && echo "$ASTRA_DIR/astra"; } || echo "") |
| 240 | +# Resolve any existing installations |
| 241 | +if exists brew; then |
| 242 | + brew_prefix=$(brew --prefix 2>/dev/null || echo "") |
248 | 243 |
|
249 | | -if [ -f "$existing_install_path" ]; then |
250 | | - echo "" |
251 | | - echo "${RED}Error: An existing astra installation was already found.${RESET}" |
252 | | - echo "" |
253 | | - echo "An existing installation was found at $(underline "$(tildify "$existing_install_path")")." |
| 244 | + if [ -n "$brew_prefix" ] && [ -f "$brew_prefix/bin/astra" ]; then |
| 245 | + existing_install_path="$brew_prefix/bin/astra" |
| 246 | + existing_package_manager="homebrew" |
| 247 | + return |
| 248 | + fi |
| 249 | +fi |
| 250 | + |
| 251 | +if exists astra; then |
| 252 | + existing_install_path=$(command -v astra) |
| 253 | +elif [ -f "$ASTRA_CLI_DIR/astra" ]; then |
| 254 | + existing_install_path="$ASTRA_CLI_DIR/astra" |
| 255 | +elif [ -f "${ASTRA_DIR:-}/astra" ]; then |
| 256 | + existing_install_path="$ASTRA_DIR/astra" |
| 257 | +fi |
| 258 | + |
| 259 | +print_basic_0_x_removal_instructions() { |
| 260 | + echo "To remove the existing Astra CLI binary (but preserve other Astra files), please do the following:" |
| 261 | + echo "${BLUE}→ ${LIGHT_GRAY}rm -f $(tildify "$existing_install_path")${RESET}" |
| 262 | +} |
| 263 | + |
| 264 | +print_brew_0_x_removal_instructions() { |
| 265 | + echo "To remove the existing Astra CLI binary (but preserve other Astra files), please do the following:" |
| 266 | + echo "${BLUE}→ ${LIGHT_GRAY}brew uninstall datastax/astra-cli/astra-cli${RESET}" |
| 267 | +} |
| 268 | + |
| 269 | +print_basic_1_x_removal_instructions() { |
| 270 | + echo "Prefer to use ${BLUE}astra upgrade${RESET} to automatically update to the latest version." |
254 | 271 | echo "" |
| 272 | + echo "Otherwise, to remove the existing Astra CLI binary (but preserve other Astra files), please do the following:" |
| 273 | + echo "${BLUE}→ ${LIGHT_GRAY}rm -f $(tildify "$existing_install_path")${RESET}" |
| 274 | +} |
| 275 | + |
| 276 | +print_brew_1_x_removal_instructions() { |
| 277 | + echo "To remove the existing Astra CLI binary (but preserve other Astra files), please do the following:" |
| 278 | + echo "${BLUE}→ ${LIGHT_GRAY}brew uninstall astra${RESET}" |
| 279 | +} |
| 280 | + |
| 281 | +print_generic_removal_instructions() { |
255 | 282 | echo "If you want to update the existing installation, please do one of the following:" |
256 | 283 | echo "${BLUE}→ ${LIGHT_GRAY}(< astra-cli 1.x)${RESET} Remove the existing installation manually and re-run this installer." |
257 | 284 | echo "${BLUE}→ ${LIGHT_GRAY}(> astra-cli 1.x)${RESET} Run ${BLUE}astra upgrade${RESET} to automatically update to the latest version." |
258 | 285 | echo "${BLUE}→ ${LIGHT_GRAY}(> astra-cli 1.x)${RESET} Run ${BLUE}astra nuke${RESET} to completely remove the CLI and then re-run this installer." |
| 286 | +} |
| 287 | + |
| 288 | +if [ -f "${existing_install_path:-}" ]; then |
| 289 | + echo "" |
| 290 | + echo "${RED}Error: An existing astra installation was already found.${RESET}" |
| 291 | + echo "" |
| 292 | + echo "An existing installation was found at $(underline "$(tildify "$existing_install_path")")." |
| 293 | + echo "" |
| 294 | + |
| 295 | + case "$("$existing_install_path" --version 2>/dev/null | cut -d. -f1)" in |
| 296 | + *0) |
| 297 | + if [ "$existing_package_manager" = "homebrew" ]; then |
| 298 | + print_brew_0_x_removal_instructions |
| 299 | + else |
| 300 | + print_basic_0_x_removal_instructions |
| 301 | + fi |
| 302 | + ;; |
| 303 | + *1) |
| 304 | + if [ "$existing_package_manager" = "homebrew" ]; then |
| 305 | + print_brew_1_x_removal_instructions |
| 306 | + else |
| 307 | + print_basic_1_x_removal_instructions |
| 308 | + fi |
| 309 | + ;; |
| 310 | + *) |
| 311 | + print_generic_removal_instructions |
| 312 | + ;; |
| 313 | + esac |
259 | 314 |
|
260 | | - if command -v astra >/dev/null 2>&1; then |
| 315 | + if ! exists astra; then |
261 | 316 | echo "" |
262 | 317 | print_next_steps "If you just can't use ${BLUE}astra${RESET}, ensure you've done the following:" |
263 | 318 | fi |
|
0 commit comments