Skip to content

Commit a3d18f5

Browse files
committed
install script update to make handling existing installation clearer
1 parent fa15446 commit a3d18f5

File tree

6 files changed

+82
-24
lines changed

6 files changed

+82
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ bin/
5151
/*fake*
5252
/.env
5353
/.direnv
54+
/.bob

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/install.sh

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
set -eu
44
IFS=$(printf '\n\t')
55

6+
exists() {
7+
command -v "$1" >/dev/null 2>&1
8+
}
9+
610
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
812
COLORS_SUPPORTED=true
913
fi
1014

@@ -44,16 +48,6 @@ renderCommand() {
4448
# Constants
4549
ASTRA_CLI_VERSION="1.0.1"
4650

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-
5751
if [ -n "${ASTRA_HOME:-}" ]; then
5852
ASTRA_CLI_DIR_RESOLVER="custom"
5953
ASTRA_CLI_DIR="$ASTRA_HOME/cli"
@@ -98,11 +92,11 @@ echo " Installer: $ASTRA_CLI_VERSION"
9892
echo "$RESET"
9993

10094
# Required tools check
101-
if ! command -v curl >/dev/null 2>&1; then
95+
if ! exists curl; then
10296
error "Error: curl is not installed. Please install curl and try again."
10397
fi
10498

105-
if ! command -v tar >/dev/null 2>&1; then
99+
if ! exists tar; then
106100
error "Error: tar is not installed. Please install tar and try again."
107101
fi
108102

@@ -190,7 +184,7 @@ mk_print_next_steps_str() {
190184
echo "$1"
191185
echo ""
192186

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
194188
renderComment "Run the following to remove the quarantine label from the binary"
195189
renderCommand "xattr -d com.apple.quarantine \"$(tildify "$EXE_PATH")\""
196190
echo ""
@@ -243,21 +237,82 @@ print_append_to_shell_profile() {
243237
echo ""
244238
}
245239

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 "")
248243

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."
254271
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() {
255282
echo "If you want to update the existing installation, please do one of the following:"
256283
echo "${BLUE}${LIGHT_GRAY}(< astra-cli 1.x)${RESET} Remove the existing installation manually and re-run this installer."
257284
echo "${BLUE}${LIGHT_GRAY}(> astra-cli 1.x)${RESET} Run ${BLUE}astra upgrade${RESET} to automatically update to the latest version."
258285
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
259314

260-
if command -v astra >/dev/null 2>&1; then
315+
if ! exists astra; then
261316
echo ""
262317
print_next_steps "If you just can't use ${BLUE}astra${RESET}, ensure you've done the following:"
263318
fi

src/main/java/com/dtsx/astra/cli/commands/CompletionsCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private int appendUtilityFunctions(String[] lines, StringBuilder sb, int i) {
7575

7676
val props = CliPropertiesImpl.mkAndLoadSysProps(new CliEnvironmentImpl());
7777

78+
// TODO should check for -p as well
7879
sb.append("""
7980
get_profile(){ for ((i=0;i<${#COMP_WORDS[@]};i++));do [[ ${COMP_WORDS[i]} == --profile ]]&&((i+1<${#COMP_WORDS[@]}))&&echo ${COMP_WORDS[i+1]}&&return;done; echo default;};
8081
""").append(NL);

src/main/java/com/dtsx/astra/cli/commands/db/cqlsh/CqlshStartImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private String readStdin() {
8686

8787
while ((line = reader.readLine()) != null) {
8888
if (line.trim().endsWith("\\")) {
89-
sb.append(line, 0, line.lastIndexOf('\\') - 1);
89+
sb.append(line, 0, line.lastIndexOf('\\') - 1); // TODO this should not be -1
9090
sb.append(NL);
9191
} else {
9292
sb.append(line);

src/main/java/com/dtsx/astra/cli/operations/SetupOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public SetupResult execute() {
8787

8888
if (shouldSetDefault) {
8989
ctx.deleteProfile(ProfileName.DEFAULT);
90-
ctx.createProfile(ProfileName.DEFAULT, details.token, details.env);
90+
ctx.createProfile(ProfileName.DEFAULT, details.token, details.env); // TODO needs source!!!
9191
}
9292
});
9393

0 commit comments

Comments
 (0)