-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): auto updating binary (#213)
feat(install): auto updating binary (#4) Note: install notes guide the user through these steps, this code doesn't run in a deployment
- Loading branch information
1 parent
ec2d59b
commit ee709d0
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# Detect your machine's architecture and set it as $OSARCH | ||
OSARCH=$(uname -m | awk '{if ($0 ~ /arm64|aarch64/) print "arm64"; else if ($0 ~ /x86_64|amd64/) print "amd64"; else print "unsupported_arch"}') | ||
export OSARCH | ||
|
||
# Detect your operating system and set it as $OSNAME | ||
OSNAME=$(uname -s | awk '{if ($1 == "Darwin") print "darwin"; else if ($1 == "Linux") print "linux"; else print "unsupported_os"}') | ||
export OSNAME | ||
|
||
# Get the latest version URL | ||
LATEST_URL=$(curl -s https://api.github.com/repos/lilypad-tech/lilypad/releases/latest | grep "browser_download_url.*lilypad-$OSNAME-$OSARCH" | cut -d : -f 2,3 | tr -d \") | ||
|
||
# Extract the latest version (including short SHA) from the URL | ||
LATEST_VERSION=$(echo $LATEST_URL | sed -n 's#.*/download/\([^/]*\)/.*#\1#p') | ||
|
||
# Get the current version | ||
CURRENT_VERSION=$(/usr/local/bin/lilypad version | grep "Lilypad:" | awk '{print $2}') | ||
|
||
echo "Current version: $CURRENT_VERSION" | ||
echo "Latest version: $LATEST_VERSION" | ||
|
||
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then | ||
echo "Updating lilypad binary from version $CURRENT_VERSION to $LATEST_VERSION" | ||
sudo systemctl stop lilypad-resource-provider | ||
echo "Stopped the service: sudo systemctl stop lilypad-resource-provider" | ||
|
||
curl -L -o lilypad "$LATEST_URL" | ||
echo "Downloaded the latest version from $LATEST_URL" | ||
|
||
chmod +x lilypad | ||
sudo mv lilypad /usr/local/bin/lilypad | ||
echo "Made the new binary executable and moved it to /usr/local/bin/lilypad" | ||
|
||
sudo systemctl start lilypad-resource-provider | ||
echo "Restarted the service: sudo systemctl start lilypad-resource-provider" | ||
|
||
echo "Update complete." | ||
else | ||
echo "Lilypad binary is already up to date." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Run lilypad-updater every hour | ||
|
||
[Timer] | ||
OnBootSec=10min | ||
OnUnitActiveSec=1h | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Unit] | ||
Description=Check and update Lilypad binary | ||
After=network-online.target | ||
Wants=network-online.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/local/bin/lilypad-updater.sh |