diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..4ee238d --- /dev/null +++ b/install.ps1 @@ -0,0 +1,28 @@ +$ErrorActionPreference = 'Stop' + +$Repo = 'fluo10/tryluck' +$InstallDir = Join-Path $HOME '.local\bin' + +$Response = Invoke-WebRequest -Uri "https://github.com/$Repo/releases/latest" -MaximumRedirection 0 -ErrorAction Ignore +$Version = $Response.Headers.Location -replace '.*/tag/', '' +if (-not $Version) { + Write-Error 'Failed to fetch latest version.' + exit 1 +} + +New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null + +$Asset = 'tryluck-windows-x86_64.exe' +$Url = "https://github.com/$Repo/releases/download/$Version/$Asset" +$Dest = Join-Path $InstallDir 'tryluck.exe' + +Write-Host "Installing tryluck $Version to $InstallDir..." +Invoke-WebRequest -Uri $Url -OutFile $Dest +Write-Host "Done! $Dest installed." + +$UserPath = [Environment]::GetEnvironmentVariable('PATH', 'User') +if ($UserPath -notlike "*$InstallDir*") { + [Environment]::SetEnvironmentVariable('PATH', "$InstallDir;$UserPath", 'User') + Write-Host "" + Write-Host "Added $InstallDir to your PATH. Restart your terminal to apply." +} diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..b225467 --- /dev/null +++ b/install.sh @@ -0,0 +1,49 @@ +#!/bin/sh +set -eu + +REPO="fluo10/tryluck" +INSTALL_DIR="${HOME}/.local/bin" + +case "$(uname -s)" in + Linux*) OS="linux" ;; + Darwin*) OS="macos" ;; + *) echo "error: unsupported OS: $(uname -s)" >&2; exit 1 ;; +esac + +case "$(uname -m)" in + x86_64) ARCH="x86_64" ;; + aarch64|arm64) ARCH="aarch64" ;; + *) echo "error: unsupported architecture: $(uname -m)" >&2; exit 1 ;; +esac + +VERSION=$(curl -sfI "https://github.com/${REPO}/releases/latest" \ + | awk '/^[Ll]ocation:/{print $2}' \ + | tr -d '\r' \ + | sed 's|.*/tag/||') + +if [ -z "$VERSION" ]; then + echo "error: failed to fetch latest version" >&2 + exit 1 +fi + +mkdir -p "$INSTALL_DIR" + +ASSET="tryluck-${OS}-${ARCH}" +URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}" + +printf "Installing tryluck %s (%s/%s) to %s...\n" "$VERSION" "$OS" "$ARCH" "$INSTALL_DIR" + +TMP=$(mktemp) +curl -fsSL "$URL" -o "$TMP" +chmod +x "$TMP" +mv "$TMP" "${INSTALL_DIR}/tryluck" + +echo "Done! ${INSTALL_DIR}/tryluck installed." + +case ":${PATH}:" in + *":${INSTALL_DIR}:"*) ;; + *) + printf "\nNote: %s is not in PATH. Add to your shell profile:\n" "$INSTALL_DIR" + printf ' export PATH="$HOME/.local/bin:$PATH"\n' + ;; +esac