From 8cfa95b4489b00e79d5f27c9be0407fa42db4202 Mon Sep 17 00:00:00 2001 From: Jack Greiner Date: Thu, 9 Oct 2025 16:53:01 -0400 Subject: [PATCH] forgejo-release.sh: Handle dependency globally This ensures checks are consistent where needed. setup_api was retained in case of changes that might need to be made in the future. --- forgejo-release.sh | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/forgejo-release.sh b/forgejo-release.sh index 12c34e9..f1d713c 100755 --- a/forgejo-release.sh +++ b/forgejo-release.sh @@ -42,7 +42,31 @@ get_arch() { echo "$arch" } +check_dependencies() { + missing="" + for cmd in curl jq; do + if ! command -v "$cmd" >/dev/null 2>&1; then + missing="$missing $cmd" + fi + done + + if [ -n "$missing" ]; then + echo "Missing required tools:$missing" >&2 + echo "Attempting to install (if supported)..." >&2 + + if command -v apt-get >/dev/null 2>&1; then + apt-get -qq update && apt-get install -y -qq $missing + elif command -v apk >/dev/null 2>&1; then + apk add --no-cache $missing + else + echo "No supported package manager found; please install manually." >&2 + return 1 + fi + fi +} + setup_tea() { + check_dependencies if command -v tea >/dev/null 2>&1; then TEA_BIN=$(command -v tea) elif ! [ -f "$TEA_BIN" ]; then @@ -181,21 +205,8 @@ upload() { } setup_api() { - # Check if jq and curl are available - if command -v jq >/dev/null 2>&1 && command -v curl >/dev/null 2>&1; then - return 0 - fi - - echo "jq and/or curl missing, attempting to install..." >&2 - - if command -v apt-get >/dev/null 2>&1; then - apt-get -qq update && apt-get install -y -qq jq curl - elif command -v apk >/dev/null 2>&1; then - apk add --no-cache jq curl - else - echo "No supported package manager found. Please install jq and curl manually." >&2 - return 1 - fi + # Retained for future expansion, but dependency checking now handled globally + check_dependencies } api() {