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.
This commit is contained in:
Jack Greiner 2025-10-09 16:53:01 -04:00
parent 324005b6c0
commit 8cfa95b448
No known key found for this signature in database
GPG key ID: F34343A8F6B33E1E

View file

@ -42,7 +42,31 @@ get_arch() {
echo "$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() { setup_tea() {
check_dependencies
if command -v tea >/dev/null 2>&1; then if command -v tea >/dev/null 2>&1; then
TEA_BIN=$(command -v tea) TEA_BIN=$(command -v tea)
elif ! [ -f "$TEA_BIN" ]; then elif ! [ -f "$TEA_BIN" ]; then
@ -181,21 +205,8 @@ upload() {
} }
setup_api() { setup_api() {
# Check if jq and curl are available # Retained for future expansion, but dependency checking now handled globally
if command -v jq >/dev/null 2>&1 && command -v curl >/dev/null 2>&1; then check_dependencies
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
} }
api() { api() {