file: better name
This commit is contained in:
Executable
+176
@@ -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 <<EOF
|
||||||
|
[Desktop Entry]
|
||||||
|
Name=logofclient
|
||||||
|
Comment=logoclient
|
||||||
|
Exec=/usr/local/bin/logofclient
|
||||||
|
Terminal=false
|
||||||
|
Type=Application
|
||||||
|
Icon=/opt/logofclient/assets/icon.png
|
||||||
|
Categories=Office;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rm -f "$ASSET"
|
||||||
|
|
||||||
|
printf 'Installed logofclient %s successfully.\n' "$tag"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uninstall(){
|
||||||
|
INSTALL_DIR="/opt/logofclient"
|
||||||
|
DESKTOP_FILE="/usr/share/applications/logofclient.desktop"
|
||||||
|
BINARY_LINK="/usr/local/bin/logofclient"
|
||||||
|
|
||||||
|
printf "Uninstalling logofclient...\n"
|
||||||
|
|
||||||
|
sudo rm -rf "$INSTALL_DIR"
|
||||||
|
sudo rm -f "$BINARY_LINK"
|
||||||
|
sudo rm -f "$DESKTOP_FILE"
|
||||||
|
|
||||||
|
printf "logofclient has been uninstalled.\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
update(){
|
||||||
|
printf "Checking for updates...\n"
|
||||||
|
|
||||||
|
GITEA_URL="${GITEA_URL:-https://git.mypapercloud.de}"
|
||||||
|
OWNER="${OWNER:-fierke}"
|
||||||
|
REPO="${REPO:-logofclient}"
|
||||||
|
|
||||||
|
API="${GITEA_URL%/}/api/v1"
|
||||||
|
INSTALL_DIR="/opt/logofclient"
|
||||||
|
|
||||||
|
if [[ -f "$INSTALL_DIR/.version" ]]; then
|
||||||
|
installed_tag="$(cat "$INSTALL_DIR/.version")"
|
||||||
|
else
|
||||||
|
installed_tag=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
release_json="$(
|
||||||
|
curl --fail --silent --show-error --location \
|
||||||
|
"$API/repos/$OWNER/$REPO/releases/latest"
|
||||||
|
)"
|
||||||
|
|
||||||
|
latest_tag="$(
|
||||||
|
jq --exit-status --raw-output '.tag_name' <<<"$release_json"
|
||||||
|
)"
|
||||||
|
|
||||||
|
printf "Installed version: %s\n" "${installed_tag:-none}"
|
||||||
|
printf "Latest version: %s\n" "$latest_tag"
|
||||||
|
|
||||||
|
if [[ "$installed_tag" == "$latest_tag" ]]; then
|
||||||
|
printf "Already up to date.\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Updating logofclient: %s -> %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
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user