Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Script #11

Open
hongkongkiwi opened this issue Oct 2, 2022 · 0 comments
Open

Update Script #11

hongkongkiwi opened this issue Oct 2, 2022 · 0 comments

Comments

@hongkongkiwi
Copy link

Perhaps in a future version we could have a self-update feature?

But in the meantime I wanted to share an update script, might be useful for others :)

#!/bin/bash -ue
EXISTING_FILE="/usr/local/bin/SARotate"
NEW_FILE="/tmp/SARotate"
SAROTATE_SERVICE="sarotate.service"
UPDATE_TYPE="SARotate-linux-x64"
RELEASE_JSON="$(curl -Ls "https://api.github.com/repos/saltydk/sarotate/releases/latest")"
RELEASE_VERSION="$(echo "$RELEASE_JSON" | jq -r '.name')"
if [ -f "$EXISTING_FILE" ]; then
  SAR_VERSION="$("$EXISTING_FILE" --version 2>&1 | cut -f2 -d' ')"
fi
if [ "${SAR_VERSION-}" != "$RELEASE_VERSION" ]; then
  echo "Found new update SARotate ${RELEASE_VERSION}, downloading now ..."
  RELEASE_LINK="$(echo "$RELEASE_JSON" | jq --arg name "$UPDATE_TYPE" -r '.assets[] | select(.name == $name) | .browser_download_url')"
  curl -Ls "$RELEASE_LINK" -o "$NEW_FILE"
  echo "Stopping existing service"
  systemctl stop "$SAROTATE_SERVICE"
  echo "Installing update"
  cp "$NEW_FILE" "$EXISTING_FILE"
  chmod +x "$EXISTING_FILE"
  rm -f "$NEW_FILE"
  echo "Restarting system service to apply update"
  systemctl start "$SAROTATE_SERVICE"
  echo "All done"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant