@@ -18,8 +18,8 @@ VERSION="latest"
18
18
INSTALLER_VERSION=" 0.1.1"
19
19
20
20
NODE_MIN=22
21
- NODE_PATH=" $( which node) "
22
- NPM_PATH=" $( which npm) "
21
+ NODE_PATH=" $( command -v node) "
22
+ NPM_PATH=" $( command -v npm) "
23
23
24
24
# Properties
25
25
ARCH=" $( uname -m) "
@@ -48,7 +48,6 @@ get_latest_version() {
48
48
npm show ${PACKAGE_ORG: +${PACKAGE_ORG} / } " ${PACKAGE_NAME} " version
49
49
}
50
50
51
- ARCHIVE_URL=" "
52
51
download_from_npm () {
53
52
local tmpdir=" $1 "
54
53
local url=" $2 "
@@ -57,12 +56,11 @@ download_from_npm() {
57
56
58
57
mkdir -p " ${tmpdir} "
59
58
60
- curl --progress-bar --show-error --location --fail " ${url} " --output " ${download_file} "
61
- if [[ $? != 0 ]]; then
59
+ if ! curl --progress-bar --show-error --location --fail " ${url} " --output " ${download_file} " ; then
62
60
return 1
63
61
fi
64
62
65
- printf " ${CLEAR_LINE} " >&2
63
+ printf %b " ${CLEAR_LINE} " >&2
66
64
echo " ${download_file} "
67
65
}
68
66
@@ -126,7 +124,7 @@ build_path_str() {
126
124
127
125
cli_dir_valid () {
128
126
if [[ -n ${HYP_CLI-} ]] && [[ -e ${HYP_CLI} ]] && ! [[ -d ${HYP_CLI} ]]; then
129
- printf " \$ HYP_CLI is set but is not a directory (${HYP_CLI} ).\n" >&2
127
+ printf " \$ HYP_CLI is set but is not a directory (%s ).\n" " ${HYP_CLI} " >&2
130
128
printf " Please check your profile scripts and environment.\n" >&2
131
129
exit 1
132
130
fi
@@ -136,28 +134,34 @@ cli_dir_valid() {
136
134
update_profile () {
137
135
local install_dir=" $1 "
138
136
if [[ " :${PATH} :" == * " :${install_dir} :" * ]]; then
139
- printf " [3/4] ${DIM} The ${CLI_NAME} is already in \$ PATH${ RESET}\n " >&2
137
+ printf " [3/4] %sThe %s is already in \$ PATH%s\n " " ${DIM} " " ${CLI_NAME} " " ${ RESET}" >&2
140
138
return 0
141
139
fi
142
140
143
- local profile=" $( detect_profile $( basename " ${SHELL} " ) $( uname -s) ) "
141
+ local shell os profile
142
+ shell=" $( basename " ${SHELL} " ) "
143
+ os=" $( uname -s) "
144
+ profile=" $( detect_profile " ${shell} " " ${os} " ) "
144
145
if [[ -z ${profile} ]]; then
145
146
printf " No user shell profile found.\n" >&2
146
147
return 1
147
148
fi
148
149
149
150
export SHOW_RESET_PROFILE=1
150
- export PROFILE=" ~/$( basename " ${profile} " ) "
151
+
152
+ PROFILE=" ${HOME} /$( basename " ${profile} " ) "
153
+ export PROFILE
151
154
152
155
if grep -q ' HYP_CLI' " ${profile} " ; then
153
- printf " [3/4] ${DIM} The ${CLI_NAME} has already been configured in ${PROFILE}${RESET} \n" >&2
156
+ printf %b " [3/4] ${DIM} The ${CLI_NAME} has already been configured in ${PROFILE}${RESET} \n" >&2
154
157
return 0
155
158
fi
156
159
157
- local path_str=" $( build_path_str " ${profile} " " ${install_dir} " ) "
160
+ local path_str
161
+ path_str=" $( build_path_str " ${profile} " " ${install_dir} " ) "
158
162
echo " ${path_str} " >> " ${profile} "
159
163
160
- printf " [3/4] ${DIM} Added the ${CLI_NAME} to the PATH in ${PROFILE}${RESET} \n" >&2
164
+ printf %b " [3/4] ${DIM} Added the ${CLI_NAME} to the PATH in ${PROFILE}${RESET} \n" >&2
161
165
}
162
166
163
167
install_version () {
@@ -172,14 +176,13 @@ install_version() {
172
176
* ) ;;
173
177
esac
174
178
175
- install_release
176
- if [[ $? == 0 ]]; then
177
- update_profile " ${INSTALL_DIR} " && printf " [4/4] ${DIM} Installed the ${CLI_NAME}${RESET} \n" >&2
179
+ if ! install_release; then
180
+ update_profile " ${INSTALL_DIR} " && printf %b " [4/4] ${DIM} Installed the ${CLI_NAME}${RESET} \n" >&2
178
181
fi
179
182
}
180
183
181
184
install_release () {
182
- printf " [1/4] ${DIM} Downloading the ${CLI_NAME} from NPM${RESET} \n"
185
+ printf %b " [1/4] ${DIM} Downloading the ${CLI_NAME} from NPM${RESET} \n"
183
186
184
187
local url=" https://registry.npmjs.org/${PACKAGE_ORG: +${PACKAGE_ORG} / }${PACKAGE_NAME} /-/${PACKAGE_NAME} -${VERSION} .tgz"
185
188
@@ -189,27 +192,29 @@ install_release() {
189
192
) "
190
193
exit_status=" $? "
191
194
if [[ ${exit_status} != 0 ]]; then
192
- printf " Could not download the ${CLI_NAME} version '${VERSION} ' from\n${url} \n" >&2
195
+ printf %b " Could not download the ${CLI_NAME} version '${VERSION} ' from\n${url} \n" >&2
193
196
exit 1
194
197
fi
195
198
196
- printf " ${CLEAR_LINE} " >&2
197
- printf " [1/4] ${DIM} Downloaded latest ${CLI_NAME} v${VERSION}${RESET} \n" >&2
199
+ printf %b " ${CLEAR_LINE} " >&2
200
+ printf %b " [1/4] ${DIM} Downloaded latest ${CLI_NAME} v${VERSION}${RESET} \n" >&2
198
201
199
202
install_from_file " ${download_archive} "
200
203
}
201
204
202
205
download_release () {
203
- local url=" $1 "
204
- local download_dir=" $( mktemp -d) "
206
+ local url download_dir
207
+ url=" $1 "
208
+ download_dir=" $( mktemp -d) "
205
209
download_from_npm " ${download_dir} " " ${url} "
206
210
}
207
211
208
212
install_from_file () {
209
- local archive=" $1 "
210
- local extract_to=" $( dirname " ${archive} " ) "
213
+ local archive extract_to
214
+ archive=" $1 "
215
+ extract_to=" $( dirname " ${archive} " ) "
211
216
212
- printf " [2/4] ${DIM} Unpacking archive${RESET} \n" >&2
217
+ printf %b " [2/4] ${DIM} Unpacking archive${RESET} \n" >&2
213
218
214
219
tar -xf " ${archive} " -C " ${extract_to} "
215
220
@@ -221,12 +226,12 @@ install_from_file() {
221
226
222
227
ln -s " ${INSTALL_DIR} /bin/run.js" " ${INSTALL_DIR} /bin/hyp"
223
228
224
- printf " ${CLEAR_LINE} " >&2
225
- printf " [2/4] ${DIM} Installing dependencies${RESET} \n" >&2
229
+ printf %b " ${CLEAR_LINE} " >&2
230
+ printf %b " [2/4] ${DIM} Installing dependencies${RESET} \n" >&2
226
231
(cd " ${INSTALL_DIR} " && " ${NPM_PATH} " install --omit=dev --silent && find . -type d -empty -delete)
227
232
228
- printf " ${CLEAR_LINE} " >&2
229
- printf " [2/4] ${DIM} Unpacked archive${RESET} \n" >&2
233
+ printf %b " ${CLEAR_LINE} " >&2
234
+ printf %b " [2/4] ${DIM} Unpacked archive${RESET} \n" >&2
230
235
}
231
236
232
237
check_platform () {
@@ -239,51 +244,52 @@ check_platform() {
239
244
case " ${ARCH} /${OS} " in
240
245
x64/Linux | arm64/Linux | x64/Darwin | arm64/Darwin) return 0 ;;
241
246
* )
242
- printf " Unsupported os ${OS} ${ARCH} \n " >&2
247
+ printf " Unsupported os %s %s\n " " ${OS} " " ${ARCH} " >&2
243
248
exit 1
244
249
;;
245
250
esac
246
251
}
247
252
248
253
check_node () {
249
254
if [[ -z ${NODE_PATH} ]]; then
250
- printf " ${RED} Node.js is not installed.${RESET} \n" >&2
251
- printf " ${RED} Please install Node.js ${NODE_WANTED} or later and try again.${RESET} \n" >&2
255
+ printf %b " ${RED} Node.js is not installed.${RESET} \n" >&2
256
+ printf %b " ${RED} Please install Node.js ${NODE_WANTED} or later and try again.${RESET} \n" >&2
252
257
exit 1
253
258
fi
254
259
255
260
# check node version
256
- local node_version=" $( " ${NODE_PATH} " --version) "
257
- local node_major=" ${node_version%% .* } "
261
+ local node_version node_major
262
+ node_version=" $( " ${NODE_PATH} " --version) "
263
+ node_major=" ${node_version%% .* } "
258
264
node_major=" ${node_major# v} "
259
265
if [[ ${node_major} -lt ${NODE_MIN} ]]; then
260
- printf " ${RED} Node.js ${NODE_MIN} or later is required. You have ${node_version} .${RESET} \n" >&2
261
- printf " ${RED} Please update and try again${RESET} \n" >&2
266
+ printf %b " ${RED} Node.js ${NODE_MIN} or later is required. You have ${node_version} .${RESET} \n" >&2
267
+ printf %b " ${RED} Please update and try again${RESET} \n" >&2
262
268
exit 1
263
269
fi
264
270
265
271
# make sure npm can be found too
266
272
if [[ -z ${NPM_PATH} ]]; then
267
- printf " ${RED} npm is not installed. Please install npm and try again.${RESET} \n" >&2
273
+ printf %b " ${RED} npm is not installed. Please install npm and try again.${RESET} \n" >&2
268
274
exit 1
269
275
fi
270
276
}
271
277
272
278
# This is the entry point
273
- printf " \n${BOLD}${BLUE}${CLI_NAME} ${RESET} Installer ${DIM} v${INSTALLER_VERSION}${RESET} \n\n" >&2
279
+ printf %b " \n${BOLD}${BLUE} Modus ${RESET} Installer ${DIM} v${INSTALLER_VERSION}${RESET} \n\n" >&2
274
280
275
281
check_platform
276
282
check_node
277
283
install_version
278
284
279
- printf " \nThe ${CLI_NAME} has been installed! 🎉\n" >&2
285
+ printf " \nThe Modus CLI has been installed! 🎉\n" >&2
280
286
281
287
if [[ -n ${SHOW_RESET_PROFILE-} ]]; then
282
- printf " \n${YELLOW} Please restart your terminal or run:${RESET} \n" >&2
283
- printf " ${DIM} source ${PROFILE}${RESET} \n" >&2
284
- printf " \nThen, run ${DIM} hyp ${RESET} to get started${RESET} \n" >&2
288
+ printf %b " \n${YELLOW} Please restart your terminal or run:${RESET} \n" >&2
289
+ printf %b " ${DIM} source ${PROFILE}${RESET} \n" >&2
290
+ printf %b " \nThen, run ${DIM} modus ${RESET} to get started${RESET} \n" >&2
285
291
else
286
- printf " \nRun ${DIM} hyp ${RESET} to get started${RESET} \n" >&2
292
+ printf %b " \nRun ${DIM} modus ${RESET} to get started${RESET} \n" >&2
287
293
fi
288
294
289
295
printf " \n" >&2
0 commit comments