# shellcheck shell=bash DESCRIPTION="install.sh piped into bash, then update: the working copy, then the real one from Gitea" TIER=quick INSTALLED="$HOME/.local/share/federated-connector/connector" RAW="https://gitea.federated.computer/Federated_Computer/connector-macos/raw/branch/main/install.sh" # As `curl ... | bash` runs it: the script on stdin, no terminal to answer # questions (so it doesn't offer to run configure) install_piped() { cat "$1" | /bin/bash } login_zsh_finds() { [ "$(zsh -lc "command -v $1" 2> /dev/null)" = "$HOME/.local/bin/$1" ] } lists_from_installed() { zsh -lc 'configure --list' < /dev/null | grep -qE '^(to do|done) +core ' } swaps() { touch "$INSTALLED/marker-from-before" "$HOME/.local/bin/update" < /dev/null && [ ! -e "$INSTALLED/marker-from-before" ] || return 1 # No staging folders left over from the swap set -- "$(dirname "$INSTALLED")"/.connector-* [ ! -e "$1" ] } up_to_date() { "$HOME/.local/bin/update" < /dev/null | grep -q 'is up to date' } scenario() { step "The working copy, through install.sh" check "install.sh, piped into bash" env FEDERATED_CONNECTOR_SOURCE="$CONNECTOR" bash -c \ "cat '$CONNECTOR/install.sh' | /bin/bash" check "it's in ~/.local/share/federated-connector/connector" test -x "$INSTALLED/configure" check "a login zsh finds configure in ~/.local/bin" login_zsh_finds configure check "...and update" login_zsh_finds update check "configure --list runs from there" lists_from_installed check_eq "update --version" "Federated Connector local" "$("$HOME/.local/bin/update" --version)" check "update swaps in a fresh copy and leaves nothing behind" env FEDERATED_CONNECTOR_SOURCE="$CONNECTOR" bash -c \ "$(declare -f swaps); INSTALLED='$INSTALLED'; swaps" check_eq "the PATH lines are in ~/.zprofile once" 1 "$(grep -c 'Federated Connector commands >>>' "$HOME/.zprofile")" step "The published version, from Gitea" check "curl -fsSL | bash" bash -c "curl -fsSL '$RAW' | /bin/bash" check "it records the commit" grep -qE '^[0-9a-f]{40}$' "$INSTALLED/.version" check "update says it's up to date" up_to_date }