Skip to content

Commit ebe461b

Browse files
authored
Merge pull request #18 from marverix/use-cache-dir
fix: Use GAH_CACHE_DIR as temp download folder
2 parents 0d17372 + 0cacb84 commit ebe461b

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

gah

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,30 +373,37 @@ function command_version() {
373373
}
374374

375375
function command_install() {
376+
print_debug "Starting installation process"
377+
376378
# Create temporary directory
377-
tmp_dir=$(mktemp -d)
379+
print_debug "Creating temporary directory"
380+
tmp_dir=$(mktemp -d -p "$GAH_CACHE_DIR")
381+
print_debug "OK, temporary directory: $tmp_dir"
378382

379383
# Change to temporary directory
380-
cd $tmp_dir
384+
print_debug "Changing to temporary directory"
385+
cd "$tmp_dir"
386+
print_debug "OK"
381387

382388
local repo="$1"
383389
local tag="$2"
384390

385391
# Fetch the release information
386392
print_blue "Fetching release info for: $repo [$tag]"
387393
fetch_release_info "$repo" "$tag"
394+
print_debug "OK"
388395

389396
# Find the download URL
397+
print_debug "Finding download URL"
390398
local download_url=$(find_download_url "$tmp_dir/release.json")
399+
print_debug "OK, Download URL:\n$download_url"
391400

392401
if [[ -z "$download_url" ]]; then
393402
local os=$(get_os)
394403
local arch=$(get_arch)
395404
throw_error 18 "Could not find any assets matching your OS ($os) and Arch ($arch)."
396405
fi
397406

398-
print_debug "Download URL:\n$download_url"
399-
400407
# Check if several download URLs were found
401408
if [[ $(echo "$download_url" | wc -l) -gt 1 ]]; then
402409
print_yellow "Several download URLs were found which match your OS and arch."
@@ -421,48 +428,69 @@ function command_install() {
421428
fi
422429

423430
# Get a filename
431+
print_debug "Getting filename from URL"
424432
local filename=$(basename "$download_url")
433+
print_debug "OK, filename: $filename"
425434

426435
# Find digest
436+
print_debug "Finding digest for download URL"
427437
local digest=$(find_digest_for_url "$tmp_dir/release.json" "$download_url")
438+
print_debug "OK, digest: $digest"
428439

429440
# Download the file
430441
print_blue "Downloading: $filename"
431442
curl -L --progress-bar -o "$filename" "$download_url"
432443

433444
# Verify the download if digest is available
445+
print_debug "Verifying download digest if available"
434446
if [[ -n "$digest" ]]; then
447+
print_debug "OK, verifying digest for $filename"
435448
verify_digest "$filename" "$digest"
436449
else
437450
print_yellow "GitHub Release did not provide digest for $filename. Skipping verification."
438451
fi
439452

440453
# Extract if needed
454+
print_debug "Checking if extraction is needed for: $filename"
441455
if [[ "$filename" =~ $REGEXP_EXT_TAR ]]; then
442456
print_blue "Extracting: $filename"
443457
tar -xf "$filename"
458+
print_debug "OK, extracted using tar"
444459

445460
elif [[ "$filename" =~ $REGEXP_EXT_ZIP ]]; then
446461
print_blue "Extracting: $filename"
447462
unzip -q "$filename"
463+
print_debug "OK, extracted using unzip"
448464

449465
else
450466
print_debug "Does not look like supported archive - no need to extract"
451467
chmod +x "$filename"
452468
fi
453469

470+
print_debug "Finding executable files to install"
454471
for bin_file in $(find . -type f -executable); do
472+
print_debug "Found executable: $bin_file"
473+
474+
print_debug "Getting base file name"
455475
local file_name=$(basename "$bin_file")
476+
print_debug "OK, base file name: $file_name"
477+
478+
print_debug "Calculating lower case file name for skip check"
456479
local lower_file_name=$(echo "$file_name" | tr '[A-Z]' '[a-z]')
480+
print_debug "OK, lower case file name: $lower_file_name"
457481

482+
print_debug "Checking if file should be skipped"
458483
if [[ "$lower_file_name" =~ $REGEXP_SKIP_FILES ]]; then
459-
print_debug "Skipping: $file_name"
484+
print_debug "File name matches skip pattern - Skipping: $file_name"
460485
continue
461486
fi
487+
print_debug "No skip pattern matched - File will be installed"
462488

489+
print_debug "Removing version/os/arch parts from file name if present"
463490
local regexp=$(get_name_regexp)
464491
if [[ "$file_name" =~ $regexp ]]; then
465492
file_name="${BASH_REMATCH[1]}"
493+
print_debug "OK, cleaned file name"
466494
fi
467495

468496
print_blue "Installing: $file_name"

0 commit comments

Comments
 (0)