-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# install_stop_nagging.ps1 | ||
# Install Stop-Nagging on Windows via PowerShell | ||
param( | ||
[string]$InstallDir = "$HOME\.local\bin" | ||
) | ||
|
||
# Exit on error | ||
$ErrorActionPreference = "Stop" | ||
|
||
Write-Host "Stop-Nagging 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 = "stop-nagging" | ||
$assetName = "stop-nagging-$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 "stop-nagging-$($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 "stop-nagging-$target" "stop-nagging.exe" | ||
if (!(Test-Path $binaryPath)) { | ||
Write-Host "stop-nagging.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: stop-nagging --help" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
REPO_OWNER="bodo-run" | ||
REPO_NAME="stop-nagging" | ||
|
||
# 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="stop-nagging-${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: stop-nagging-${TARGET}/stop-nagging | ||
echo "Moving binary to ${install_dir}..." | ||
mv "stop-nagging-${TARGET}/stop-nagging" "${install_dir}/stop-nagging" | ||
|
||
echo "Making the binary executable..." | ||
chmod +x "${install_dir}/stop-nagging" | ||
|
||
# Cleanup | ||
rm -rf "stop-nagging-${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: stop-nagging --help" |