#!/usr/bin/env sh # Install the latest onwrite release. # # curl -fsSL https://raw.githubusercontent.com/amartya-dev/onwrite/main/scripts/install.sh | sh # # Set ONWRITE_INSTALL_DIR to choose where the binary lands (default: the first # writable entry among ~/.local/bin, /usr/local/bin). set -eu repo="amartya-dev/onwrite" os="$(uname -s | tr '[:upper:]' '[:lower:]')" arch="$(uname -m)" case "$arch" in x86_64 | amd64) arch="amd64" ;; arm64 | aarch64) arch="arm64" ;; *) echo "onwrite: unsupported architecture: $arch" >&2; exit 1 ;; esac case "$os" in darwin | linux) ;; *) echo "onwrite: unsupported OS: $os — see the releases page" >&2; exit 1 ;; esac version="${ONWRITE_VERSION:-}" if [ -z "$version" ]; then version="$(curl -fsSL "https://api.github.com/repos/$repo/releases/latest" \ | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -1)" fi if [ -z "$version" ]; then echo "onwrite: could not determine the latest version" >&2 exit 1 fi dir="${ONWRITE_INSTALL_DIR:-}" if [ -z "$dir" ]; then for candidate in "$HOME/.local/bin" /usr/local/bin; do if [ -d "$candidate" ] && [ -w "$candidate" ]; then dir="$candidate"; break; fi done fi if [ -z "$dir" ]; then dir="$HOME/.local/bin" mkdir -p "$dir" fi asset="onwrite_${version}_${os}_${arch}.tar.gz" url="https://github.com/$repo/releases/download/$version/$asset" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT echo "onwrite: downloading $version for $os/$arch" curl -fsSL "$url" -o "$tmp/onwrite.tar.gz" tar -xzf "$tmp/onwrite.tar.gz" -C "$tmp" found="$(find "$tmp" -name onwrite -type f | head -1)" if [ -z "$found" ]; then echo "onwrite: the archive did not contain a binary" >&2 exit 1 fi install -m 0755 "$found" "$dir/onwrite" echo "onwrite: installed to $dir/onwrite" case ":$PATH:" in *":$dir:"*) ;; *) echo "onwrite: note that $dir is not on your PATH" ;; esac "$dir/onwrite" --version