#!/bin/sh # Hosted bootstrap for https://install.shakerscan.com # Usage: curl -fsSL https://install.shakerscan.com | sh set -eu INSTALL_URL="https://install.shakerscan.com" REPO_RAW_BASE="${SHAKERSCAN_RAW_BASE:-https://raw.githubusercontent.com/andriyze/shakerscan/main}" INSTALL_DIR="${SHAKERSCAN_HOME:-$HOME/.shakerscan}" BIN_DIR="${SHAKERSCAN_BIN_DIR:-$HOME/.local/bin}" START_AFTER_INSTALL="${SHAKERSCAN_START:-1}" REMOTE_ACCESS="${SHAKERSCAN_REMOTE:-0}" say() { printf '%s\n' "$*" } fail() { say "Error: $*" >&2 exit 1 } have() { command -v "$1" >/dev/null 2>&1 } run_sudo() { if [ "$(id -u)" -eq 0 ]; then "$@" elif have sudo; then sudo "$@" else return 1 fi } detect_package_manager() { if have apt-get; then echo apt elif have dnf; then echo dnf elif have yum; then echo yum elif have pacman; then echo pacman elif have zypper; then echo zypper elif have apk; then echo apk else echo "" fi } install_bootstrap_deps() { missing="" for dep in bash curl; do if ! have "$dep"; then missing="$missing $dep" fi done if [ -z "$missing" ]; then return 0 fi manager="$(detect_package_manager)" [ -n "$manager" ] || fail "missing required tools:$missing. Install bash and curl, then re-run $INSTALL_URL" say "Installing bootstrap tools:$missing" case "$manager" in apt) run_sudo apt-get update run_sudo apt-get install -y bash curl ca-certificates ;; dnf|yum) run_sudo "$manager" -y install bash curl ca-certificates ;; pacman) run_sudo pacman -Sy --needed --noconfirm bash curl ca-certificates ;; zypper) run_sudo zypper --non-interactive install bash curl ca-certificates ;; apk) run_sudo apk add bash curl ca-certificates ;; *) fail "unsupported package manager for bootstrap tools: $manager" ;; esac } download() { src="$1" dst="$2" tmp="${dst}.tmp" if ! curl -fsSL "$src" -o "$tmp"; then rm -f "$tmp" fail "failed to download $src" fi mv "$tmp" "$dst" } add_path_to_profile() { profile="$1" [ -n "$profile" ] || return 0 if [ -f "$profile" ] && grep -F "# >>> shakerscan path >>>" "$profile" >/dev/null 2>&1 && grep -F "$BIN_DIR" "$profile" >/dev/null 2>&1; then return 0 fi mkdir -p "$(dirname "$profile")" touch "$profile" { printf '\n' printf '%s\n' '# >>> shakerscan path >>>' printf '%s\n' 'case ":$PATH:" in' printf ' *":%s:"*) ;;\n' "$BIN_DIR" printf ' *) export PATH="%s:$PATH" ;;\n' "$BIN_DIR" printf '%s\n' 'esac' printf '%s\n' '# <<< shakerscan path <<<' } >> "$profile" say "Added $BIN_DIR to PATH in $profile" } install_path_profiles() { shell_name="" if [ -n "${SHELL:-}" ]; then shell_name="$(basename "$SHELL")" fi add_path_to_profile "$HOME/.profile" case "$shell_name" in bash) add_path_to_profile "$HOME/.bashrc" ;; zsh) add_path_to_profile "$HOME/.zshrc" ;; fish) fish_profile="$HOME/.config/fish/config.fish" if [ ! -f "$fish_profile" ] || ! grep -F "# >>> shakerscan path >>>" "$fish_profile" >/dev/null 2>&1 || ! grep -F "$BIN_DIR" "$fish_profile" >/dev/null 2>&1; then mkdir -p "$(dirname "$fish_profile")" touch "$fish_profile" { printf '\n' printf '%s\n' '# >>> shakerscan path >>>' printf 'fish_add_path "%s"\n' "$BIN_DIR" printf '%s\n' '# <<< shakerscan path <<<' } >> "$fish_profile" say "Added $BIN_DIR to PATH in $fish_profile" fi ;; esac if [ -f "$HOME/.bashrc" ] && [ "$shell_name" != "bash" ]; then add_path_to_profile "$HOME/.bashrc" fi if [ -f "$HOME/.zshrc" ] && [ "$shell_name" != "zsh" ]; then add_path_to_profile "$HOME/.zshrc" fi } PATH_NEEDS_ACTIVATION=0 install_command() { mkdir -p "$BIN_DIR" launcher="$BIN_DIR/shakerscan" cat > "$launcher" <