@@ -149,7 +149,7 @@ parse_args() {
149
149
}
150
150
151
151
# =============================================================================
152
- # START: Code shared with other scripts
152
+ # START: Shared code
153
153
# =============================================================================
154
154
155
155
# Function for verbose logging
@@ -245,30 +245,74 @@ detect_architecture() {
245
245
246
246
# Function to compute the Runtime Identifier (RID)
247
247
get_runtime_identifier () {
248
- local os=" $1 "
249
- local arch=" $2 "
248
+ # set target_os to $1 and default to HOST_OS
249
+ local target_os=" $1 "
250
+ local target_arch=" $2 "
250
251
251
- # Detect OS and architecture if not provided
252
- if [[ -z " $OS " ]]; then
253
- if ! os=$( detect_os) ; then
254
- say_error " Unsupported operating system. Current platform: $( uname -s) "
252
+ if [[ -z " $target_os " ]]; then
253
+ target_os=$HOST_OS
254
+ fi
255
+
256
+ if [[ -z " $target_arch " ]]; then
257
+ if ! target_arch=$( get_cli_architecture_from_architecture " <auto>" ) ; then
255
258
return 1
256
259
fi
257
260
else
258
- os=" $OS "
261
+ if ! target_arch=$( get_cli_architecture_from_architecture " $target_arch " ) ; then
262
+ return 1
263
+ fi
264
+ fi
265
+
266
+ printf " %s" " ${target_os} -${target_arch} "
267
+ }
268
+
269
+ # Function to install/unpack archive files
270
+ install_archive () {
271
+ local archive_file=" $1 "
272
+ local destination_path=" $2 "
273
+
274
+ if [[ " $DRY_RUN " == true ]]; then
275
+ say_info " [DRY RUN] Would install archive $archive_file to $destination_path "
276
+ return 0
277
+ fi
278
+
279
+ say_verbose " Installing archive to: $destination_path "
280
+
281
+ # Create install directory if it doesn't exist
282
+ if [[ ! -d " $destination_path " ]]; then
283
+ say_verbose " Creating install directory: $destination_path "
284
+ mkdir -p " $destination_path "
259
285
fi
260
286
261
- if [[ -z " $ARCH " ]]; then
262
- if ! arch=$( get_cli_architecture_from_architecture " <auto>" ) ; then
287
+ # Check archive format and extract accordingly
288
+ if [[ " $archive_file " == * .zip ]]; then
289
+ # Use unzip for ZIP files
290
+ if ! command -v unzip > /dev/null 2>&1 ; then
291
+ say_error " unzip command not found. Please install unzip to extract ZIP files."
263
292
return 1
264
293
fi
265
- else
266
- if ! arch=$( get_cli_architecture_from_architecture " $ARCH " ) ; then
294
+
295
+ if ! unzip -o " $archive_file " -d " $destination_path " ; then
296
+ say_error " Failed to extract ZIP archive: $archive_file "
297
+ return 1
298
+ fi
299
+ elif [[ " $archive_file " == * .tar.gz ]]; then
300
+ # Use tar for tar.gz files on Unix systems
301
+ if ! command -v tar > /dev/null 2>&1 ; then
302
+ say_error " tar command not found. Please install tar to extract tar.gz files."
267
303
return 1
268
304
fi
305
+
306
+ if ! tar -xzf " $archive_file " -C " $destination_path " ; then
307
+ say_error " Failed to extract tar.gz archive: $archive_file "
308
+ return 1
309
+ fi
310
+ else
311
+ say_error " Unsupported archive format: $archive_file . Only .zip and .tar.gz are supported."
312
+ return 1
269
313
fi
270
314
271
- printf " %s " " ${os} - ${arch} "
315
+ say_verbose " Successfully installed archive "
272
316
}
273
317
274
318
# Function to add PATH to shell configuration file
@@ -410,7 +454,7 @@ cleanup() {
410
454
}
411
455
412
456
# =============================================================================
413
- # END: Code shared with get-aspire-cli*.sh
457
+ # END: Shared code
414
458
# =============================================================================
415
459
416
460
# Common function for HTTP requests with centralized configuration
0 commit comments