github.com/Jeffail/benthos/v3@v3.65.0/website/static/sh/install (about) 1 #!/usr/bin/env bash 2 # 3 # Installs Benthos the quick way, for adventurers that want to spend more time 4 # grooming their cats. 5 # 6 # Requires curl, grep, cut, tar, uname, chmod, mv, rm. 7 8 [[ $- = *i* ]] && echo "Don't source this script!" && return 10 9 10 header() { 11 cat 1>&2 <<EOF 12 Benthos Installer 13 14 Website: https://benthos.dev 15 Docs: https://benthos.dev/docs 16 Repo: https://github.com/Jeffail/benthos 17 18 EOF 19 } 20 21 check_cmd() { 22 command -v "$1" > /dev/null 2>&1 23 } 24 25 check_tools() { 26 Tools=("curl" "grep" "cut" "tar" "uname" "chmod" "mv" "rm") 27 28 for tool in ${Tools[*]}; do 29 if ! check_cmd $tool; then 30 echo "Aborted, missing $tool, sorry!" 31 exit 6 32 fi 33 done 34 } 35 36 install_benthos() 37 { 38 trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; exit 1' ERR 39 install_path="/usr/local/bin" 40 benthos_os="unsupported" 41 benthos_arch="unknown" 42 benthos_arm="" 43 44 header 45 check_tools 46 47 if [[ -n "$PREFIX" ]]; then 48 install_path="$PREFIX/bin" 49 fi 50 51 # Fall back to /usr/bin if necessary 52 if [[ ! -d $install_path ]]; then 53 install_path="/usr/bin" 54 fi 55 56 # Not every platform has or needs sudo (https://termux.com/linux.html) 57 ((EUID)) && sudo_cmd="sudo" 58 59 ######################### 60 # Which OS and version? # 61 ######################### 62 63 benthos_bin="benthos" 64 benthos_dl_ext=".tar.gz" 65 66 # NOTE: `uname -m` is more accurate and universal than `arch` 67 # See https://en.wikipedia.org/wiki/Uname 68 unamem="$(uname -m)" 69 if [[ $unamem == *aarch64* ]]; then 70 benthos_arch="arm64" 71 elif [[ $unamem == *64* ]]; then 72 benthos_arch="amd64" 73 elif [[ $unamem == *armv5* ]]; then 74 benthos_arch="arm" 75 benthos_arm="v5" 76 elif [[ $unamem == *armv6l* ]]; then 77 benthos_arch="arm" 78 benthos_arm="v6" 79 elif [[ $unamem == *armv7l* ]]; then 80 benthos_arch="arm" 81 benthos_arm="v7" 82 else 83 echo "Aborted, unsupported or unknown architecture: $unamem" 84 return 2 85 fi 86 87 unameu="$(tr '[:lower:]' '[:upper:]' <<<$(uname))" 88 if [[ $unameu == *DARWIN* ]]; then 89 benthos_os="darwin" 90 version=${vers##*ProductVersion:} 91 elif [[ $unameu == *LINUX* ]]; then 92 benthos_os="linux" 93 elif [[ $unameu == *FREEBSD* ]]; then 94 benthos_os="freebsd" 95 elif [[ $unameu == *OPENBSD* ]]; then 96 benthos_os="openbsd" 97 elif [[ $unameu == *WIN* || $unameu == MSYS* ]]; then 98 # Should catch cygwin 99 sudo_cmd="" 100 benthos_os="windows" 101 benthos_bin=$benthos_bin.exe 102 else 103 echo "Aborted, unsupported or unknown os: $uname" 104 return 6 105 fi 106 107 ######################## 108 # Download and extract # 109 ######################## 110 111 echo "Downloading Benthos for ${benthos_os}/${benthos_arch}${benthos_arm}..." 112 benthos_file="benthos_${benthos_os}_${benthos_arch}${benthos_arm}${benthos_dl_ext}" 113 114 if [[ "$#" -eq 0 ]]; then 115 # get latest release 116 benthos_tag=$(curl -s https://api.github.com/repos/Jeffail/benthos/releases/latest | grep 'tag_name' | cut -d\" -f4) 117 benthos_version=$(echo ${benthos_tag} | cut -c2-) 118 elif [[ "$#" -gt 1 ]]; then 119 echo "Too many arguments." 120 exit 1 121 elif [ -n $1 ]; then 122 # try to get passed version 123 benthos_tag="v$1" 124 benthos_version=$1 125 fi 126 127 benthos_url="https://github.com/Jeffail/benthos/releases/download/${benthos_tag}/benthos_${benthos_version}_${benthos_os}_${benthos_arch}${benthos_arm}.tar.gz" 128 129 dl="/tmp/$benthos_file" 130 rm -rf -- "$dl" 131 132 curl -fsSL "$benthos_url" -o "$dl" 133 134 echo "Extracting..." 135 case "$benthos_file" in 136 *.tar.gz) tar -xzf "$dl" -C "$PREFIX/tmp/" "$benthos_bin" ;; 137 esac 138 chmod +x "$PREFIX/tmp/$benthos_bin" 139 140 echo "Putting benthos in $install_path (may require password)" 141 $sudo_cmd mv "$PREFIX/tmp/$benthos_bin" "$install_path/$benthos_bin" 142 $sudo_cmd rm -- "$dl" 143 144 # check installation 145 $benthos_bin -version 146 147 echo "Successfully installed" 148 trap ERR 149 return 0 150 } 151 152 install_benthos $@