From 49f9aa3a415bd65ddb926228ca70b92c1eb90dfd Mon Sep 17 00:00:00 2001 From: tom goriunov Date: Wed, 8 Nov 2023 10:11:40 -0300 Subject: [PATCH] support local file URI for ENVs with external resources (#1325) [skip ci] support local file URI for ENVs with external resources Fixes #1324 --- deploy/scripts/download_assets.sh | 35 ++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/deploy/scripts/download_assets.sh b/deploy/scripts/download_assets.sh index 49bbe73b81..93ef31f491 100755 --- a/deploy/scripts/download_assets.sh +++ b/deploy/scripts/download_assets.sh @@ -37,11 +37,20 @@ get_target_filename() { local name_suffix="${name_prefix%_URL}" local name_lc="$(echo "$name_suffix" | tr '[:upper:]' '[:lower:]')" - # Remove query parameters from the URL and get the filename - local filename=$(basename "${url%%\?*}") - - # Extract the extension from the filename - local extension="${filename##*.}" + # Check if the URL starts with "file://" + if [[ "$url" == file://* ]]; then + # Extract the local file path + local file_path="${url#file://}" + # Get the filename from the local file path + local filename=$(basename "$file_path") + # Extract the extension from the filename + local extension="${filename##*.}" + else + # Remove query parameters from the URL and get the filename + local filename=$(basename "${url%%\?*}") + # Extract the extension from the filename + local extension="${filename##*.}" + fi # Convert the extension to lowercase extension=$(echo "$extension" | tr '[:upper:]' '[:lower:]') @@ -59,19 +68,25 @@ download_and_save_asset() { # Check if the environment variable is set if [ -z "${!env_var}" ]; then - echo " [.] Environment variable $env_var is not set. Skipping download." + echo " [.] $env_var: Variable is not set. Skipping download." return 1 fi - # Download the asset using curl - curl -s -o "$destination" "$url" + # Check if the URL starts with "file://" + if [[ "$url" == file://* ]]; then + # Copy the local file to the destination + cp "${url#file://}" "$destination" + else + # Download the asset using curl + curl -s -o "$destination" "$url" + fi # Check if the download was successful if [ $? -eq 0 ]; then - echo " [+] Downloaded $env_var to $destination successfully." + echo " [+] $env_var: Successfully saved file from $url to $destination." return 0 else - echo " [-] Failed to download $env_var from $url." + echo " [-] $env_var: Failed to save file from $url." return 1 fi }