Files
Cursor AgentandFrank Vitrano 7380d7c4b8 Document one-line upgrade via install.sh re-run
Clarify that re-running the curl installer upgrades in place, and detect
an existing install so the script prints an Updating message.

Co-authored-by: Frank Vitrano <WHC2006@users.noreply.github.com>
2026-07-23 14:45:58 +00:00

157 lines
3.9 KiB
Bash

#!/usr/bin/env bash
# miaur one-click installer
# Usage:
# ./install.sh
# ./install.sh --user
# ./install.sh --uninstall
# bash <(curl -fsSL https://raw.githubusercontent.com/<user>/miaur/main/install.sh)
set -euo pipefail
# Override when forking: MIAUR_REPO=https://github.com/you/miaur.git ./install.sh
REPO_URL="${MIAUR_REPO:-https://github.com/WHC2006/miaur.git}"
BRANCH="${MIAUR_BRANCH:-main}"
USER_INSTALL=0
UNINSTALL=0
for arg in "$@"; do
case "$arg" in
--user) USER_INSTALL=1 ;;
--uninstall) UNINSTALL=1 ;;
-h | --help)
cat <<'EOF'
Usage: install.sh [--user] [--uninstall]
(default) Install or upgrade system-wide to /usr/local (needs sudo)
--user Install or upgrade to ~/.local (no sudo for the link)
--uninstall Remove installed miaur
Re-running this script upgrades an existing install in place.
EOF
exit 0
;;
*)
echo "Unknown option: $arg" >&2
exit 1
;;
esac
done
if [[ $USER_INSTALL -eq 1 ]]; then
PREFIX="${HOME}/.local"
SUDO=
else
PREFIX=/usr/local
SUDO=sudo
fi
SHARE_DIR="${PREFIX}/share/miaur"
BIN_LINK="${PREFIX}/bin/miaur"
die() { echo "error: $*" >&2; exit 1; }
need_root_ok() {
if [[ $USER_INSTALL -eq 0 && ${EUID:-$(id -u)} -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || die "sudo is required"
sudo -v || die "sudo authentication failed"
fi
}
uninstall() {
need_root_ok
echo "==> Uninstalling miaur"
$SUDO rm -f "$BIN_LINK"
$SUDO rm -rf "$SHARE_DIR"
echo "Done: removed $BIN_LINK and $SHARE_DIR"
}
install_deps() {
command -v pacman >/dev/null 2>&1 || die "Arch Linux is required (pacman not found)"
echo "==> Installing dependencies"
if [[ ${EUID:-$(id -u)} -eq 0 ]]; then
pacman -S --needed --noconfirm base-devel git curl jq
else
sudo pacman -S --needed --noconfirm base-devel git curl jq
fi
}
# Resolve source tree: current repo, or clone to temp
resolve_src() {
local src=${BASH_SOURCE[0]}
local here=
# `bash <(curl ...)` sets BASH_SOURCE to /dev/fd/N (a pipe). readlink -f then
# yields /proc/PID/fd/pipe:..., and cd fails under set -e before we can clone.
# Only look for a local tree when the installer is a normal on-disk file.
case "$src" in
/dev/fd/* | /proc/*/fd/*) ;;
*)
if here=$(cd "$(dirname "$(readlink -f "$src")")" && pwd); then
if [[ -f $here/miaur && -d $here/lib ]]; then
SRC=$here
return 0
fi
fi
;;
esac
echo "==> Cloning ${REPO_URL} (${BRANCH})"
TMP=$(mktemp -d)
trap 'rm -rf "${TMP:-}"' EXIT
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$TMP/miaur" \
|| die "clone failed; set MIAUR_REPO to the repository URL"
SRC=$TMP/miaur
}
do_install() {
need_root_ok
install_deps
resolve_src
[[ -f $SRC/miaur && -d $SRC/lib ]] || die "incomplete source tree: $SRC"
if [[ -e $BIN_LINK || -d $SHARE_DIR ]]; then
echo "==> Updating existing install at ${SHARE_DIR}"
else
echo "==> Installing to ${SHARE_DIR}"
fi
$SUDO mkdir -p "$SHARE_DIR" "${PREFIX}/bin"
$SUDO rm -rf "$SHARE_DIR"
$SUDO mkdir -p "$SHARE_DIR"
$SUDO cp -a "$SRC/miaur" "$SRC/lib" "$SHARE_DIR/"
if [[ -d $SRC/completions ]]; then
$SUDO cp -a "$SRC/completions" "$SHARE_DIR/"
fi
if [[ -d $SRC/config ]]; then
$SUDO cp -a "$SRC/config" "$SHARE_DIR/"
fi
$SUDO chmod 755 "$SHARE_DIR/miaur"
$SUDO ln -sfn "$SHARE_DIR/miaur" "$BIN_LINK"
# Optional bash completion (system or user)
if [[ -d $SRC/completions ]]; then
if [[ $USER_INSTALL -eq 1 ]]; then
mkdir -p "${HOME}/.local/share/bash-completion/completions"
cp -f "$SRC/completions/miaur.bash" \
"${HOME}/.local/share/bash-completion/completions/miaur" 2>/dev/null || true
else
if [[ -d /usr/share/bash-completion/completions ]]; then
$SUDO cp -f "$SRC/completions/miaur.bash" \
/usr/share/bash-completion/completions/miaur 2>/dev/null || true
fi
fi
fi
echo
echo "Done: $(command -v miaur 2>/dev/null || echo "$BIN_LINK")"
"$BIN_LINK" -V
echo
echo "Try: miaur -Ss foo"
}
if [[ $UNINSTALL -eq 1 ]]; then
uninstall
else
do_install
fi