#!/bin/sh # Install the portbug client on Linux or macOS. No root needed. # # curl -fsSL https://portbug.pckee.com/i.sh | sh # ./install.sh --prefix ~/bin --source ./dist/0.1.0/linux-amd64 # ./install.sh --uninstall # # Installs to ~/.local/bin by default, which is already on PATH on most systems; # if it is not, the script says so rather than editing shell rc files behind # your back. set -eu PREFIX="${PORTBUG_PREFIX:-$HOME/.local/bin}" SOURCE="" BASE_URL="${PORTBUG_BASE_URL:-https://portbug.pckee.com}" UNINSTALL=0 while [ $# -gt 0 ]; do case "$1" in --prefix) PREFIX="$2"; shift 2 ;; --source) SOURCE="$2"; shift 2 ;; --uninstall) UNINSTALL=1; shift ;; -h|--help) sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "unknown option: $1" >&2; exit 2 ;; esac done say() { printf ' %s\n' "$*"; } if [ "$UNINSTALL" = 1 ]; then for b in portbug portbugd portbugctl; do [ -f "$PREFIX/$b" ] && rm -f "$PREFIX/$b" && say "removed $PREFIX/$b" done echo "uninstalled." exit 0 fi os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in linux) os=linux ;; darwin) os=darwin ;; *) echo "portbug: unsupported OS '$os' (Linux and macOS only; Windows uses install.ps1)" >&2; exit 1 ;; esac case "$(uname -m)" in x86_64|amd64) arch=amd64 ;; arm64|aarch64) arch=arm64 ;; *) echo "portbug: unsupported architecture '$(uname -m)'" >&2; exit 1 ;; esac tmp="" cleanup() { [ -n "$tmp" ] && rm -rf "$tmp"; } trap cleanup EXIT if [ -z "$SOURCE" ]; then # Alongside the script first: release archives ship install.sh next to the # binaries, so an offline install just works. here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) if [ -f "$here/portbug" ]; then SOURCE="$here" else SOURCE="$BASE_URL/dl/portbug-$os-$arch.tar.gz" fi fi case "$SOURCE" in http://*|https://*) tmp=$(mktemp -d) say "downloading $SOURCE" if command -v curl >/dev/null 2>&1; then curl -fsSL "$SOURCE" -o "$tmp/portbug.tar.gz" elif command -v wget >/dev/null 2>&1; then wget -qO "$tmp/portbug.tar.gz" "$SOURCE" else echo "portbug: need curl or wget" >&2; exit 1 fi tar -xzf "$tmp/portbug.tar.gz" -C "$tmp" src="$tmp" ;; *.tar.gz) tmp=$(mktemp -d); tar -xzf "$SOURCE" -C "$tmp"; src="$tmp" ;; *) src="$SOURCE" ;; esac if [ ! -f "$src/portbug" ]; then found=$(find "$src" -name portbug -type f 2>/dev/null | head -n 1 || true) [ -n "$found" ] || { echo "portbug: no 'portbug' binary under $src" >&2; exit 1; } src=$(dirname "$found") fi mkdir -p "$PREFIX" for b in portbug portbugd portbugctl; do if [ -f "$src/$b" ]; then install -m 0755 "$src/$b" "$PREFIX/$b" 2>/dev/null || { cp "$src/$b" "$PREFIX/$b"; chmod 0755 "$PREFIX/$b"; } say "$b" fi done say "installed to $PREFIX" case ":$PATH:" in *":$PREFIX:"*) ;; *) echo echo " $PREFIX is not on your PATH. Add this to your shell rc:" echo " export PATH=\"\$PATH:$PREFIX\"" ;; esac echo "$PREFIX/portbug" version echo echo " portbug quick --to --center $BASE_URL"