Skip to content

Commit 8b6a5e7

Browse files
committed
add yek scripts
1 parent e3f665f commit 8b6a5e7

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

public/yek.ps1

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# install_yek.ps1
2+
# Install Yek on Windows via PowerShell
3+
param(
4+
[string]$InstallDir = "$HOME\.local\bin"
5+
)
6+
7+
# Exit on error
8+
$ErrorActionPreference = "Stop"
9+
10+
Write-Host "Yek Windows Installer"
11+
12+
if (!(Test-Path -Path $InstallDir)) {
13+
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
14+
}
15+
16+
Write-Host "Selected install directory: $InstallDir"
17+
18+
# Detect architecture
19+
$arch = $ENV:PROCESSOR_ARCHITECTURE
20+
switch ($arch) {
21+
"AMD64" { $target = "x86_64-pc-windows-msvc" }
22+
"ARM64" { $target = "aarch64-pc-windows-msvc" }
23+
default {
24+
Write-Host "Unsupported or unknown architecture: $arch"
25+
Write-Host "Please build from source or check for a compatible artifact."
26+
exit 1
27+
}
28+
}
29+
30+
$repoOwner = "bodo-run"
31+
$repoName = "yek"
32+
$assetName = "yek-$target.zip"
33+
34+
Write-Host "OS/ARCH => Windows / $arch"
35+
Write-Host "Asset name => $assetName"
36+
37+
Write-Host "Fetching latest release info from GitHub..."
38+
$releasesUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases/latest"
39+
try {
40+
$releaseData = Invoke-RestMethod -Uri $releasesUrl
41+
} catch {
42+
Write-Host "Failed to fetch release info from GitHub."
43+
Write-Host "Please build from source or check back later."
44+
exit 0
45+
}
46+
47+
# Find the asset download URL
48+
$asset = $releaseData.assets | Where-Object { $_.name -eq $assetName }
49+
if (!$asset) {
50+
Write-Host "Failed to find an asset named $assetName in the latest release."
51+
Write-Host "Check that your OS/ARCH is built or consider building from source."
52+
exit 0
53+
}
54+
55+
$downloadUrl = $asset.browser_download_url
56+
Write-Host "Downloading from: $downloadUrl"
57+
58+
$zipPath = Join-Path $env:TEMP $assetName
59+
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
60+
61+
Write-Host "Extracting archive..."
62+
$extractDir = Join-Path $env:TEMP "yek-$($arch)"
63+
if (Test-Path $extractDir) {
64+
Remove-Item -Recurse -Force $extractDir
65+
}
66+
Expand-Archive -Path $zipPath -DestinationPath $extractDir
67+
68+
Write-Host "Moving binary to $InstallDir..."
69+
$binaryPath = Join-Path $extractDir "yek-$target" "yek.exe"
70+
if (!(Test-Path $binaryPath)) {
71+
Write-Host "yek.exe not found in the extracted folder."
72+
exit 1
73+
}
74+
Move-Item -Force $binaryPath $InstallDir
75+
76+
Write-Host "Cleanup temporary files..."
77+
Remove-Item -Force $zipPath
78+
Remove-Item -Recurse -Force $extractDir
79+
80+
Write-Host "Installation complete!"
81+
82+
# Check if $InstallDir is in PATH
83+
$pathDirs = $ENV:PATH -split ";"
84+
if ($pathDirs -notcontains (Resolve-Path $InstallDir)) {
85+
Write-Host "NOTE: $InstallDir is not in your PATH. Add it by running something like:"
86+
Write-Host "`$env:Path += `";$(Resolve-Path $InstallDir)`""
87+
Write-Host "Or update your system's environment variables to persist this."
88+
}
89+
90+
Write-Host "Now you can run: yek --help"

public/yek.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
REPO_OWNER="bodo-run"
5+
REPO_NAME="yek"
6+
7+
# Determine a sensible default install directory
8+
# We'll check for a directory in PATH that is writable.
9+
# If none is found, we fall back to "$HOME/.local/bin".
10+
fallback_dir="$HOME/.local/bin"
11+
12+
# Split PATH on ":" into an array
13+
IFS=':' read -ra path_entries <<<"$PATH"
14+
install_candidates=("/usr/local/bin" "${path_entries[@]}")
15+
install_dir=""
16+
17+
for dir in "${install_candidates[@]}"; do
18+
# Skip empty paths
19+
[ -z "$dir" ] && continue
20+
21+
# Check if directory is writable
22+
if [ -d "$dir" ] && [ -w "$dir" ]; then
23+
install_dir="$dir"
24+
break
25+
fi
26+
done
27+
28+
# If we didn't find a writable dir in PATH, fallback to $HOME/.local/bin
29+
if [ -z "$install_dir" ]; then
30+
install_dir="$fallback_dir"
31+
fi
32+
33+
mkdir -p "$install_dir"
34+
35+
echo "Selected install directory: $install_dir"
36+
37+
# Detect OS and ARCH to choose the correct artifact
38+
OS=$(uname -s)
39+
ARCH=$(uname -m)
40+
41+
case "${OS}_${ARCH}" in
42+
Linux_x86_64)
43+
TARGET="x86_64-unknown-linux-gnu"
44+
;;
45+
Darwin_x86_64)
46+
TARGET="x86_64-apple-darwin"
47+
;;
48+
Darwin_arm64)
49+
TARGET="aarch64-apple-darwin"
50+
;;
51+
*)
52+
echo "Unsupported OS/ARCH combo: ${OS} ${ARCH}"
53+
echo "Please check the project's releases for a compatible artifact or build from source."
54+
exit 1
55+
;;
56+
esac
57+
58+
ASSET_NAME="yek-${TARGET}.tar.gz"
59+
echo "OS/ARCH => ${TARGET}"
60+
echo "Asset name => ${ASSET_NAME}"
61+
62+
echo "Fetching latest release info from GitHub..."
63+
LATEST_URL=$(
64+
curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest" |
65+
grep "browser_download_url" |
66+
grep "${ASSET_NAME}" |
67+
cut -d '"' -f 4
68+
)
69+
70+
if [ -z "${LATEST_URL}" ]; then
71+
echo "Failed to find a release asset named ${ASSET_NAME} in the latest release."
72+
echo "Check that your OS/ARCH is built or consider building from source."
73+
exit 1
74+
fi
75+
76+
echo "Downloading from: ${LATEST_URL}"
77+
curl -L -o "${ASSET_NAME}" "${LATEST_URL}"
78+
79+
echo "Extracting archive..."
80+
tar xzf "${ASSET_NAME}"
81+
82+
# The tar will contain a folder named something like: yek-${TARGET}/yek
83+
echo "Moving binary to ${install_dir}..."
84+
mv "yek-${TARGET}/yek" "${install_dir}/yek"
85+
86+
echo "Making the binary executable..."
87+
chmod +x "${install_dir}/yek"
88+
89+
# Cleanup
90+
rm -rf "yek-${TARGET}" "${ASSET_NAME}"
91+
92+
echo "Installation complete!"
93+
94+
# Check if install_dir is in PATH
95+
if ! echo "$PATH" | tr ':' '\n' | grep -Fx "$install_dir" >/dev/null; then
96+
echo "NOTE: $install_dir is not in your PATH. Add it by running:"
97+
echo " export PATH=\"\$PATH:$install_dir\""
98+
fi
99+
100+
echo "Now you can run: yek --help"

0 commit comments

Comments
 (0)