From 0a562be8870b1cd35183e5f8203340e07adedb32 Mon Sep 17 00:00:00 2001 From: Ron Stone Date: Fri, 25 Nov 2022 12:59:19 -0500 Subject: [PATCH] Scope vars Minor cleanup on var scopes in functions. Add support for prot selection. Signed-off-by: Ron Stone Change-Id: I9763a6d50631d357f7de11668b1f02d5cab898b1 --- get-remote-files.sh | 30 +++++++++++++++++++++++------- templates/events.sh | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/get-remote-files.sh b/get-remote-files.sh index 9a5b5f109..5b0b5e1da 100755 --- a/get-remote-files.sh +++ b/get-remote-files.sh @@ -3,6 +3,8 @@ # Fetch arbitrary files from a remote location for processing/ # inclusion in local build. +declare -A stx_repo + message () { echo -e "$@" 1>&2; } usage_error () { @@ -42,28 +44,42 @@ get_remote () { if [[ $no_branch = "t" ]]; then message "Branch ignored"; return; fi - local regex_br="^defaultbranch\=(.*)\s*$" + local _regex_br="^defaultbranch\=(.*)\s*$" local _remote=$(grep defaultbranch $branch_file) - if [[ "${_remote}" =~ $regex_br ]] + if [[ "${_remote}" =~ $_regex_br ]] then - remote="${BASH_REMATCH[1]}/" + remote="${BASH_REMATCH[1]}" else message "Can't find remote branch"; exit 1 fi + + for b in "${!stx_repo[@]}" + do + if [[ ${remote} == ${b} ]] + then + remote="${stx_repo[$b]}" + break + fi + done + + remote="$remote/" message "Remote is: $remote" } fetch_files () { - for f in "${!remote_files[@]}"; do + + local _f + + for _f in "${!remote_files[@]}"; do local _outfile case $out_method in "file") - _outfile="$common_target${remote_files[$f]}" + _outfile="$common_target${remote_files[$_f]}" if [ ! -d $(dirname $_outfile) ]; then mkdir -p `dirname $_outfile`; fi ;; "stdout") @@ -81,11 +97,11 @@ fetch_files () { exit 1 fi - wget -q -O $_outfile http://$remote_repo/$remote$f + wget $addtional_flags -q -O $_outfile $prot://$remote_repo/$remote$_f if [ $? -ne 0 ]; then if [ ! -s $_outfile ]; then rm -f $_outfile; fi - message "Could not download ${remote_files[$f]}. Quiting" + message "Could not download ${remote_files[$_f]}. Quiting" exit 1 fi diff --git a/templates/events.sh b/templates/events.sh index 0175b4885..71d948ec0 100644 --- a/templates/events.sh +++ b/templates/events.sh @@ -1,5 +1,6 @@ # If set, will be prepended to output paths common_target="tmp/" +prot="http" # The repo to download from remote_repo="opendev.org/starlingx/fault/raw/branch"