github.com/iotexproject/iotex-core@v1.14.1-rc1/install-cli.sh (about) 1 #!/bin/sh 2 3 # This install script is intended to download and install the latest available 4 # release of the ioctl dependency manager for Golang. 5 # 6 # It attempts to identify the current platform and an error will be thrown if 7 # the platform is not supported. 8 # 9 # Environment variables: 10 # - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin (if $GOPATH exists) 11 # or /usr/local/bin (else) 12 # - CLI_RELEASE_TAG (optional): defaults to fetching the latest release 13 # 14 # You can install using this script: 15 # $ curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-cli.sh | sh 16 17 set -e 18 19 RELEASES_URL="https://github.com/iotexproject/iotex-core/releases" 20 S3URL="https://s3-ap-southeast-1.amazonaws.com/ioctl" 21 INSTALL_DIRECTORY='/usr/local/bin' 22 23 BREW_UPDATE_CMD="brew update" 24 BREW_INSTALL_CMD="brew install ioctl" 25 BREW_REINSTALL_CMD="brew reinstall ioctl" 26 BREW_UNSTABLE_TAP_CMD="brew tap iotexproject/ioctl-unstable" 27 BREW_UNSTABLE_INSTALL_CMD="brew install iotexproject/ioctl-unstable/ioctl-unstable" 28 BREW_UNSTABLE_REINSTALL_CMD="brew reinstall ioctl-unstable" 29 BREW_INSTALLED_PATH="/usr/local/bin" 30 31 downloadJSON() { 32 url="$2" 33 34 echo "Fetching $url.." 35 if test -x "$(command -v curl)"; then 36 response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url") 37 body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g') 38 code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') 39 elif test -x "$(command -v wget)"; then 40 temp=$(mktemp) 41 body=$(wget -q --header='Accept: application/json' -O - --server-response "$url" 2> "$temp") 42 code=$(awk '/^ HTTP/{print $2}' < "$temp" | tail -1) 43 rm "$temp" 44 else 45 echo "Neither curl nor wget was available to perform http requests." 46 exit 1 47 fi 48 if [ "$code" != 200 ]; then 49 echo "Request failed with code $code" 50 exit 1 51 fi 52 53 eval "$1='$body'" 54 } 55 56 downloadFile() { 57 url="$1" 58 destination="$2" 59 60 echo "Fetching $url.." 61 if test -x "$(command -v curl)"; then 62 code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination") 63 elif test -x "$(command -v wget)"; then 64 code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1) 65 else 66 echo "Neither curl nor wget was available to perform http requests." 67 exit 1 68 fi 69 70 if [ "$code" != 200 ]; then 71 echo "Request failed with code $code" 72 exit 1 73 fi 74 } 75 76 initArch() { 77 ARCH=$(uname -m) 78 case $ARCH in 79 amd64) ARCH="amd64";; 80 x86_64) ARCH="amd64";; 81 i386) ARCH="386";; 82 ppc64) ARCH="ppc64";; 83 ppc64le) ARCH="ppc64le";; 84 s390x) ARCH="s390x";; 85 armv6*) ARCH="arm";; 86 armv7*) ARCH="arm";; 87 aarch64) ARCH="arm64";; 88 arm64) ARCH="arm64";; 89 *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; 90 esac 91 echo "ARCH = $ARCH" 92 } 93 94 initOS() { 95 OS=$(uname | tr '[:upper:]' '[:lower:]') 96 OS_CYGWIN=0 97 case "$OS" in 98 darwin) OS='darwin';; 99 linux) OS='linux';; 100 freebsd) OS='freebsd';; 101 mingw*) OS='windows';; 102 msys*) OS='windows';; 103 cygwin*) 104 OS='windows' 105 OS_CYGWIN=1 106 ;; 107 *) echo "OS ${OS} is not supported by this installation script"; exit 1;; 108 esac 109 echo "OS = $OS" 110 } 111 112 # identify platform based on uname output 113 initArch 114 initOS 115 116 # assemble expected release artifact name 117 if [ "${OS}" != "linux" ] && { [ "${ARCH}" = "ppc64" ] || [ "${ARCH}" = "ppc64le" ];}; then 118 # ppc64 and ppc64le are only supported on Linux. 119 echo "${OS}-${ARCH} is not supported by this instalation script" 120 else 121 BINARY="ioctl-${OS}-${ARCH}" 122 fi 123 124 if [ "${OS}" = "darwin" ];then 125 if test -x "$(command -v brew)"; then 126 if [ "$1" = "unstable" ]; then 127 if [ `command -v ioctl-unstable` ]; then 128 $BREW_UNSTABLE_REINSTALL_CMD 129 else 130 $BREW_UNSTABLE_TAP_CMD && $BREW_UNSTABLE_INSTALL_CMD 131 fi 132 echo "Command-line tools is installed to `command -v ioctl-unstable`" 133 else 134 if [ `command -v ioctl` ]; then 135 $BREW_UPDATE_CMD && $BREW_REINSTALL_CMD 136 else 137 $BREW_UPDATE_CMD && $BREW_INSTALL_CMD 138 fi 139 echo "Command-line tools is installed to `command -v ioctl`" 140 fi 141 exit 0 142 else 143 echo "None command 'brew' is available to perform installed." 144 exit 1 145 fi 146 fi 147 148 # add .exe if on windows 149 if [ "$OS" = "windows" ]; then 150 BINARY="$BINARY.exe" 151 fi 152 153 if [ -z "$CLI_RELEASE_TAG" ]; then 154 downloadJSON LATEST_RELEASE "$RELEASES_URL/latest" 155 CLI_RELEASE_TAG=$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' ) 156 fi 157 158 if [ "$1" = "unstable" ]; then 159 BINARY_URL="$S3URL/$BINARY" 160 161 else 162 # fetch the real release data to make sure it exists before we attempt a download 163 downloadJSON RELEASE_DATA "$RELEASES_URL/tag/$CLI_RELEASE_TAG" 164 BINARY_URL="$RELEASES_URL/download/$CLI_RELEASE_TAG/$BINARY" 165 fi 166 167 DOWNLOAD_FILE=$(mktemp) 168 169 downloadFile "$BINARY_URL" "$DOWNLOAD_FILE" 170 171 echo "Setting executable permissions." 172 chmod +x "$DOWNLOAD_FILE" 173 174 INSTALL_NAME="ioctl" 175 176 if [ "$OS" = "windows" ]; then 177 INSTALL_NAME="$INSTALL_NAME.exe" 178 echo "Moving executable to $HOME/$INSTALL_NAME" 179 mv "$DOWNLOAD_FILE" "$HOME/$INSTALL_NAME" 180 else 181 echo "Moving executable to $INSTALL_DIRECTORY/$INSTALL_NAME" 182 sudo mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/$INSTALL_NAME" 183 fi