Skip to content

Commit

Permalink
feat(install): auto updating binary (#213)
Browse files Browse the repository at this point in the history
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
richardbremner authored Jun 30, 2024
1 parent ec2d59b commit ee709d0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ops/lilypad-updater.sh
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
9 changes: 9 additions & 0 deletions ops/systemd/lilpad-updater.timer
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
8 changes: 8 additions & 0 deletions ops/systemd/lilypad-updater.service
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

0 comments on commit ee709d0

Please sign in to comment.