chore: implemented whole functionality since it's not too complex (linux)
This commit is contained in:
+104
-32
@@ -22,55 +22,127 @@ show_help(){
|
||||
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"
|
||||
curl --fail --silent --show-error --location \
|
||||
"$API/repos/$OWNER/$REPO/releases/latest"
|
||||
)"
|
||||
|
||||
tag="$(
|
||||
jq --exit-status --raw-output '.tag_name' <<<"$release_json"
|
||||
latest_tag="$(
|
||||
jq --exit-status --raw-output '.tag_name' <<<"$release_json"
|
||||
)"
|
||||
|
||||
printf "Installing logofclient $tag...\n"
|
||||
printf "Installed version: %s\n" "${installed_tag:-none}"
|
||||
printf "Latest version: %s\n" "$latest_tag"
|
||||
|
||||
ASSET="logofclient-$tag-linux.tar.xz"
|
||||
if [[ "$installed_tag" == "$latest_tag" ]]; then
|
||||
printf "Already up to date.\n"
|
||||
return 0
|
||||
fi
|
||||
|
||||
asset_url="$(
|
||||
jq --exit-status --raw-output \
|
||||
--arg asset "$ASSET" \
|
||||
'.assets[]
|
||||
| select(.name == $asset)
|
||||
| .browser_download_url' \
|
||||
<<<"$release_json"
|
||||
)"
|
||||
printf "Updating logofclient: %s -> %s\n" \
|
||||
"${installed_tag:-none}" "$latest_tag"
|
||||
|
||||
#printf 'Release tag: %s\n' "$tag"
|
||||
printf 'Downloading package: %s\n' "$asset_url"
|
||||
if [[ -n "$installed_tag" ]]; then
|
||||
uninstall
|
||||
fi
|
||||
|
||||
curl --fail --location --retry 3 \
|
||||
"${AUTH[@]}" \
|
||||
--output "$ASSET" \
|
||||
"$asset_url"
|
||||
|
||||
#printf 'Gespeichert als: %s\n' "$ASSET"
|
||||
install
|
||||
}
|
||||
|
||||
update(){
|
||||
echo "updating logofclient"
|
||||
}
|
||||
|
||||
uninstall(){
|
||||
echo "removing logofclient from your system"
|
||||
}
|
||||
|
||||
while getopts "yhv" opt; do
|
||||
case $opt in
|
||||
@@ -91,13 +163,13 @@ fi
|
||||
|
||||
if [[ "$1" == "update" ]]; then
|
||||
|
||||
# update
|
||||
update
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$1" == "uninstall" ]]; then
|
||||
|
||||
# uninstall
|
||||
uninstall
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user