#!/usr/bin/env sh # Official installer for superpenguin. # Source: https://install.superpenguin.ai # # curl -fsSL https://install.superpenguin.ai | sh # # Detects OS/arch, fetches latest.json from the CLI's release prefix, # downloads the matching tarball, SHA-256 verifies it, extracts to # ~/.local/share/okibi/clis/superpenguin/versions//, and # symlinks the binary into ~/.local/bin and its version-matched Agent Skill # into ~/.agents/skills, then links it into detected agents' native skill # directories. Identity-enabled archives also carry a compatible # okibi-auth helper beside that CLI. The generated CLI prefers a separately # verified canonical helper when one exists, otherwise it uses this bundled # copy. Idempotent — re-running upgrades the CLI and its managed skill to # latest.json together. # # Env overrides: # SUPERPENGUIN_RELEASE_BASE Release prefix URL (default baked at serve time). # SUPERPENGUIN_UPDATE_URL Stable public update channel (default baked at serve time). # SUPERPENGUIN_INSTALL_ROOT Install dir (default ~/.local/share/okibi). # SUPERPENGUIN_BIN_DIR Symlink dir (default ~/.local/bin). # SUPERPENGUIN_SKILLS_DIR Agent Skills dir (default ~/.agents/skills). # SUPERPENGUIN_NO_PROMPT Set to 1 to never be asked to remove another # copy found on PATH. The prompt waits for y or n # with no time limit, so set this when installing # from an agent or script in a real terminal. The # copies and how to remove them still print. # # The installer writes private, NUL-delimited update metadata beside both the # versioned binary and stable launcher. New generated binaries use it for a # fail-open update check after commands, at most once every four hours in normal # operation. When available, newly generated CLIs expose # `superpenguin self-update` to check and install immediately, or # `superpenguin self-update --check` to check without installing. `update` # is an alias when no service command uses it. # No release token is written to shell config. set -eu CLI_NAME='superpenguin' OWNERSHIP_ID='jd74rswq6f1pxepkq7az3gxg8x8ek3q1' DEFAULT_RELEASE_BASE='https://releases.okibi.ai/clis/christopher18/superpenguin/r/39c1f9da637e2325e952ff1de7371832f069f4378741c26d' RELEASE_BASE="${SUPERPENGUIN_RELEASE_BASE:-$DEFAULT_RELEASE_BASE}" DEFAULT_UPDATE_URL='https://okibi.ai/i/cli/jd74rswq6f1pxepkq7az3gxg8x8ek3q1' UPDATE_URL="${SUPERPENGUIN_UPDATE_URL:-$DEFAULT_UPDATE_URL}" INSTALL_ROOT="${SUPERPENGUIN_INSTALL_ROOT:-$HOME/.local/share/okibi}" BIN_DIR="${SUPERPENGUIN_BIN_DIR:-$HOME/.local/bin}" SKILLS_DIR="${SUPERPENGUIN_SKILLS_DIR:-$HOME/.agents/skills}" err() { printf 'install: %s\n' "$*" >&2; exit 1; } info() { printf 'install: %s\n' "$*"; } # The ownership id recorded in a .okibi-update file, its sixth field. okibi_metadata_owner() { tr '\000' '\n' <"$1" | sed -n '6p' } absolute_dir() { mkdir -p "$1" (CDPATH='' cd -P -- "$1" && pwd -P) } INSTALL_ROOT="$(absolute_dir "$INSTALL_ROOT")" BIN_DIR="$(absolute_dir "$BIN_DIR")" SKILLS_DIR="$(absolute_dir "$SKILLS_DIR")" # Whether a symlink points into this CLI's own versions directory, as one # left by an installer from before ownership ids or by a local build does. links_into_own_versions() { [ -L "$1" ] || return 1 link_target="$(readlink "$1" 2>/dev/null)" || return 1 case "$link_target" in /*) ;; *) link_target="$(dirname "$1")/$link_target" ;; esac link_dir="$(CDPATH='' cd -P -- "$(dirname "$link_target")" 2>/dev/null && pwd -P)" \ || return 1 case "$link_dir/" in "$INSTALL_ROOT/clis/$CLI_NAME/versions/"*) return 0 ;; esac return 1 } if [ -e "$BIN_DIR/$CLI_NAME" ] || [ -L "$BIN_DIR/$CLI_NAME" ]; then existing_owner='' if [ -f "$BIN_DIR/$CLI_NAME.okibi-update" ]; then existing_owner="$(okibi_metadata_owner "$BIN_DIR/$CLI_NAME.okibi-update")" fi if [ "$existing_owner" != "$OWNERSHIP_ID" ]; then # An install with no recorded owner is ours to upgrade when it links into # our versions directory; one recorded for another CLI never is. { [ -z "$existing_owner" ] && links_into_own_versions "$BIN_DIR/$CLI_NAME"; } \ || err "$BIN_DIR/$CLI_NAME is already occupied by another installation" fi fi link_detected_agent_skill() { agent_name="$1" agent_home="$2" [ -d "$agent_home" ] || return 0 agent_skills="$agent_home/skills" agent_dest="$agent_skills/$SKILL_NAME" [ "$agent_dest" = "$SKILL_DEST" ] && return 0 if [ -L "$agent_dest" ]; then agent_target="$(readlink "$agent_dest" 2>/dev/null || true)" [ "$agent_target" != "$SKILL_DEST" ] || return 0 fi if [ -f "$agent_dest/.okibi-owner" ] \ && [ "$(cat "$agent_dest/.okibi-owner")" = "$OWNERSHIP_ID" ]; then rm -rf "$agent_dest" elif [ -e "$agent_dest" ] || [ -L "$agent_dest" ]; then info "NOTE: $agent_name skill not linked because $agent_dest already exists and is not managed by $CLI_NAME" return 0 fi mkdir -p "$agent_skills" ln -s "$SKILL_DEST" "$agent_dest" info "linked Agent Skill for $agent_name at $agent_dest" } link_detected_agent_skills() { claude_home="${CLAUDE_CONFIG_DIR:-$HOME/.claude}" codex_home="${CODEX_HOME:-$HOME/.codex}" config_home="${XDG_CONFIG_HOME:-$HOME/.config}" link_detected_agent_skill 'Claude Code' "$claude_home" link_detected_agent_skill 'Codex' "$codex_home" link_detected_agent_skill 'Cursor' "$HOME/.cursor" link_detected_agent_skill 'Gemini CLI' "$HOME/.gemini" link_detected_agent_skill 'GitHub Copilot' "$HOME/.copilot" link_detected_agent_skill 'Windsurf' "$HOME/.codeium/windsurf" link_detected_agent_skill 'OpenCode' "$config_home/opencode" } command -v curl >/dev/null 2>&1 || err 'curl is required' command -v tar >/dev/null 2>&1 || err 'tar is required' detect_platform() { os='' arch='' case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) err "unsupported OS: $(uname -s) (this installer ships macOS and Linux builds; Windows: append .ps1 to the install URL)" ;; esac case "$(uname -m)" in arm64 | aarch64) arch=arm64 ;; x86_64 | amd64) arch=x64 ;; *) err "unsupported architecture: $(uname -m)" ;; esac printf '%s-%s' "$os" "$arch" } # Bare-bones JSON extraction — avoids requiring jq. Pulls `field` from the # artifact object whose "platform" matches. Fragile by design: latest.json # is written by Okibi's publish pipeline with a fixed shape. extract_json_field() { platform="$1" field="$2" file="$3" tr -d '\n' <"$file" \ | grep -o "{[^{}]*\"platform\"[[:space:]]*:[[:space:]]*\"$platform\"[^{}]*}" \ | grep -o "\"$field\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" \ | head -1 \ | sed -E "s/.*\"$field\"[[:space:]]*:[[:space:]]*\"([^\"]*)\".*/\\1/" } extract_json_string() { field="$1" file="$2" tr -d '\n' <"$file" \ | grep -o "\"$field\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" \ | head -1 \ | sed -E "s/.*\"$field\"[[:space:]]*:[[:space:]]*\"([^\"]*)\".*/\\1/" } verify_sha256() { file="$1" expected="$2" if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$file" | awk '{print $1}')" elif command -v shasum >/dev/null 2>&1; then actual="$(shasum -a 256 "$file" | awk '{print $1}')" else err 'no sha256sum or shasum available to verify the download' fi [ "$actual" = "$expected" ] \ || err "checksum mismatch: expected $expected, got $actual" } PLATFORM="$(detect_platform)" info "platform: $PLATFORM" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT MANIFEST="$TMP/latest.json" info "fetching $RELEASE_BASE/latest.json" curl -fsSL "$RELEASE_BASE/latest.json" -o "$MANIFEST" \ || err "could not reach the release host at $RELEASE_BASE" VERSION="$(extract_json_string version "$MANIFEST")" [ -n "$VERSION" ] || err 'latest.json is missing a version field' BINARY_NAME="$(extract_json_string binaryName "$MANIFEST")" [ -z "$BINARY_NAME" ] || [ "$BINARY_NAME" = "$CLI_NAME" ] \ || err 'latest.json does not match this CLI name' # The version becomes a path segment that is rm -rf'd below, so a hostile or # corrupt manifest must not be able to smuggle in path separators or "..". case "$VERSION" in *[!A-Za-z0-9._+-]* | *..*) err "latest.json has an unsafe version string: $VERSION" ;; esac # Only the manifest's explicit public version describes the binary. Older # builds may report 1.0.0 regardless of hosted revision, so never infer it. RELEASE_VERSION="$(extract_json_string releaseVersion "$MANIFEST")" VERSION_LABEL='' if printf '%s' "$RELEASE_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then VERSION_LABEL=" v$RELEASE_VERSION" fi URL="$(extract_json_field "$PLATFORM" url "$MANIFEST")" SHA="$(extract_json_field "$PLATFORM" sha256 "$MANIFEST")" [ -n "$URL" ] || err "no $CLI_NAME build published for $PLATFORM yet" [ -n "$SHA" ] || err "latest.json has no checksum for $PLATFORM" # skillName was added after generated CLI installers first shipped. Old # immutable releases remain installable; current releases carry the skill in # the same checksummed archive as the binary. SKILL_NAME="$(extract_json_string skillName "$MANIFEST")" SKILL_DEST='' SKILL_DEST_MANAGED=0 if [ -n "$SKILL_NAME" ]; then case "$SKILL_NAME" in *[!a-z0-9-]* | -* | *-) err "latest.json has an unsafe skill name: $SKILL_NAME" ;; esac SKILL_DEST="$SKILLS_DIR/$SKILL_NAME" if [ -f "$SKILL_DEST/.okibi-owner" ] \ && [ "$(cat "$SKILL_DEST/.okibi-owner")" = "$OWNERSHIP_ID" ]; then SKILL_DEST_MANAGED=1 elif [ -L "$SKILL_DEST" ]; then existing_target="$(readlink "$SKILL_DEST" 2>/dev/null || true)" case "$existing_target" in "$INSTALL_ROOT"/clis/"$CLI_NAME"/versions/*/skills/"$SKILL_NAME") SKILL_DEST_MANAGED=1 ;; esac fi if { [ -e "$SKILL_DEST" ] || [ -L "$SKILL_DEST" ]; } \ && [ "$SKILL_DEST_MANAGED" -ne 1 ]; then err "$SKILL_DEST is already occupied by another installation" fi fi # Relative URLs resolve against the release base. case "$URL" in http://* | https://*) ;; *) URL="$RELEASE_BASE/$URL" ;; esac TARBALL="$TMP/$CLI_NAME.tar.gz" info "downloading $CLI_NAME$VERSION_LABEL" curl -fsSL "$URL" -o "$TARBALL" || err 'download failed' verify_sha256 "$TARBALL" "$SHA" info 'checksum verified' VERSION_DIR="$INSTALL_ROOT/clis/$CLI_NAME/versions/$VERSION" rm -rf "$VERSION_DIR" mkdir -p "$VERSION_DIR" # Okibi CLI tarballs are flat: the binary at the archive root. tar -xzf "$TARBALL" -C "$VERSION_DIR" [ -f "$VERSION_DIR/$CLI_NAME" ] || err "archive did not contain a $CLI_NAME binary" chmod +x "$VERSION_DIR/$CLI_NAME" 2>/dev/null || true [ ! -f "$VERSION_DIR/okibi-auth" ] || chmod +x "$VERSION_DIR/okibi-auth" 2>/dev/null || true info "installed to $VERSION_DIR" # NUL delimiters preserve spaces and shell metacharacters without asking the # generated binary to evaluate a config file as code. printf '%s\0%s\0%s\0%s\0%s\0%s\0' \ "$RELEASE_BASE" "$UPDATE_URL" "$INSTALL_ROOT" "$BIN_DIR" "$SKILLS_DIR" "$OWNERSHIP_ID" \ > "$VERSION_DIR/.okibi-update" chmod 600 "$VERSION_DIR/.okibi-update" 2>/dev/null || true if [ -n "$SKILL_NAME" ]; then SKILL_SOURCE="$VERSION_DIR/skills/$SKILL_NAME" [ -f "$SKILL_SOURCE/SKILL.md" ] \ || err "archive did not contain skills/$SKILL_NAME/SKILL.md" grep -Eq "^name:[[:space:]]*$SKILL_NAME[[:space:]]*$" "$SKILL_SOURCE/SKILL.md" \ || err "bundled SKILL.md name does not match $SKILL_NAME" [ -f "$SKILL_SOURCE/.okibi-managed" ] \ && [ "$(cat "$SKILL_SOURCE/.okibi-managed")" = "$CLI_NAME" ] \ || err "bundled skill is missing its Okibi ownership marker" if [ -f "$SKILL_SOURCE/.okibi-owner" ]; then [ "$(cat "$SKILL_SOURCE/.okibi-owner")" = "$OWNERSHIP_ID" ] \ || err "bundled skill has the wrong Okibi ownership identity" else printf '%s\n' "$OWNERSHIP_ID" > "$SKILL_SOURCE/.okibi-owner" fi mkdir -p "$SKILLS_DIR" if [ "$SKILL_DEST_MANAGED" -eq 1 ]; then rm -rf "$SKILL_DEST" fi SKILL_SOURCE="$(cd "$SKILL_SOURCE" && pwd)" ln -s "$SKILL_SOURCE" "$SKILL_DEST" info "installed Agent Skill to $SKILL_DEST" link_detected_agent_skills else info "NOTE: this older release has no bundled Agent Skill" fi mkdir -p "$BIN_DIR" ln -sfn "$VERSION_DIR/$CLI_NAME" "$BIN_DIR/$CLI_NAME" printf '%s\0%s\0%s\0%s\0%s\0%s\0' \ "$RELEASE_BASE" "$UPDATE_URL" "$INSTALL_ROOT" "$BIN_DIR" "$SKILLS_DIR" "$OWNERSHIP_ID" \ > "$BIN_DIR/$CLI_NAME.okibi-update" chmod 600 "$BIN_DIR/$CLI_NAME.okibi-update" 2>/dev/null || true info "symlinked $BIN_DIR/$CLI_NAME" if [ -f "$VERSION_DIR/okibi-auth" ]; then info "installed bundled Identity helper beside $CLI_NAME" fi # A direct install after a rename replaces older managed names for this same # immutable CLI id. Reused names owned by another CLI have different metadata # and are left untouched. find "$BIN_DIR" -maxdepth 1 -type f -name '*.okibi-update' 2>/dev/null | while IFS= read -r metadata; do [ "$metadata" = "$BIN_DIR/$CLI_NAME.okibi-update" ] && continue owner="$(okibi_metadata_owner "$metadata")" [ "$owner" = "$OWNERSHIP_ID" ] || continue old_name="$(basename "$metadata" .okibi-update)" rm -f "$BIN_DIR/$old_name" "$BIN_DIR/$old_name-okibi-auth" "$metadata" rm -rf "$INSTALL_ROOT/clis/$old_name" rm -rf "$HOME/.config/$old_name" "$HOME/.local/share/$old_name" "$HOME/.cache/$old_name" done find "$SKILLS_DIR" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | while IFS= read -r installed_skill; do [ "$installed_skill" = "$SKILL_DEST" ] && continue [ -f "$installed_skill/.okibi-owner" ] || continue [ "$(cat "$installed_skill/.okibi-owner")" = "$OWNERSHIP_ID" ] || continue rm -rf "$installed_skill" done remove_retired_agent_skills() { agent_home="$1" [ -d "$agent_home/skills" ] || return 0 find "$agent_home/skills" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) 2>/dev/null | while IFS= read -r installed_skill; do [ "$installed_skill" = "$agent_home/skills/$SKILL_NAME" ] && continue [ -f "$installed_skill/.okibi-owner" ] || continue [ "$(cat "$installed_skill/.okibi-owner")" = "$OWNERSHIP_ID" ] || continue rm -rf "$installed_skill" done } remove_retired_agent_skills "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" remove_retired_agent_skills "${CODEX_HOME:-$HOME/.codex}" remove_retired_agent_skills "$HOME/.cursor" remove_retired_agent_skills "$HOME/.gemini" remove_retired_agent_skills "$HOME/.copilot" remove_retired_agent_skills "$HOME/.codeium/windsurf" remove_retired_agent_skills "${XDG_CONFIG_HOME:-$HOME/.config}/opencode" # Another command with this name elsewhere on PATH (for example an earlier # vendor CLI installed with `go install`) either runs instead of this install # when it comes first, or lingers in terminals that were already open: shells # remember where they last found a command and never search PATH for it again # until `hash -r`. This script runs in a child process and can fix neither, so # it names each copy and, when it can tell, what installed it and how to # remove it. When that removal needs no sudo and someone is at the terminal, # it asks, and a y runs it. canonical_dir() { (CDPATH='' cd -P -- "$1" 2>/dev/null && pwd -P) || true } # Prints the file a path finally names after following every symlink. resolve_path() { resolved="$1" resolve_hops=0 while [ -L "$resolved" ] && [ "$resolve_hops" -lt 40 ]; do resolve_link="$(readlink "$resolved" 2>/dev/null || true)" [ -n "$resolve_link" ] || break case "$resolve_link" in /*) resolved="$resolve_link" ;; *) resolved="$(dirname "$resolved")/$resolve_link" ;; esac resolve_hops=$((resolve_hops + 1)) done resolved_dir="$(canonical_dir "$(dirname "$resolved")")" if [ -n "$resolved_dir" ]; then resolved="$resolved_dir/$(basename "$resolved")" fi printf '%s' "$resolved" } shell_quote() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")" } # A path as it should be typed: quoted only when it needs to be. display_path() { case "$1" in *[!A-Za-z0-9_./+-]*) shell_quote "$1" ;; *) printf '%s' "$1" ;; esac } # The directories Go itself installs into, computed at most once with a # single `go env`. Go runs from / with the local toolchain, so a go.mod in # the current directory can never make it download another toolchain in the # middle of an install. Without Go, nothing is attributed to it. GO_BIN_DIRS='' GO_BIN_DIRS_LOADED=0 load_go_bin_dirs() { [ "$GO_BIN_DIRS_LOADED" -eq 0 ] || return 0 GO_BIN_DIRS_LOADED=1 command -v go >/dev/null 2>&1 || return 0 go_env="$( (CDPATH='' cd -P / && GOTOOLCHAIN=local go env GOBIN GOPATH) 2>/dev/null || true)" GO_BIN_DIRS="$( { printf '%s\n' "$go_env" | sed -n '1p' printf '%s\n' "$go_env" | sed -n '2p' | tr ':' '\n' | sed '/^$/d; s|$|/bin|' } | while IFS= read -r go_dir; do if [ -n "$go_dir" ]; then canonical_dir "$go_dir"; fi done)" } # `go install module/path@version` builds from the module cache, the only # kind of build that records its main module with an h1: checksum. Release # archives, local builds and other installers never do. built_by_go_install() { (CDPATH='' cd -P / && GOTOOLCHAIN=local go version -m "$1") 2>/dev/null \ | awk '$1 == "mod" && $4 ~ /^h1:/ { found = 1 } END { exit !found }' } # Sets COPY_ADVICE, the line that says what installed a copy and how to # remove it, given the copy, its canonical directory and the file it # finally resolves to. When the removal is a single command this script # knows, it is recorded once in COPY_REMOVAL (rm or brew), COPY_REMOVAL_TARGET # (the path or formula) and COPY_BREW (which brew), so the advice, the # prompt and what runs cannot drift apart. COPY_RUNNABLE is 1 when this # script may run it itself: no sudo, and only what the copy's own installer # would do. classify_copy() { copy="$1" copy_dir="$2" copy_resolved="$3" COPY_ADVICE='Uninstall it with the tool that installed it.' COPY_REMOVAL='' COPY_REMOVAL_TARGET='' COPY_REMOVAL_METADATA='' COPY_REMOVAL_HELPER='' COPY_BREW='' COPY_RUNNABLE=0 case "$copy_resolved" in "$INSTALL_ROOT/clis/$CLI_NAME/"*) # A link can go; a PATH entry inside the install root names this # installer's own file, so the entry is what should go instead. if [ -L "$copy" ]; then removal_by_rm "$copy" "$copy_dir" # A former bin dir of this CLI also holds its update metadata, and # may hold the Identity helper link older installers put beside it. if [ -f "$copy.okibi-update" ] \ && [ "$(okibi_metadata_owner "$copy.okibi-update")" = "$OWNERSHIP_ID" ]; then COPY_REMOVAL_METADATA="$copy.okibi-update" if [ -L "$copy-okibi-auth" ]; then case "$(resolve_path "$copy-okibi-auth")" in "$INSTALL_ROOT/clis/$CLI_NAME/"*) COPY_REMOVAL_HELPER="$copy-okibi-auth" ;; esac fi fi COPY_ADVICE="It links to an older version of this install. To remove it: $(removal_command)" else COPY_ADVICE="It is an older version inside this install. Remove $(display_path "$(dirname "$copy")") from your PATH." fi return 0 ;; */Caskroom/*/*) # Never run: uninstalling a cask can run its own sudo steps. COPY_ADVICE="It was installed by Homebrew. To remove it: brew uninstall --cask $(printf '%s' "$copy_resolved" | sed 's|.*/Caskroom/\([^/]*\)/.*|\1|')" return 0 ;; /nix/store/*) COPY_ADVICE='It was installed by Nix; remove it there.' return 0 ;; esac if homebrew_formula_command "$copy"; then # Homebrew marks a formula's current keg with an opt/ link. brew_current='' if [ -L "$BREW_PREFIX/opt/$BREW_FORMULA" ]; then brew_current="$(canonical_dir "$BREW_PREFIX/opt/$BREW_FORMULA")" fi # The brew that owns this Cellar, not whichever brew is first on PATH: # a Mac can have both /usr/local and /opt/homebrew. COPY_BREW='brew' brew_owned=0 if [ -x "$BREW_PREFIX/bin/brew" ]; then COPY_BREW="$BREW_PREFIX/bin/brew" brew_owned=1 fi # brew uninstall removes the current keg, so an older one would stay. if [ -n "$brew_current" ] && [ "$brew_current" != "$BREW_KEG" ]; then COPY_ADVICE="It is an older Homebrew version of $BREW_FORMULA. To remove it: $(display_path "$COPY_BREW") cleanup $(display_path "$BREW_FORMULA")" return 0 fi COPY_REMOVAL='brew' COPY_REMOVAL_TARGET="$BREW_FORMULA" # Run only for a real keg (it has an install receipt) that is the # formula's current one, reached through Homebrew's own bin or straight # through the keg's, so a link the user made elsewhere never costs them # the whole formula, and only when this user can write what brew # uninstall changes. if [ "$brew_owned" -eq 1 ] \ && [ -f "$BREW_KEG/INSTALL_RECEIPT.json" ] \ && [ "$brew_current" = "$BREW_KEG" ] \ && { [ "$copy_dir" = "$BREW_PREFIX/bin" ] \ || [ "$copy_dir" = "$BREW_KEG/bin" ]; } \ && [ -w "$BREW_PREFIX/Cellar/$BREW_FORMULA" ] \ && [ -w "$BREW_PREFIX/bin" ]; then COPY_RUNNABLE=1 fi COPY_ADVICE="It was installed by Homebrew. To remove it: $(removal_command)" return 0 fi # Ask the package database about the copy itself, never the file a link # leads to: /snap/bin commands all link to /usr/bin/snap, which would # blame snapd. A diverted path holds whatever the diversion put there, # not the listed package's file, so it stays unattributed, as does a path # dpkg would read as a wildcard pattern. case "$copy" in *'*'* | *'?'* | *'['* | *'\'*) ;; *) if command -v dpkg >/dev/null 2>&1; then dpkg_owners="$(dpkg -S "$copy" 2>/dev/null || true)" case "$dpkg_owners" in *'diversion '*) return 0 ;; esac copy_package="$(printf '%s\n' "$dpkg_owners" | sed -n 's/[,:].*//p' | head -n 1)" if [ -n "$copy_package" ]; then COPY_ADVICE="It was installed by a system package. To remove it: sudo apt-get remove $copy_package" return 0 fi fi ;; esac if command -v rpm >/dev/null 2>&1 \ && copy_package="$(rpm -qf --qf '%{NAME}\n' "$copy" 2>/dev/null)"; then COPY_ADVICE="It was installed by a system package. To remove it: sudo rpm -e $(printf '%s\n' "$copy_package" | head -n 1)" return 0 fi load_go_bin_dirs if [ -f "$copy" ] && [ ! -L "$copy" ] \ && printf '%s\n' "$GO_BIN_DIRS" | grep -Fxq "$copy_dir" \ && built_by_go_install "$copy"; then removal_by_rm "$copy" "$copy_dir" COPY_ADVICE="It was installed by go install. To remove it: $(removal_command)" fi } # Sets BREW_PREFIX, BREW_FORMULA and BREW_KEG when a copy is a formula's # command, /Cellar///bin/: either the copy # itself (a keg's bin on PATH, often through opt//bin) or the file # its link from Homebrew's bin names. That keg file may link on into # libexec, as Python and Node formulae do, while another tool's script # elsewhere in a keg (a framework's bin) is never either. Homebrew keeps no # per-file record, so the path's shape is the evidence. homebrew_formula_command() { brew_copy_dir="$(canonical_dir "$(dirname "$1")")" [ -n "$brew_copy_dir" ] || return 1 homebrew_keg_command "$brew_copy_dir/$(basename "$1")" && return 0 [ -L "$1" ] || return 1 brew_link="$(readlink "$1" 2>/dev/null || true)" case "$brew_link" in '') return 1 ;; /*) ;; *) brew_link="$brew_copy_dir/$brew_link" ;; esac brew_link_dir="$(canonical_dir "$(dirname "$brew_link")")" [ -n "$brew_link_dir" ] || return 1 homebrew_keg_command "$brew_link_dir/$(basename "$brew_link")" } homebrew_keg_command() { case "$1" in */Cellar/*/*/bin/"$CLI_NAME") ;; *) return 1 ;; esac BREW_KEG="$(dirname "$(dirname "$1")")" brew_cellar="$(dirname "$(dirname "$BREW_KEG")")" [ "$(basename "$brew_cellar")" = 'Cellar' ] || return 1 BREW_FORMULA="$(basename "$(dirname "$BREW_KEG")")" BREW_PREFIX="$(dirname "$brew_cellar")" } # Runnable only where this user can delete the entry; elsewhere rm would # need sudo, which an installer piped from curl should not run. removal_by_rm() { COPY_REMOVAL='rm' COPY_REMOVAL_TARGET="$1" if [ -w "$2" ]; then COPY_RUNNABLE=1 fi } # Calls $1 with each path an rm removal deletes, so what is shown and what # runs come from one list. each_removal_path() { for removal_path in "$COPY_REMOVAL_TARGET" "$COPY_REMOVAL_METADATA" "$COPY_REMOVAL_HELPER"; do [ -z "$removal_path" ] || "$1" "$removal_path" done } show_removal_path() { printf ' %s' "$(shell_quote "$1")"; } drop_removal_path() { rm -f -- "$1"; } # The recorded removal as a person would type it, and as it runs. brew # uninstall also removes dependencies nothing else needs unless autoremove # is off, which would delete formulae the prompt never named. removal_command() { case "$COPY_REMOVAL" in rm) printf 'rm' && each_removal_path show_removal_path ;; brew) printf '%s uninstall %s' "$(display_path "$COPY_BREW")" "$(display_path "$COPY_REMOVAL_TARGET")" ;; esac } run_removal() { case "$COPY_REMOVAL" in rm) each_removal_path drop_removal_path ;; brew) HOMEBREW_NO_AUTOREMOVE=1 "$COPY_BREW" uninstall "$COPY_REMOVAL_TARGET" /dev/null && is_foreground_job; then PROMPT_STATE='yes' fi fi [ "$PROMPT_STATE" = 'yes' ] } # Asks whether to run the copy's removal, and takes only y or n: Enter or # anything else asks again. The answer is read by a foreground child with # the terminal's normal line editing (Backspace, Ctrl-D), so Ctrl-C ends it # at once with the default SIGINT action while this shell's trap only # records it. The child reports through its exit status: 0 for y, 3 for n, # anything else for end of input or Ctrl-C. Ctrl-C or Ctrl-D keeps the copy, # ends prompting for the rest of the install, and lets it carry on. PROMPT_HINT_SHOWN=0 confirm_removal() { # Once per install: an agent stuck here can see how to run without it. if [ "$PROMPT_HINT_SHOWN" -eq 0 ]; then PROMPT_HINT_SHOWN=1 info ' To skip this question (agents, scripts), set SUPERPENGUIN_NO_PROMPT=1.' fi # Trapped before the prompt appears, so even an instant Ctrl-C is a "no". prompt_interrupted=0 trap 'prompt_interrupted=1' INT printf 'install: Remove it now (runs: %s)? [y/n] ' "$(removal_command)" prompt_status=4 if [ "$prompt_interrupted" -eq 0 ]; then prompt_status=0 # $0 names the reader, so a leftover one is easy to spot in ps. sh -c 'while IFS= read -r line