#!/bin/bash # # Purpose: Download and install pre-built binaries from binaries.conf CONF_FILE="${HAMPACK_BINARIES_CONF:-$HOME/.local/share/HamPack/binaries.conf}" TMP_DIR="/tmp/hampack-build" VERSION_FILE="$HOME/.local/state/HamPack/.installed_versions" # Get the installed version of an app get_installed_version() { local app="$1" if [ -f "$VERSION_FILE" ]; then local stored stored=$(grep "^$app=" "$VERSION_FILE" | cut -d'=' -f2) if [ -n "$stored" ]; then echo "$stored" return fi fi echo "unknown" } # Save installed version to version file save_installed_version() { local app="$1" local version="$2" touch "$VERSION_FILE" if grep -q "^$app=" "$VERSION_FILE"; then sed -i "s/^$app=.*/$app=$version/" "$VERSION_FILE" else echo "$app=$version" >> "$VERSION_FILE" fi } # Check if an update is needed needs_update() { local app="$1" local install_path="$2" local latest="$3" if [ ! -f "$install_path" ]; then echo " $app is not installed." return 0 fi local installed installed=$(get_installed_version "$app") if [ "$installed" = "unknown" ]; then echo " Warning: could not determine installed version of $app." echo " binaries.conf specifies version $latest." read -rp " Download and install $app anyway? [y/N] " response if [[ "$response" =~ ^[yY] ]]; then return 0 else return 1 fi fi echo " Installed version : $installed" echo " Latest version : $latest" if [ "$installed" = "$latest" ]; then echo " $app is up to date, skipping." return 1 fi echo " Update available for $app." return 0 } # Download binary and place it at the install path download_binary() { local app="$1" local url="$2" local install_path="$3" local filename="${url##*/}" local tmp_file="$TMP_DIR/$filename" echo " Downloading $url..." wget -q "$url" -O "$tmp_file" mkdir -p "$(dirname "$install_path")" mv "$tmp_file" "$install_path" chmod +x "$install_path" echo " Installed to $install_path" } # Generate and install a .desktop file install_desktop() { local app="$1" local install_path="$2" local exec_cmd="$3" local comment="$4" local icon="$5" local categories="$6" [ -z "$categories" ] && categories="HamRadio;" [ -z "$exec_cmd" ] && exec_cmd="$install_path" local desktop_dir="$HOME/.local/share/applications" mkdir -p "$desktop_dir" local desktop_file="$desktop_dir/$app.desktop" echo " Generating desktop file $desktop_file..." cat > "$desktop_file" <