Skip to content

Commit 2c74b17

Browse files
committed
update installation script to be more portable with colors
1 parent a30d7f5 commit 2c74b17

File tree

5 files changed

+35
-112
lines changed

5 files changed

+35
-112
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ jobs:
3434
"src/test/resources/snapshots/AstraCli/help_output.human.approved.txt"
3535
)
3636
37+
tag="${{ inputs.tag }}"
38+
3739
missing_files=()
3840
for f in "${files[@]}"; do
39-
if ! grep -q "${{ inputs.tag }}" "$f"; then
41+
if ! grep -q "${tag#v}" "$f"; then
4042
missing_files+=("$f")
4143
fi
4244
done

.idea/inspectionProfiles/Project_Default.xml

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

.idea/workspace.xml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/install.sh

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

6-
# Utilities
6+
color() {
7+
if command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
8+
tput "$@"
9+
else
10+
printf ""
11+
fi
12+
}
13+
714
error() {
815
printf "${RED}%s${RESET}\n" "$(printf "$1")" # `printf $1` to preserve newlines
916
exit 1
@@ -14,7 +21,7 @@ checklist() {
1421
}
1522

1623
underline(){
17-
printf "$(tput smul)%s$(tput rmul)" "$(printf "$1")"
24+
printf "$(color smul)%s$(color rmul)" "$(printf "$1")"
1825
}
1926

2027
tildify() {
@@ -47,21 +54,21 @@ EXE_PATH="$ASTRA_CLI_DIR/astra"
4754
TAR_PATH="$ASTRA_CLI_DIR/astra.tar.gz"
4855

4956
# Colors
50-
if false; then
51-
LIGHT_GRAY=$(tput setaf 245)
52-
BLUE=$(tput setaf 110)
53-
PURPLE=$(tput setaf 134)
54-
RED=$(tput setaf 167)
55-
GREEN=$(tput setaf 76)
57+
if [ "$(color colors)" -ge 256 ]; then
58+
LIGHT_GRAY=$(color setaf 245)
59+
BLUE=$(color setaf 110)
60+
PURPLE=$(color setaf 134)
61+
RED=$(color setaf 167)
62+
GREEN=$(color setaf 76)
5663
else
57-
LIGHT_GRAY=$(tput setaf 7)
58-
BLUE=$(tput setaf 6)
59-
PURPLE=$(tput setaf 5)
60-
RED=$(tput setaf 1)
61-
GREEN=$(tput setaf 2)
64+
LIGHT_GRAY=$(color setaf 7)
65+
BLUE=$(color setaf 6)
66+
PURPLE=$(color setaf 5)
67+
RED=$(color setaf 1)
68+
GREEN=$(color setaf 2)
6269
fi
6370

64-
RESET=$(tput sgr0)
71+
RESET=$(color sgr0)
6572

6673
# Prelude
6774
echo "$PURPLE"
@@ -75,25 +82,6 @@ echo ""
7582
echo " Installer: $ASTRA_CLI_VERSION"
7683
echo "$RESET"
7784

78-
# Options
79-
AUTO_YES_INSTALL=0
80-
81-
if [ -t 0 ]; then
82-
if [ "${1:-}" = "--yes" ] || [ "${1:-}" = "-y" ]; then
83-
AUTO_YES_INSTALL=1
84-
fi
85-
else
86-
echo "${RED}Error: Script is running in a non-interactive terminal${RESET}"
87-
echo ""
88-
echo "Please use the following command instead to run the script interactively:"
89-
echo ""
90-
renderCommand "sh -c \"\$(curl -fsSL \"https://raw.githubusercontent.com/datastax/astra-cli/main/scripts/install.sh\")\""
91-
echo ""
92-
echo "If you really want to run this script in a non-interactively, pass the ${BLUE}--yes${RESET} flag to accept installing astra in the following location:"
93-
echo "${BLUE}>${RESET} $(underline "$(tildify "$ASTRA_CLI_DIR/")")"
94-
exit 1
95-
fi
96-
9785
# Required tools check
9886
if ! command -v curl >/dev/null 2>&1; then
9987
error "Error: curl is not installed. Please install curl and try again."
@@ -168,36 +156,6 @@ else
168156
checklist "No existing installation found."
169157
fi
170158

171-
# Verify installation path
172-
echo ""
173-
echo "${GREEN}Ready to install Astra CLI ✅${RESET}"
174-
echo ""
175-
echo "Do you want to install Astra CLI to $(underline "$(tildify "$ASTRA_CLI_DIR/")")? ${BLUE}[Y]es/[d]ifferent path/[c]ancel${RESET}"
176-
177-
while [ "$AUTO_YES_INSTALL" = 0 ]; do
178-
printf "%s" "${BLUE}> ${RESET}"
179-
read -r res
180-
181-
case ${res:-y} in
182-
[Yy]* )
183-
for _ in $(seq 1 5); do tput cuu1 && tput el; done
184-
break;;
185-
[Dd]*)
186-
echo ""
187-
echo "${RED}To use a custom installation path, please globally set the ASTRA_HOME environment variable.${RESET}"
188-
echo ""
189-
echo "This variable $(tput bold)must remain in place forever${RESET} (e.g. in your shell profile like $(underline "~/.zprofile"), $(underline "~/.bash_profile"), etc.) so that the CLI can always locate its home directory."
190-
echo ""
191-
echo "After setting it, restart your terminal or run 'source ~/.zprofile' (or the appropriate file) to apply the change."
192-
exit 1
193-
;;
194-
[Cc]* )
195-
error "\nCancelling installation.";;
196-
* )
197-
echo "Please answer ${BLUE}yes${RESET}, ${BLUE}no${RESET}, or ${BLUE}cancel${RESET}.";;
198-
esac
199-
done
200-
201159
# Create installation directory
202160
if mkdir -p "$ASTRA_CLI_DIR"; then
203161
checklist "Using installation dir $(underline "$(tildify "$ASTRA_CLI_DIR/")")${RESET}${LIGHT_GRAY}."
@@ -210,7 +168,7 @@ echo ""
210168
echo "Downloading archive..."
211169

212170
if curl -fL --progress-bar "$install_url" > "$TAR_PATH"; then
213-
for _ in $(seq 1 3); do tput cuu1 && tput el; done
171+
for _ in $(seq 1 3); do color cuu1 && color el; done
214172
checklist "Archive downloaded."
215173
else
216174
rm "$TAR_PATH" 2>/dev/null || true

src/main/java/com/dtsx/astra/cli/utils/FileUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ public Optional<Path> getCurrentBinaryPath() {
3434
return ProcessHandle.current().info().command()
3535
.filter((_) -> ImageInfo.inImageCode())
3636
.map(Path::of)
37-
.map(FileUtils::toRealPath);
37+
.map((p) -> {
38+
try {
39+
return p.toRealPath();
40+
} catch (IOException e) {
41+
return p.toAbsolutePath();
42+
}
43+
});
3844
}
3945

4046
public Path toRealPath(Path path) {

0 commit comments

Comments
 (0)