Skip to content

Commit 8038f08

Browse files
committed
shell install
1 parent 6327ab2 commit 8038f08

File tree

1 file changed

+53
-73
lines changed

1 file changed

+53
-73
lines changed

astra-shell/dist/astra-install.sh

Lines changed: 53 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ echo_failed_command() {
1616
}
1717
trap echo_failed_command EXIT
1818

19+
clear
20+
echo " "
21+
echo " █████╗ ███████╗████████╗██████╗ █████╗ ███████╗██╗ ██╗███████╗██╗ ██╗"
22+
echo " ██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██╔══██╗ ██╔════╝██║ ██║██╔════╝██║ ██║ "
23+
echo " ███████║███████╗ ██║ ██████╔╝███████║ ███████╗███████║█████╗ ██║ ██║ "
24+
echo " ██╔══██║╚════██║ ██║ ██╔══██╗██╔══██║ ╚════██║██╔══██║██╔══╝ ██║ ██║"
25+
echo " ██║ ██║███████║ ██║ ██║ ██║██║ ██║ ███████║██║ ██║███████╗███████╗███████╗"
26+
echo " ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝"
27+
echo " "
28+
29+
echo "Installing Astra Cli, please wait... "
1930
# Global variables
2031
ASTRA_CLI_VERSION="0.3.2-alpha1"
2132
ASTRA_CLI_PLATFORM=$(uname)
2233
ASTRA_CLI_DIR="$HOME/.astra/cli"
23-
ASTRA_CLI_DIR_RAW='$HOME/.astra/cli'
2434

2535
# Local variables
2636
astra_tmp_folder="$HOME/.astra/tmp"
@@ -33,9 +43,9 @@ astra_profile="${HOME}/.profile"
3343
astra_bashrc="${HOME}/.bashrc"
3444
astra_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"
3545
astra_init_snippet=$( cat << EOF
36-
#THIS MUST BE AT THE END OF THE FILE FOR ASTRA TO WORK!!!
37-
export ASTRADIR="$ASTRA_CLI_DIR_RAW"
38-
[[ -s "${ASTRADIR}/astra-init.sh" ]] && source "${ASTRADIR}/astra-init.sh"
46+
#THIS MUST BE AT THE END OF THE FILE FOR ASTRA_CLI TO WORK!!!
47+
export ASTRADIR="$ASTRA_CLI_DIR"
48+
[[ -s "${ASTRA_CLI_DIR}/astra-init.sh" ]] && source "${ASTRA_CLI_DIR}/astra-init.sh"
3949
EOF
4050
)
4151

@@ -59,8 +69,9 @@ case "$(uname)" in
5969
esac
6070

6171
# Sanity checks
72+
echo ""
73+
echo "Checking prerequisites:"
6274

63-
echo "Looking for a previous installation of SDKMAN..."
6475
if [ -d "$ASTRA_DIR" ]; then
6576
echo "ASTRA-CLI found."
6677
echo ""
@@ -75,8 +86,8 @@ if [ -d "$ASTRA_DIR" ]; then
7586
echo ""
7687
exit 0
7788
fi
89+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - No previous installation detected."
7890

79-
echo "Looking for unzip..."
8091
if ! command -v unzip > /dev/null; then
8192
echo "Not found."
8293
echo "======================================================================================================"
@@ -87,8 +98,8 @@ if ! command -v unzip > /dev/null; then
8798
echo ""
8899
exit 1
89100
fi
101+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - unzip command is available"
90102

91-
echo "Looking for zip..."
92103
if ! command -v zip > /dev/null; then
93104
echo "Not found."
94105
echo "======================================================================================================"
@@ -99,8 +110,8 @@ if ! command -v zip > /dev/null; then
99110
echo ""
100111
exit 1
101112
fi
113+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - zip command is available"
102114

103-
echo "Looking for curl..."
104115
if ! command -v curl > /dev/null; then
105116
echo "Not found."
106117
echo ""
@@ -112,55 +123,27 @@ if ! command -v curl > /dev/null; then
112123
echo ""
113124
exit 1
114125
fi
126+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - curl command is available"
115127

116-
if [[ "$solaris" == true ]]; then
117-
echo "Looking for gsed..."
118-
if [ -z $(which gsed) ]; then
119-
echo "Not found."
120-
echo ""
121-
echo "======================================================================================================"
122-
echo " Please install gsed on your solaris system."
123-
echo ""
124-
echo " SDKMAN uses gsed extensively."
125-
echo ""
126-
echo " Restart after installing gsed."
127-
echo "======================================================================================================"
128-
echo ""
129-
exit 1
130-
fi
131-
else
132-
echo "Looking for sed..."
133-
if [ -z $(command -v sed) ]; then
134-
echo "Not found."
135-
echo ""
136-
echo "======================================================================================================"
137-
echo " Please install sed on your system using your favourite package manager."
138-
echo ""
139-
echo " Restart after installing sed."
140-
echo "======================================================================================================"
141-
echo ""
142-
exit 1
143-
fi
144-
fi
145-
146-
echo "Installing Astra Cli scripts..."
147-
148-
# Create directory structure
149-
150-
echo "Create distribution directories..."
128+
echo ""
129+
echo "Preparing directories:"
151130
mkdir -p "$astra_tmp_folder"
152-
mkdir -p "$ASTRA_CLI_DIR_RAW"
131+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Created $astra_tmp_folder"
132+
mkdir -p "$ASTRA_CLI_DIR"
133+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Created $ASTRA_CLI_DIR"
153134

154-
# script cli distribution
155-
echo "Installing script cli archive..."
156-
# fetch distribution
157-
download_url="${ASTRA_SERVICE}/...."
158-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRAVERSION}.zip"
159-
echo "* Downloading..."
160-
curl --fail --location --progress-bar "$download_url" > "$astra_zip_file"
135+
echo ""
136+
echo "Downloading archive:"
137+
download_url="https://github.com/datastaxdevs/datastaxdevs.github.io/raw/master/cli/${ASTRA_CLI_VERSION}.zip"
138+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}.zip"
139+
if [ -f "$astra_zip_file" ]; then
140+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Archive is already there"
141+
else
142+
curl --fail --location --progress-bar "$download_url" > "$astra_zip_file"
143+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - File downloaded"
144+
fi
161145

162146
# check integrity
163-
echo "* Checking archive integrity..."
164147
ARCHIVE_OK=$(unzip -qt "$astra_zip_file" | grep 'No errors detected in compressed data')
165148
if [[ -z "$ARCHIVE_OK" ]]; then
166149
echo "Downloaded zip archive corrupt. Are you connected to the internet?"
@@ -170,52 +153,49 @@ if [[ -z "$ARCHIVE_OK" ]]; then
170153
echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"
171154
exit
172155
fi
156+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Integrity of the archive checked"
157+
173158

174-
# extract
175-
echo "* Extracting archive..."
176159
if [[ "$cygwin" == 'true' ]]; then
177-
astratmp_folder=$(cygpath -w "$astratmp_folder")
178-
astrazip_file=$(cygpath -w "$astrazip_file")
179-
astrazip_base_folder=$(cygpath -w "$astrazip_base_folder")
160+
astra_tmp_folder=$(cygpath -w "$astra_tmp_folder")
161+
astra_zip_file=$(cygpath -w "$astra_zip_file")
180162
fi
181-
unzip -qo "$astrazip_file" -d "$astratmp_folder"
182-
183-
# copy in place
184163

185-
echo "* Copying archive contents..."
186-
cp -rf "${astrazip_base_folder}/"* "$ASTRA_DIR"
164+
echo ""
165+
echo "Extracting and installation:"
166+
unzip -qo "$astra_zip_file" -d "$astra_tmp_folder"
167+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Extraction is successful"
187168

188-
# clean up
189-
echo "* Cleaning up..."
190-
rm -rf "$astra_zip_base_folder"
191169
rm -rf "$astra_zip_file"
170+
cp -rf "${astra_tmp_folder}/"* "$ASTRA_CLI_DIR"
171+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - File moved to $ASTRA_CLI_DIR"
192172

193-
echo ""
173+
rm -rf "${astra_tmp_folder}"
174+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Installation cleaned up"
194175

176+
echo $astra_init_snippet
195177

196-
echo "Set version to $ASTRA_CLI_VERSION ..."
197-
echo "$ASTRA_CLI_VERSION" > "${ASTRA_CLI_DIR}/var/version"
198178

199179
if [[ $darwin == true ]]; then
180+
# Adding on MAC OS
200181
touch "$astra_bash_profile"
201-
echo "Attempt update of login bash profile on OSX..."
202182
if [[ -z $(grep 'astra-init.sh' "$astra_bash_profile") ]]; then
203183
echo -e "\n$astra_init_snippet" >> "$astra_bash_profile"
204-
echo "Added astra init snippet to $astra_bash_profile"
184+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_bash_profile}"
205185
fi
206186
else
207-
echo "Attempt update of interactive bash profile on regular UNIX..."
187+
# Attempt update of interactive bash profile on regular UNIX
208188
touch "${astra_bashrc}"
209189
if [[ -z $(grep 'astra-init.sh' "$astra_bashrc") ]]; then
210190
echo -e "\n$astra_init_snippet" >> "$astra_bashrc"
211-
echo "Added astra init snippet to $astra_bashrc"
191+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_bashrc}"
212192
fi
213193
fi
214194

215-
echo "Attempt update of zsh profile..."
216195
touch "$astra_zshrc"
217196
if [[ -z $(grep 'astra-init.sh' "$astra_zshrc") ]]; then
218197
echo -e "\n$astra_init_snippet" >> "$astra_zshrc"
198+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_zshrc}"
219199
echo "Updated existing ${astra_zshrc}"
220200
fi
221201

0 commit comments

Comments
 (0)