diff --git a/logofclientinstall-linux.sh b/logofclientinstall-linux.sh new file mode 100755 index 0000000..162fe3c --- /dev/null +++ b/logofclientinstall-linux.sh @@ -0,0 +1,176 @@ +#!/bin/bash +set -Eeuo pipefail + +echo "Welcome to logofclient!" +echo "(c)2026 - MyPapertown, MyPaperCloud, Elias Fierke" +echo "Version 1.0" +echo "" + +show_help(){ + echo "-- HELP --" + echo " -v | Print the current application version" + echo " -h | Show this help text" + echo " -y | Answer all questions with yes" + echo "" + echo "-- COMMANDS --" + echo " install | install logofclient to your linux-system" + echo " update | update the logofclient to the newest version" + echo " uninstall | remove logofclient from your system" + exit 0 +} + +install(){ + printf "Fetching version...\n" + + GITEA_URL="${GITEA_URL:-https://git.mypapercloud.de}" + OWNER="${OWNER:-fierke}" + REPO="${REPO:-logofclient}" + + API="${GITEA_URL%/}/api/v1" + + release_json="$( + curl --fail --silent --show-error --location \ + "$API/repos/$OWNER/$REPO/releases/latest" + )" + + tag="$( + jq --exit-status --raw-output '.tag_name' <<<"$release_json" + )" + + printf "Installing logofclient %s...\n" "$tag" + + ASSET="logofclient-$tag-linux.tar.xz" + + asset_url="$( + jq --exit-status --raw-output \ + --arg asset "$ASSET" \ + '.assets[] + | select(.name == $asset) + | .browser_download_url' \ + <<<"$release_json" + )" + + printf 'Downloading package: %s\n' "$asset_url" + + curl --fail --location --retry 3 \ + --output "$ASSET" \ + "$asset_url" + + INSTALL_DIR="/opt/logofclient" + + printf 'Installing to: %s\n' "$INSTALL_DIR" + + sudo rm -rf "$INSTALL_DIR" + sudo mkdir -p "$INSTALL_DIR" + + sudo tar -xf "$ASSET" -C "$INSTALL_DIR" + echo "$tag" | sudo tee "$INSTALL_DIR/.version" > /dev/null + + sudo ln -sf "$INSTALL_DIR/Logof Client" "/usr/local/bin/logofclient" + + sudo tee /usr/share/applications/logofclient.desktop > /dev/null < %s\n" \ + "${installed_tag:-none}" "$latest_tag" + + if [[ -n "$installed_tag" ]]; then + uninstall + fi + + install +} + + +while getopts "yhv" opt; do + case $opt in + v) exit 0 ;; + h) show_help ;; + y) ALWAYS_YES="1" ;; + \?) echo "Unknown option: -$OPTARG" >&2; exit 1 ;; + :) echo "Option -$OPTARG needs an argument" >&2; exit 1 ;; + esac +done + +if [[ "$1" == "install" ]]; then + + install + + exit 0 +fi + +if [[ "$1" == "update" ]]; then + + update + exit 0 +fi + +if [[ "$1" == "uninstall" ]]; then + + uninstall + exit 0 +fi + +