Rework msg_functions for tool.func Pt. 2

This commit is contained in:
CanbiZ 2025-06-17 16:40:52 +02:00
parent 37d1d7da2d
commit fd1c8c5368

View File

@ -744,7 +744,6 @@ function fetch_and_deploy_gh_release() {
local current_version=""
if [[ -f "$version_file" ]]; then
current_version=$(<"$version_file")
$STD msg_info "Current installed version of $app: $current_version"
fi
if ! command -v jq &>/dev/null; then
@ -756,7 +755,6 @@ function fetch_and_deploy_gh_release() {
local header=()
[[ -n "${GITHUB_TOKEN:-}" ]] && header=(-H "Authorization: token $GITHUB_TOKEN")
$STD msg_info "Fetching release metadata for $repo ($version)..."
local resp http_code
resp=$(curl $curl_timeout -fsSL -w "%{http_code}" -o /tmp/gh_rel.json "${header[@]}" "$api_url")
http_code="${resp:(-3)}"
@ -779,12 +777,13 @@ function fetch_and_deploy_gh_release() {
tmpdir=$(mktemp -d) || return 1
local filename="" url=""
msg_info "Setup $app ($version)"
if [[ "$mode" == "tarball" || "$mode" == "source" ]]; then
url=$(echo "$json" | jq -r '.tarball_url // empty')
[[ -z "$url" ]] && url="https://github.com/$repo/archive/refs/tags/v$version.tar.gz"
filename="${app_lc}-${version}.tar.gz"
$STD msg_info "Downloading source tarball: $url"
curl $curl_timeout -fsSL -o "$tmpdir/$filename" "$url" || {
msg_error "Download failed: $url"
rm -rf "$tmpdir"
@ -800,8 +799,6 @@ function fetch_and_deploy_gh_release() {
cp -r "$unpack_dir"/* "$target/"
shopt -u dotglob nullglob
$STD msg_ok "$app (tarball) deployed to $target"
elif [[ "$mode" == "binary" ]]; then
local arch
arch=$(dpkg --print-architecture 2>/dev/null || uname -m)
@ -831,7 +828,6 @@ function fetch_and_deploy_gh_release() {
fi
filename="${url_match##*/}"
$STD msg_info "Downloading binary package: $filename"
curl $curl_timeout -fsSL -o "$tmpdir/$filename" "$url_match" || {
msg_error "Download failed: $url_match"
rm -rf "$tmpdir"
@ -839,18 +835,14 @@ function fetch_and_deploy_gh_release() {
}
chmod 644 "$tmpdir/$filename"
$STD msg_info "Installing $filename via apt..."
$STD apt-get install -y "$tmpdir/$filename" || {
$STD msg_info "apt failed, falling back to dpkg -i..."
dpkg -i "$tmpdir/$filename" || {
$STD dpkg -i "$tmpdir/$filename" || {
msg_error "Both apt and dpkg installation failed"
rm -rf "$tmpdir"
return 1
}
}
$STD msg_ok "$app (.deb binary) installed successfully"
elif [[ "$mode" == "prebuild" ]]; then
local pattern="$6"
[[ -z "$pattern" ]] && {
@ -871,7 +863,6 @@ function fetch_and_deploy_gh_release() {
}
filename="${asset_url##*/}"
$STD msg_info "Downloading prebuilt asset: $filename"
curl $curl_timeout -fsSL -o "$tmpdir/$filename" "$asset_url" || {
msg_error "Download failed: $asset_url"
rm -rf "$tmpdir"
@ -881,7 +872,6 @@ function fetch_and_deploy_gh_release() {
mkdir -p "$target"
if [[ "$filename" == *.zip ]]; then
if ! command -v unzip &>/dev/null; then
$STD msg_info "Installing unzip..."
$STD apt-get install -y unzip
fi
unzip "$tmpdir/$filename" -d "$target"
@ -893,8 +883,6 @@ function fetch_and_deploy_gh_release() {
return 1
fi
$STD msg_ok "$app (prebuilt) extracted to $target"
elif [[ "$mode" == "singlefile" ]]; then
local pattern="$6"
[[ -z "$pattern" ]] && {
@ -916,7 +904,6 @@ function fetch_and_deploy_gh_release() {
filename="${asset_url##*/}"
mkdir -p "$target"
$STD msg_info "Downloading single binary: $filename"
curl $curl_timeout -fsSL -o "$target/$app" "$asset_url" || {
msg_error "Download failed: $asset_url"
rm -rf "$tmpdir"
@ -924,7 +911,6 @@ function fetch_and_deploy_gh_release() {
}
chmod +x "$target/$app"
$STD msg_ok "$app (single binary) installed to $target"
else
msg_error "Unknown mode: $mode"
@ -933,7 +919,7 @@ function fetch_and_deploy_gh_release() {
fi
echo "$version" >"$version_file"
$STD msg_ok "$app v$version deployed successfully"
msg_ok "Setup $app ($version)"
rm -rf "$tmpdir"
}