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