From 0911a5a5aed9232f8f9d1685e0a12378f21e41fe Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 13:13:13 +0100 Subject: lib.sh: split up xbmkget() it was too complicated. most of the logic has been moved to a new function, try_file() the for loop is handled by xbmkget(), whereas each try is now handled in try_file() Signed-off-by: Leah Rowe --- include/lib.sh | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index 2f87e8b1..c69825e8 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -50,34 +50,34 @@ xbmkget() _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" _dlop="curl" && [ $# -gt 4 ] && _dlop="$5" - cached="$XBMK_CACHE/file/$4" - dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum - bad_checksum "$4" "$cached" 2>/dev/null && dl_fail="y" - [ "$dl_fail" = "n" ] && e "$3" f && return 0 x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file" for url in "$1" "$2"; do - [ "$dl_fail" = "n" ] && break - [ -z "$url" ] && continue - x_ rm -f "$cached" - if [ "$_dlop" = "curl" ]; then - curl --location --retry 3 -A "$_ua" "$url" \ - -o "$cached" || wget --tries 3 -U "$_ua" "$url" \ - -O "$cached" || continue - elif [ "$_dlop" = "copy" ]; then - [ -L "$url" ] && \ - printf "dl %s %s %s %s: '%s' is a symlink\n" \ - "$1" "$2" "$3" "$4" "$url" 1>&2 && continue - [ ! -f "$url" ] && \ - printf "dl %s %s %s %s: '%s' not a file\n" \ - "$1" "$2" "$3" "$4" "$url" 1>&2 && continue - cp "$url" "$cached" || continue - else - err "$1 $2 $3 $4: Unsupported dlop type: '$_dlop'" - fi - bad_checksum "$4" "$cached" || dl_fail="n" - done - [ "$dl_fail" = "y" ] && err "$1 $2 $3 $4: not downloaded" - [ "$cached" = "$3" ] || x_ cp "$cached" "$3"; : + [ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0 + done && err "$1 $2 $3 $4: not downloaded"; : +} + +try_file() +{ + cached="$XBMK_CACHE/file/$6" + dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum + bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y" + [ "$dl_fail" = "n" ] && e "$5" f && return 0 + + x_ rm -f "$cached" + if [ "$2" = "curl" ]; then + curl --location --retry 3 -A "$_ua" "$1" -o "$cached" || \ + wget --tries 3 -U "$_ua" "$1" -O "$cached" || return 1 + elif [ "$2" = "copy" ]; then + [ -L "$1" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \ + "$3" "$4" "$5" "$6" "$1" 1>&2 && return 1 + [ ! -f "$1" ] && printf "dl %s %s %s %s: '%s' not a file\n" \ + "$3" "$4" "$5" "$6" "$1" 1>&2 && return 1 + cp "$1" "$cached" || return 1 + else + err "$3 $4 $5 $6: Unsupported dlop type: '$2'" + fi + bad_checksum "$6" "$cached" && return 1 + [ "$cached" = "$5" ] || x_ cp "$cached" "$5"; : } bad_checksum() -- cgit v1.2.1 From 3879f6c4d8ff89b390ff64afbcec66ea17f41123 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 13:21:59 +0100 Subject: lib.sh: use fx_ in rmgit() with fx_, i have more much granular control over how errors are handled. Signed-off-by: Leah Rowe --- include/lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index c69825e8..c0adc7a6 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -39,8 +39,8 @@ mksha512sum() rmgit() { - x_ find "$1" -name ".git" -exec rm -Rf {} + - x_ find "$1" -name ".gitmodules" -exec rm -Rf {} + + fx_ "x_ rm -Rf" x_ find "$1" -name ".git" + fx_ "x_ rm -Rf" x_ find "$1" -name ".gitmodules" } # can grab from the internet, or copy locally. -- cgit v1.2.1 From 89cd828e87c8a98e37f689adafa32d0f2d404c39 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 15:32:50 +0100 Subject: lib.sh: move _ua to try_file() it's only used there Signed-off-by: Leah Rowe --- include/lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index c0adc7a6..32f81cd0 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -47,8 +47,6 @@ rmgit() # if copying locally, it can only copy a file. xbmkget() { - _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" - _dlop="curl" && [ $# -gt 4 ] && _dlop="$5" x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file" for url in "$1" "$2"; do @@ -58,6 +56,8 @@ xbmkget() try_file() { + _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" + cached="$XBMK_CACHE/file/$6" dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y" -- cgit v1.2.1 From 80f0562e8d1d0de4715bdcbdab52440302fd1c44 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 15:44:31 +0100 Subject: lib.sh: split up try_file() Signed-off-by: Leah Rowe --- include/lib.sh | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index 32f81cd0..fc26c733 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -56,30 +56,37 @@ xbmkget() try_file() { - _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" - cached="$XBMK_CACHE/file/$6" dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y" [ "$dl_fail" = "n" ] && e "$5" f && return 0 x_ rm -f "$cached" - if [ "$2" = "curl" ]; then - curl --location --retry 3 -A "$_ua" "$1" -o "$cached" || \ - wget --tries 3 -U "$_ua" "$1" -O "$cached" || return 1 - elif [ "$2" = "copy" ]; then - [ -L "$1" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \ - "$3" "$4" "$5" "$6" "$1" 1>&2 && return 1 - [ ! -f "$1" ] && printf "dl %s %s %s %s: '%s' not a file\n" \ - "$3" "$4" "$5" "$6" "$1" 1>&2 && return 1 - cp "$1" "$cached" || return 1 - else - err "$3 $4 $5 $6: Unsupported dlop type: '$2'" - fi + [ "$2" = "curl" ] || [ "$2" = "copy" ] || \ + err "$3 $4 $5 $6: Unsupported dlop type: '$2'" + + try_$2 "$cached" "$@" || return 1 + bad_checksum "$6" "$cached" && return 1 [ "$cached" = "$5" ] || x_ cp "$cached" "$5"; : } +try_curl() +{ + _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" + curl --location --retry 3 -A "$_ua" "$2" -o "$1" || \ + wget --tries 3 -U "$_ua" "$2" -O "$1" || return 1; : +} + +try_copy() +{ + [ -L "$2" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \ + "$4" "$5" "$6" "$7" "$2" 1>&2 && return 1 + [ ! -f "$2" ] && printf "dl %s %s %s %s: '%s' not a file\n" \ + "$4" "$5" "$6" "$7" "$2" 1>&2 && return 1 + cp "$2" "$1" || return 1; : +} + bad_checksum() { [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1 -- cgit v1.2.1 From 23913bb8d2aa80452c381086b7513587badcd1e4 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 16:20:34 +0100 Subject: lib.sh: move mksha512sum() to vendor.sh this is unused in cbmk. it's only used from vendor.sh. therefore, lbmk shall have it in vendor.sh. Signed-off-by: Leah Rowe --- include/lib.sh | 8 -------- 1 file changed, 8 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index fc26c733..d5607c61 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -29,14 +29,6 @@ mktarball() x_ tar -c "$1" | xz -T$XBMK_THREADS -9e > "$2" || err "mktarball2, $1" } -mksha512sum() -{ - ( - [ "${1%/*}" != "$1" ] && x_ cd "${1%/*}" - sha512sum ./"${1##*/}" >> "$2" || err "!sha512sum \"$1\" > \"$2\"" - ) || err "failed to create tarball checksum" -} - rmgit() { fx_ "x_ rm -Rf" x_ find "$1" -name ".git" -- cgit v1.2.1 From c9696e233389f1f896dc70076cfc03f14f8a940a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 16:30:05 +0100 Subject: lib.sh: move xbmkget() to git.sh in cbmk, it's only used from there. in lbmk, it's also used from vendor.sh. however, i plan to further expand git.sh at some point, tidying it up so that git cloning is also done from xbmkget, with dlop=git and git.sh would then be renamed to get.sh Signed-off-by: Leah Rowe --- include/lib.sh | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index d5607c61..ba7d5d8c 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -35,56 +35,6 @@ rmgit() fx_ "x_ rm -Rf" x_ find "$1" -name ".gitmodules" } -# can grab from the internet, or copy locally. -# if copying locally, it can only copy a file. -xbmkget() -{ - _dlop="curl" && [ $# -gt 4 ] && _dlop="$5" - x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file" - for url in "$1" "$2"; do - [ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0 - done && err "$1 $2 $3 $4: not downloaded"; : -} - -try_file() -{ - cached="$XBMK_CACHE/file/$6" - dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum - bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y" - [ "$dl_fail" = "n" ] && e "$5" f && return 0 - - x_ rm -f "$cached" - [ "$2" = "curl" ] || [ "$2" = "copy" ] || \ - err "$3 $4 $5 $6: Unsupported dlop type: '$2'" - - try_$2 "$cached" "$@" || return 1 - - bad_checksum "$6" "$cached" && return 1 - [ "$cached" = "$5" ] || x_ cp "$cached" "$5"; : -} - -try_curl() -{ - _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" - curl --location --retry 3 -A "$_ua" "$2" -o "$1" || \ - wget --tries 3 -U "$_ua" "$2" -O "$1" || return 1; : -} - -try_copy() -{ - [ -L "$2" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \ - "$4" "$5" "$6" "$7" "$2" 1>&2 && return 1 - [ ! -f "$2" ] && printf "dl %s %s %s %s: '%s' not a file\n" \ - "$4" "$5" "$6" "$7" "$2" 1>&2 && return 1 - cp "$2" "$1" || return 1; : -} - -bad_checksum() -{ - [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1 - printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; : -} - e() { es_t="e" && [ $# -gt 1 ] && es_t="$2" -- cgit v1.2.1 From 05b5914b35492ddb4076873e0b6519396dfe92de Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 18:01:53 +0100 Subject: lib.sh: remove mk() i don't need it. i can use fx_ instead, on functions that previously called mk(). Signed-off-by: Leah Rowe --- include/lib.sh | 8 -------- 1 file changed, 8 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index ba7d5d8c..cb3ba6cc 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -46,14 +46,6 @@ e() printf "%s %s\n" "$1" "$es2" 1>&2 } -mk() -{ - mk_flag="$1" || err "No argument given" - shift 1 && for mk_arg in "$@"; do - x_ ./mk $mk_flag $mk_arg - done; : -} - setvars() { _setvars="" -- cgit v1.2.1 From 92954eeb38f69ebc0cfef7b9629e96a1599667be Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 12 May 2025 19:20:50 +0100 Subject: lib.sh: remove rmgit() We don't need to call it from git.sh, because it's only being done when building a release anyway, and we already run rmgit when doing a release. The function itself is only two simple fx_ calls, so we can just do that from build_release(). Signed-off-by: Leah Rowe --- include/lib.sh | 6 ------ 1 file changed, 6 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index cb3ba6cc..cf4305a1 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -29,12 +29,6 @@ mktarball() x_ tar -c "$1" | xz -T$XBMK_THREADS -9e > "$2" || err "mktarball2, $1" } -rmgit() -{ - fx_ "x_ rm -Rf" x_ find "$1" -name ".git" - fx_ "x_ rm -Rf" x_ find "$1" -name ".gitmodules" -} - e() { es_t="e" && [ $# -gt 1 ] && es_t="$2" -- cgit v1.2.1