Files
2026-04-29 19:48:14 +00:00

97 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
set -e
SHOW_HELP=0
SPECIFIED_VERSION=""
INSTALL_DIR="/opt/uptimerunner"
GITEA_BASE_URL="https://code.foss.global"
GITEA_REPO="uptime.link/uptimerunner"
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
SHOW_HELP=1
shift
;;
--version)
SPECIFIED_VERSION="$2"
shift 2
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
if [ $SHOW_HELP -eq 1 ]; then
echo "uptimerunner installer"
echo ""
echo "Usage: curl -sSL https://code.foss.global/uptime.link/uptimerunner/raw/branch/main/install.sh | sudo bash"
echo "Options: --version VERSION --install-dir DIR"
exit 0
fi
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit 1
fi
detect_platform() {
local os=$(uname -s)
local arch=$(uname -m)
case "$os" in
Linux) os_name="linux" ;;
Darwin) os_name="macos" ;;
MINGW*|MSYS*|CYGWIN*) os_name="windows" ;;
*) echo "Unsupported operating system: $os"; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) arch_name="x64" ;;
aarch64|arm64) arch_name="arm64" ;;
*) echo "Unsupported architecture: $arch"; exit 1 ;;
esac
if [ "$os_name" = "windows" ]; then
echo "uptimerunner-${os_name}-${arch_name}.exe"
else
echo "uptimerunner-${os_name}-${arch_name}"
fi
}
get_latest_version() {
local response=$(curl -sSL "${GITEA_BASE_URL}/api/v1/repos/${GITEA_REPO}/releases/latest")
local version=$(echo "$response" | grep -o '"tag_name":"[^"]*"' | cut -d'"' -f4)
if [ -z "$version" ]; then
echo "Could not determine latest release version" >&2
exit 1
fi
echo "$version"
}
echo "Installing uptime.link runner..."
BINARY_NAME=$(detect_platform)
VERSION=${SPECIFIED_VERSION:-$(get_latest_version)}
DOWNLOAD_URL="${GITEA_BASE_URL}/${GITEA_REPO}/releases/download/${VERSION}/${BINARY_NAME}"
if systemctl is-active --quiet uptimerunner 2>/dev/null; then
systemctl stop uptimerunner
fi
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
curl -sSL "$DOWNLOAD_URL" -o "$INSTALL_DIR/uptimerunner"
chmod +x "$INSTALL_DIR/uptimerunner"
ln -sf "$INSTALL_DIR/uptimerunner" /usr/local/bin/uptimerunner
echo "Installed /usr/local/bin/uptimerunner"
echo "Configure with: sudo uptimerunner config write --url https://uptime.link --runner-id edge-1 --token <token>"
echo "Install service with: sudo uptimerunner service install && sudo uptimerunner service start"