|
| 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 | +RELEASES_URL=$S3URL |
| 22 | +INSTALL_DIRECTORY='/usr/local/bin' |
| 23 | + |
| 24 | +downloadJSON() { |
| 25 | + url="$2" |
| 26 | + |
| 27 | + echo "Fetching $url.." |
| 28 | + if test -x "$(command -v curl)"; then |
| 29 | + response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url") |
| 30 | + body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g') |
| 31 | + code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') |
| 32 | + elif test -x "$(command -v wget)"; then |
| 33 | + temp=$(mktemp) |
| 34 | + body=$(wget -q --header='Accept: application/json' -O - --server-response "$url" 2> "$temp") |
| 35 | + code=$(awk '/^ HTTP/{print $2}' < "$temp" | tail -1) |
| 36 | + rm "$temp" |
| 37 | + else |
| 38 | + echo "Neither curl nor wget was available to perform http requests." |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + if [ "$code" != 200 ]; then |
| 42 | + echo "Request failed with code $code" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + |
| 46 | + eval "$1='$body'" |
| 47 | +} |
| 48 | + |
| 49 | +downloadFile() { |
| 50 | + url="$1" |
| 51 | + destination="$2" |
| 52 | + |
| 53 | + echo "Fetching $url.." |
| 54 | + if test -x "$(command -v curl)"; then |
| 55 | + code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination") |
| 56 | + elif test -x "$(command -v wget)"; then |
| 57 | + code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1) |
| 58 | + else |
| 59 | + echo "Neither curl nor wget was available to perform http requests." |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + |
| 63 | + if [ "$code" != 200 ]; then |
| 64 | + echo "Request failed with code $code" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +} |
| 68 | + |
| 69 | +initArch() { |
| 70 | + ARCH=$(uname -m) |
| 71 | + case $ARCH in |
| 72 | + amd64) ARCH="amd64";; |
| 73 | + x86_64) ARCH="amd64";; |
| 74 | + i386) ARCH="386";; |
| 75 | + ppc64) ARCH="ppc64";; |
| 76 | + ppc64le) ARCH="ppc64le";; |
| 77 | + s390x) ARCH="s390x";; |
| 78 | + armv6*) ARCH="arm";; |
| 79 | + armv7*) ARCH="arm";; |
| 80 | + aarch64) ARCH="arm64";; |
| 81 | + *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; |
| 82 | + esac |
| 83 | + echo "ARCH = $ARCH" |
| 84 | +} |
| 85 | + |
| 86 | +initOS() { |
| 87 | + OS=$(uname | tr '[:upper:]' '[:lower:]') |
| 88 | + OS_CYGWIN=0 |
| 89 | + case "$OS" in |
| 90 | + darwin) OS='darwin';; |
| 91 | + linux) OS='linux';; |
| 92 | + freebsd) OS='freebsd';; |
| 93 | + mingw*) OS='windows';; |
| 94 | + msys*) OS='windows';; |
| 95 | + cygwin*) |
| 96 | + OS='windows' |
| 97 | + OS_CYGWIN=1 |
| 98 | + ;; |
| 99 | + *) echo "OS ${OS} is not supported by this installation script"; exit 1;; |
| 100 | + esac |
| 101 | + echo "OS = $OS" |
| 102 | +} |
| 103 | + |
| 104 | +# identify platform based on uname output |
| 105 | +initArch |
| 106 | +initOS |
| 107 | +INSTALL_NAME="bookkeeper" |
| 108 | + |
| 109 | +# assemble expected release artifact name |
| 110 | +if [ "${OS}" != "linux" ] && { [ "${ARCH}" = "ppc64" ] || [ "${ARCH}" = "ppc64le" ];}; then |
| 111 | + # ppc64 and ppc64le are only supported on Linux. |
| 112 | + echo "${OS}-${ARCH} is not supported by this instalation script" |
| 113 | +else |
| 114 | + BINARY="${INSTALL_NAME}-${OS}-${ARCH}" |
| 115 | +fi |
| 116 | + |
| 117 | +# add .exe if on windows |
| 118 | +if [ "$OS" = "windows" ]; then |
| 119 | + BINARY="$BINARY.exe" |
| 120 | +fi |
| 121 | + |
| 122 | +#if [ -z "$CLI_RELEASE_TAG" ]; then |
| 123 | +# downloadJSON LATEST_RELEASE "$RELEASES_URL/latest" |
| 124 | +# CLI_RELEASE_TAG=$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' ) |
| 125 | +#fi |
| 126 | + |
| 127 | +if [ "$1" = "unstable" ]; then |
| 128 | + BINARY_URL="$S3URL/$BINARY" |
| 129 | + |
| 130 | +else |
| 131 | + # fetch the real release data to make sure it exists before we attempt a download |
| 132 | +# downloadJSON RELEASE_DATA "$RELEASES_URL/tag/$CLI_RELEASE_TAG" |
| 133 | + BINARY_URL="$RELEASES_URL/$BINARY" |
| 134 | +fi |
| 135 | + |
| 136 | +DOWNLOAD_FILE=$(mktemp) |
| 137 | + |
| 138 | +downloadFile "$BINARY_URL" "$DOWNLOAD_FILE" |
| 139 | +downloadFile "$RELEASES_URL/committee.yaml" "committee.yaml" |
| 140 | + |
| 141 | +echo "Setting executable permissions." |
| 142 | +chmod +x "$DOWNLOAD_FILE" |
| 143 | + |
| 144 | +if [ "$OS" = "windows" ]; then |
| 145 | + INSTALL_NAME="$INSTALL_NAME.exe" |
| 146 | + echo "Moving executable to $HOME/$INSTALL_NAME" |
| 147 | + mv "$DOWNLOAD_FILE" "$HOME/$INSTALL_NAME" |
| 148 | +else |
| 149 | + echo "Moving executable to $INSTALL_DIRECTORY/$INSTALL_NAME" |
| 150 | + sudo mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/$INSTALL_NAME" |
| 151 | +fi |
| 152 | +sudo cp committee.yaml $INSTALL_DIRECTORY/ |
| 153 | + |
0 commit comments