33set -eu
44IFS=$( printf ' \n\t' )
55
6+ if command -v tput > /dev/null 2>&1 && [ " $( tput colors 2> /dev/null || echo 0) " -ge 8 ]; then
7+ COLORS_SUPPORTED=true
8+ fi
9+
610color () {
7- if command -v tput > /dev/null 2>&1 && [ " $( tput colors 2> /dev/null || echo 0 ) " -ge 8 ]; then
11+ if [ " $COLORS_SUPPORTED " = true ]; then
812 tput " $@ "
913 else
1014 printf " "
@@ -37,7 +41,7 @@ renderCommand() {
3741}
3842
3943# Constants
40- ASTRA_CLI_VERSION=" 1.0.0 "
44+ ASTRA_CLI_VERSION=" 1.0.1-rc.3 "
4145
4246get_astra_dir () {
4347 if [ -n " ${ASTRA_HOME:- } " ]; then
@@ -126,22 +130,116 @@ install_url="https://github.com/datastax/astra-cli/releases/download/v$ASTRA_CLI
126130
127131# Out of order but shh
128132print_next_steps () {
133+ steps_str=$( mk_print_next_steps_str " $1 " )
134+
135+ if [ " $COLORS_SUPPORTED " = true ]; then
136+ draw_box_around " $steps_str "
137+ else
138+ printf ' %s\n' " $steps_str "
139+ fi
140+ }
141+
142+ draw_box_around () {
143+ max_width=0
144+ while IFS= read -r line; do
145+ visible_len=$( visible_len " $line " )
146+
147+ if [ " $visible_len " -gt " $max_width " ]; then
148+ max_width=$visible_len
149+ fi
150+ done << EOF
151+ $1
152+ EOF
153+
154+ box_width=$(( max_width + 6 ))
155+ border_len=$(( box_width - 2 ))
156+
157+ draw_line " $border_len " " ┌" " ─" " ┐"
158+ draw_line " $border_len " " │" " " " │"
159+
160+ while IFS= read -r line; do
161+ padding=$(( max_width - $(visible_len "$line ")) )
162+ draw_line " $padding " " ${BLUE} │${RESET} ${line} " " " " ${BLUE} │${RESET} "
163+ done << EOF
164+ $1
165+ EOF
166+
167+ draw_line " $border_len " " │" " " " │"
168+ draw_line " $border_len " " └" " ─" " ┘"
169+ }
170+
171+ # https://stackoverflow.com/a/56170835
172+ visible_len () {
173+ esc=$( printf ' \033' )
174+ stripped=$( printf ' %s' " $1 " | sed " s/${esc} [^m]*m//g" )
175+ printf ' %d' " ${# stripped} "
176+ }
177+
178+ draw_line () {
179+ i=0
180+ printf ' %s' " ${BLUE}${2} "
181+ while [ " $i " -lt " $1 " ]; do
182+ printf " $3 "
183+ i=$(( i + 1 ))
184+ done
185+ printf ' %s\n' " ${4}${RESET} "
186+ }
187+
188+ mk_print_next_steps_str () {
189+ echo " $1 "
190+ echo " "
191+
129192 if [ $os = " macos" ] && command -v xattr > /dev/null 2>&1 && xattr -l " $EXE_PATH " | grep -q " com.apple.quarantine" ; then
130193 renderComment " Run the following to remove the quarantine label from the binary"
131194 renderCommand " xattr -d com.apple.quarantine \" $( tildify " $EXE_PATH " ) \" "
132195 echo " "
133196 fi
134197
135- renderComment " Append the following to your shell profile (e.g. $( underline " ~/.zprofile" ) , $( underline " ~/.bash_profile" ) , etc.)"
198+ case " ${SHELL} " in
199+ * /bash* )
200+ if [ " $os " = linux ]; then
201+ print_append_to_shell_profile " ${HOME} /.bashrc"
202+ else
203+ print_append_to_shell_profile " ${HOME} /.bash_profile"
204+ fi
205+ ;;
206+ * /zsh* )
207+ if [ " $os " = linux ]; then
208+ print_append_to_shell_profile " ${ZDOTDIR:- " ${HOME} " } /.zshrc"
209+ else
210+ print_append_to_shell_profile " ${ZDOTDIR:- " ${HOME} " } /.zprofile"
211+ fi
212+ ;;
213+ * )
214+ renderComment " Add astra to your PATH in your shell profile"
215+ renderCommand " export PATH=$( dirname \" " $( tildify " $EXE_PATH " ) " \" ) :\$ PATH\" "
216+ echo " "
217+ ;;
218+ esac
219+
220+ renderComment " Run the following to get started!"
221+ renderCommand " astra setup"
222+ }
223+
224+ print_append_to_shell_profile () {
225+ file=" $1 "
226+
227+ # shellcheck disable=SC2016
136228 if [ " $ASTRA_CLI_DIR_RESOLVER " = " custom" ]; then
137- renderCommand " eval \"\$ ($( tildify " $EXE_PATH " ) shellenv --home \" $( tildify " $ASTRA_HOME " ) \" )\" "
229+ command= " eval \"\$ ($( tildify " $EXE_PATH " ) shellenv --home \" $( tildify " $ASTRA_HOME " ) \" )\" "
138230 else
139- renderCommand " eval \"\$ ($( tildify " $EXE_PATH " ) shellenv)\" "
231+ command= " eval \"\$ ($( tildify " $EXE_PATH " ) shellenv)\" "
140232 fi
141- echo " "
142233
143- renderComment " Run the following to get started!"
144- renderCommand " astra setup"
234+ if [ -w " $file " ]; then
235+ renderComment " Run the following to enable completions and update your PATH"
236+ renderCommand " echo '$command ' >> $( tildify " $file " ) "
237+ else
238+ renderComment " Append the following to your $( underline " $( tildify " $file " ) " ) to enable completions and update your PATH"
239+ renderCommand " $command "
240+ fi
241+
242+ echo " "
145243}
146244
147245# Existing installation checks
@@ -157,10 +255,12 @@ if [ -f "$existing_install_path" ]; then
157255 echo " ${BLUE} → ${LIGHT_GRAY} (< astra-cli 1.x)${RESET} Remove the existing installation manually and re-run this installer."
158256 echo " ${BLUE} → ${LIGHT_GRAY} (> astra-cli 1.x)${RESET} Run ${BLUE} astra upgrade${RESET} to automatically update to the latest version."
159257 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."
160- echo " "
161- echo " If you already knew astra was installed but you can't use it, please make sure you've done the following:"
162- echo " "
163- print_next_steps
258+
259+ if command -v astra > /dev/null 2>&1 ; then
260+ echo " "
261+ print_next_steps " If you just can't use ${BLUE} astra${RESET} , ensure you've done the following:"
262+ fi
263+
164264 exit 1
165265else
166266 checklist " No existing installation found."
@@ -198,6 +298,4 @@ rm "$TAR_PATH" 2>/dev/null || true
198298echo " "
199299echo " ${GREEN} Astra CLI installed successfully! 🎉${RESET} "
200300echo " "
201- echo " Next steps:"
202- echo " "
203- print_next_steps
301+ print_next_steps " Next steps:"
0 commit comments