diff --git a/public/yek.ps1 b/public/yek.ps1 new file mode 100644 index 0000000..d6ef883 --- /dev/null +++ b/public/yek.ps1 @@ -0,0 +1,90 @@ +# install_yek.ps1 +# Install Yek on Windows via PowerShell +param( + [string]$InstallDir = "$HOME\.local\bin" +) + +# Exit on error +$ErrorActionPreference = "Stop" + +Write-Host "Yek Windows Installer" + +if (!(Test-Path -Path $InstallDir)) { + New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null +} + +Write-Host "Selected install directory: $InstallDir" + +# Detect architecture +$arch = $ENV:PROCESSOR_ARCHITECTURE +switch ($arch) { + "AMD64" { $target = "x86_64-pc-windows-msvc" } + "ARM64" { $target = "aarch64-pc-windows-msvc" } + default { + Write-Host "Unsupported or unknown architecture: $arch" + Write-Host "Please build from source or check for a compatible artifact." + exit 1 + } +} + +$repoOwner = "bodo-run" +$repoName = "yek" +$assetName = "yek-$target.zip" + +Write-Host "OS/ARCH => Windows / $arch" +Write-Host "Asset name => $assetName" + +Write-Host "Fetching latest release info from GitHub..." +$releasesUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases/latest" +try { + $releaseData = Invoke-RestMethod -Uri $releasesUrl +} catch { + Write-Host "Failed to fetch release info from GitHub." + Write-Host "Please build from source or check back later." + exit 0 +} + +# Find the asset download URL +$asset = $releaseData.assets | Where-Object { $_.name -eq $assetName } +if (!$asset) { + Write-Host "Failed to find an asset named $assetName in the latest release." + Write-Host "Check that your OS/ARCH is built or consider building from source." + exit 0 +} + +$downloadUrl = $asset.browser_download_url +Write-Host "Downloading from: $downloadUrl" + +$zipPath = Join-Path $env:TEMP $assetName +Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing + +Write-Host "Extracting archive..." +$extractDir = Join-Path $env:TEMP "yek-$($arch)" +if (Test-Path $extractDir) { + Remove-Item -Recurse -Force $extractDir +} +Expand-Archive -Path $zipPath -DestinationPath $extractDir + +Write-Host "Moving binary to $InstallDir..." +$binaryPath = Join-Path $extractDir "yek-$target" "yek.exe" +if (!(Test-Path $binaryPath)) { + Write-Host "yek.exe not found in the extracted folder." + exit 1 +} +Move-Item -Force $binaryPath $InstallDir + +Write-Host "Cleanup temporary files..." +Remove-Item -Force $zipPath +Remove-Item -Recurse -Force $extractDir + +Write-Host "Installation complete!" + +# Check if $InstallDir is in PATH +$pathDirs = $ENV:PATH -split ";" +if ($pathDirs -notcontains (Resolve-Path $InstallDir)) { + Write-Host "NOTE: $InstallDir is not in your PATH. Add it by running something like:" + Write-Host "`$env:Path += `";$(Resolve-Path $InstallDir)`"" + Write-Host "Or update your system's environment variables to persist this." +} + +Write-Host "Now you can run: yek --help" \ No newline at end of file diff --git a/public/yek.sh b/public/yek.sh new file mode 100755 index 0000000..ab9a448 --- /dev/null +++ b/public/yek.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +set -euo pipefail + +REPO_OWNER="bodo-run" +REPO_NAME="yek" + +# Determine a sensible default install directory +# We'll check for a directory in PATH that is writable. +# If none is found, we fall back to "$HOME/.local/bin". +fallback_dir="$HOME/.local/bin" + +# Split PATH on ":" into an array +IFS=':' read -ra path_entries <<<"$PATH" +install_candidates=("/usr/local/bin" "${path_entries[@]}") +install_dir="" + +for dir in "${install_candidates[@]}"; do + # Skip empty paths + [ -z "$dir" ] && continue + + # Check if directory is writable + if [ -d "$dir" ] && [ -w "$dir" ]; then + install_dir="$dir" + break + fi +done + +# If we didn't find a writable dir in PATH, fallback to $HOME/.local/bin +if [ -z "$install_dir" ]; then + install_dir="$fallback_dir" +fi + +mkdir -p "$install_dir" + +echo "Selected install directory: $install_dir" + +# Detect OS and ARCH to choose the correct artifact +OS=$(uname -s) +ARCH=$(uname -m) + +case "${OS}_${ARCH}" in +Linux_x86_64) + TARGET="x86_64-unknown-linux-gnu" + ;; +Darwin_x86_64) + TARGET="x86_64-apple-darwin" + ;; +Darwin_arm64) + TARGET="aarch64-apple-darwin" + ;; +*) + echo "Unsupported OS/ARCH combo: ${OS} ${ARCH}" + echo "Please check the project's releases for a compatible artifact or build from source." + exit 1 + ;; +esac + +ASSET_NAME="yek-${TARGET}.tar.gz" +echo "OS/ARCH => ${TARGET}" +echo "Asset name => ${ASSET_NAME}" + +echo "Fetching latest release info from GitHub..." +LATEST_URL=$( + curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest" | + grep "browser_download_url" | + grep "${ASSET_NAME}" | + cut -d '"' -f 4 +) + +if [ -z "${LATEST_URL}" ]; then + echo "Failed to find a release asset named ${ASSET_NAME} in the latest release." + echo "Check that your OS/ARCH is built or consider building from source." + exit 1 +fi + +echo "Downloading from: ${LATEST_URL}" +curl -L -o "${ASSET_NAME}" "${LATEST_URL}" + +echo "Extracting archive..." +tar xzf "${ASSET_NAME}" + +# The tar will contain a folder named something like: yek-${TARGET}/yek +echo "Moving binary to ${install_dir}..." +mv "yek-${TARGET}/yek" "${install_dir}/yek" + +echo "Making the binary executable..." +chmod +x "${install_dir}/yek" + +# Cleanup +rm -rf "yek-${TARGET}" "${ASSET_NAME}" + +echo "Installation complete!" + +# Check if install_dir is in PATH +if ! echo "$PATH" | tr ':' '\n' | grep -Fx "$install_dir" >/dev/null; then + echo "NOTE: $install_dir is not in your PATH. Add it by running:" + echo " export PATH=\"\$PATH:$install_dir\"" +fi + +echo "Now you can run: yek --help"