1
+ #! /bin/bash
2
+
3
+ set -e
4
+
5
+ track_last_command () {
6
+ last_command=$current_command
7
+ current_command=$BASH_COMMAND
8
+ }
9
+ trap track_last_command DEBUG
10
+
11
+ echo_failed_command () {
12
+ local exit_code=" $? "
13
+ if [[ " $exit_code " != " 0" ]]; then
14
+ echo " '$last_command ': command failed with exit code $exit_code ."
15
+ fi
16
+ }
17
+ trap echo_failed_command EXIT
18
+
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... "
30
+ # Global variables
31
+ ASTRA_CLI_VERSION=" 0.1.alpha3"
32
+ ASTRA_CLI_PLATFORM=$( uname)
33
+ ASTRA_CLI_DIR=" $HOME /.astra/cli"
34
+
35
+ # Local variables
36
+ astra_tmp_folder=" $HOME /.astra/tmp"
37
+ astra_scb_folder=" $HOME /.astra/scb"
38
+ astra_zip_file=" ${astra_tmp_folder} /astra-cli-${ASTRA_CLI_VERSION} .zip"
39
+ astra_zip_base_folder=" ${astra_tmp_folder} /astra-cli-${ASTRA_CLI_VERSION} "
40
+
41
+ # Config Files
42
+ astra_bash_profile=" ${HOME} /.bash_profile"
43
+ astra_profile=" ${HOME} /.profile"
44
+ astra_bashrc=" ${HOME} /.bashrc"
45
+ astra_zshrc=" ${ZDOTDIR:- ${HOME} } /.zshrc"
46
+ astra_init_snippet=$( cat << EOF
47
+ #THIS MUST BE AT THE END OF THE FILE FOR ASTRA_CLI TO WORK!!!
48
+ export ASTRADIR="$ASTRA_CLI_DIR "
49
+ [[ -s "${ASTRA_CLI_DIR} /astra-init.sh" ]] && source "${ASTRA_CLI_DIR} /astra-init.sh"
50
+ EOF
51
+ )
52
+
53
+ # OS specific support (must be 'true' or 'false').
54
+ cygwin=false;
55
+ darwin=false;
56
+ solaris=false;
57
+ freebsd=false;
58
+ case " $( uname) " in
59
+ CYGWIN* )
60
+ cygwin=true
61
+ ;;
62
+ Darwin* )
63
+ darwin=true
64
+ ;;
65
+ SunOS* )
66
+ solaris=true
67
+ ;;
68
+ FreeBSD* )
69
+ freebsd=true
70
+ esac
71
+
72
+ # Sanity checks
73
+ echo " "
74
+ echo " Checking prerequisites:"
75
+
76
+ if [ -d " $ASTRA_DIR " ]; then
77
+ echo " "
78
+ echo " ======================================================================================================"
79
+ echo " You already have ASTRA-CLI installed, deleting..."
80
+ echo " ======================================================================================================"
81
+ echo " "
82
+ rm -Rf ${ASTRA_CLI_DIR}
83
+ exit 0
84
+ fi
85
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Ready to install."
86
+
87
+ if ! command -v unzip > /dev/null; then
88
+ echo " Not found."
89
+ echo " ======================================================================================================"
90
+ echo " Please install unzip on your system using your favourite package manager."
91
+ echo " "
92
+ echo " Restart after installing unzip."
93
+ echo " ======================================================================================================"
94
+ echo " "
95
+ exit 1
96
+ fi
97
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - unzip command is available"
98
+
99
+ if ! command -v zip > /dev/null; then
100
+ echo " Not found."
101
+ echo " ======================================================================================================"
102
+ echo " Please install zip on your system using your favourite package manager."
103
+ echo " "
104
+ echo " Restart after installing zip."
105
+ echo " ======================================================================================================"
106
+ echo " "
107
+ exit 1
108
+ fi
109
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - zip command is available"
110
+
111
+ if ! command -v curl > /dev/null; then
112
+ echo " Not found."
113
+ echo " "
114
+ echo " ======================================================================================================"
115
+ echo " Please install curl on your system using your favourite package manager."
116
+ echo " "
117
+ echo " Restart after installing curl."
118
+ echo " ======================================================================================================"
119
+ echo " "
120
+ exit 1
121
+ fi
122
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - curl command is available"
123
+
124
+ echo " "
125
+ echo " Preparing directories:"
126
+ mkdir -p " $astra_tmp_folder "
127
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Created $astra_tmp_folder "
128
+ mkdir -p " $ASTRA_CLI_DIR "
129
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Created $ASTRA_CLI_DIR "
130
+ mkdir -p " $astra_scb_folder "
131
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Created $astra_scb_folder "
132
+
133
+
134
+ echo " "
135
+ echo " Downloading archive:"
136
+ download_url=" https://github.com/datastaxdevs/datastaxdevs.github.io/raw/master/cli/astra-cli-${ASTRA_CLI_VERSION} .zip"
137
+ astra_zip_file=" ${astra_tmp_folder} /astra-cli-${ASTRA_CLI_VERSION} .zip"
138
+ if [ -f " $astra_zip_file " ]; then
139
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Archive is already there"
140
+ else
141
+ curl --fail --location --progress-bar " $download_url " > " $astra_zip_file "
142
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - File downloaded"
143
+ fi
144
+
145
+ # check integrity
146
+ ARCHIVE_OK=$( unzip -qt " $astra_zip_file " | grep ' No errors detected in compressed data' )
147
+ if [[ -z " $ARCHIVE_OK " ]]; then
148
+ echo " Downloaded zip archive corrupt. Are you connected to the internet?"
149
+ echo " "
150
+ echo " If problems persist, please ask for help on our Slack:"
151
+ echo " * easy sign up: https://slack.sdkman.io/"
152
+ echo " * report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"
153
+ exit
154
+ fi
155
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Integrity of the archive checked"
156
+
157
+
158
+ if [[ " $cygwin " == ' true' ]]; then
159
+ astra_tmp_folder=$( cygpath -w " $astra_tmp_folder " )
160
+ astra_zip_file=$( cygpath -w " $astra_zip_file " )
161
+ fi
162
+
163
+ echo " "
164
+ echo " Extracting and installation:"
165
+ unzip -qo " $astra_zip_file " -d " $astra_tmp_folder "
166
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Extraction is successful"
167
+
168
+ rm -rf " $astra_zip_file "
169
+ cp -rf " ${astra_tmp_folder} /" * " $ASTRA_CLI_DIR "
170
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - File moved to $ASTRA_CLI_DIR "
171
+
172
+ rm -rf " ${astra_tmp_folder} "
173
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Installation cleaned up"
174
+
175
+ if [[ $darwin == true ]]; then
176
+ # Adding on MAC OS
177
+ touch " $astra_bash_profile "
178
+ if [[ -z $( grep ' astra-init.sh' " $astra_bash_profile " ) ]]; then
179
+ echo -e " \n$astra_init_snippet " >> " $astra_bash_profile "
180
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - astra added to ${astra_bash_profile} "
181
+ fi
182
+ else
183
+ # Attempt update of interactive bash profile on regular UNIX
184
+ touch " ${astra_bashrc} "
185
+ if [[ -z $( grep ' astra-init.sh' " $astra_bashrc " ) ]]; then
186
+ echo -e " \n$astra_init_snippet " >> " $astra_bashrc "
187
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - astra added to ${astra_bashrc} "
188
+ fi
189
+ fi
190
+
191
+ touch " $astra_zshrc "
192
+ if [[ -z $( grep ' astra-init.sh' " $astra_zshrc " ) ]]; then
193
+ echo -e " \n$astra_init_snippet " >> " $astra_zshrc "
194
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - astra added to ${astra_zshrc} "
195
+ fi
196
+
197
+ echo " $( tput setaf 2) [OK]$( tput setaf 7) - Installation Successful"
198
+ echo " "
199
+ echo " Open $( tput setaf 2) A NEW TERMINAL$( tput setaf 7) and run: $( tput setaf 3) astra setup$( tput setaf 7) "
200
+ echo " "
201
+ echo " You can close this window."
0 commit comments