#!/bin/sh # shellcheck disable=SC2034 test || __() { :; } installer="https://git.io/shellspec" repo="https://github.com/shellspec/shellspec.git" archive="https://github.com/shellspec/shellspec/archive" project="shellspec" exec="shellspec" set -eu && :<<'USAGE' Usage: [sudo] ${0##*/} [VERSION] [OPTIONS...] or : wget -O- $installer | [sudo] sh or : wget -O- $installer | [sudo] sh -s -- [OPTIONS...] or : wget -O- $installer | [sudo] sh -s VERSION [OPTIONS...] or : curl -fsSL $installer | [sudo] sh or : curl -fsSL $installer | [sudo] sh -s -- [OPTIONS...] or : curl -fsSL $installer | [sudo] sh -s VERSION [OPTIONS...] VERSION: Specify install version and method e.g 1.0.0 Install 1.0.0 from git master Install master from git 1.0.0.tar.gz Install 1.0.0 from tar.gz archive . Install from local directory OPTIONS: -p, --prefix PREFIX Specify prefix [default: \$HOME/.local] -b, --bin BIN Specify bin directory [default: /bin] -d, --dir DIR Specify installation directory [default: /lib/$project] -s, --switch Switch version (requires installation via git) -l, --list List available versions (tags) --pre Include pre-release --fetch FETCH Force command to use when installing from archive (curl or wget) -y, --yes Automatic yes to prompts -h, --help You're looking at it USAGE usage() { while IFS= read -r line && [ ! "${line#*:}" = \<\<"'$1'" ]; do :; done while IFS= read -r line && [ ! "$line" = "$1" ]; do set "$@" "$line"; done shift && [ $# -eq 0 ] || printf '%s\n' cat\<\<"$line" "$@" "$line" } CDPATH='' [ "${ZSH_VERSION:-}" ] && setopt shwordsplit finish() { done=1; exit "${1:-0}"; } error() { printf '\033[31m%s\033[0m\n' "$1"; } abort() { [ "${1:-}" ] && error "$1" >&2; finish 1; } finished() { [ "$done" ] || error "Failed to install"; } exists() { type "$1" >/dev/null 2>&1 && return 0 ( IFS=:; for p in $PATH; do [ -x "${p%/}/$1" ] && return 0; done; return 1 ) } prompt() { set -- "$1" "$2" "${3:-/dev/tty}" printf "%s " "$1" if eval "[ \"\$$2\" ] && :"; then eval "printf \"%s\n\" \"\$$2\"" else IFS= read -r "$2" < "$3" || return 1 [ "$3" = "/dev/tty" ] || eval "printf \"%s\n\" \"\$$2\"" fi } is_yes() { case $1 in ( [Yy] | [Yy][Ee][Ss] ) return 0; esac return 1 } confirm() { prompt "$@" || return 1 eval "is_yes \"\$$2\" &&:" } fetch() { tmpfile="${TMPDIR:-${TMP:-/tmp}}/${1##*/}.$$" case $FETCH in curl) curl --head -sSfL -o /dev/null "$1" && curl -SfL "$1" ;; wget) wget --spider -q "$1" && wget -O- "$1" ;; esac > "$tmpfile" &&: error=$? if [ "$error" -eq 0 ]; then unarchive "$tmpfile" "$1" "$2" &&: error=$? [ "$error" -ne 0 ] && [ -d "$2" ]