github.com/iotexproject/iotex-core@v1.14.1-rc1/install-solc.sh (about)

     1  #!/bin/sh
     2  
     3  # This install script is intended to install solc release supported.
     4  #
     5  # It attempts to identify the current platform and an error will be thrown if
     6  # the platform is not supported.
     7  #
     8  # Environment variables:
     9  # - INSTALL_DIRECTORY (optional): defaults to /usr/local/bin or $HOME (windows)
    10  #
    11  # You can install using this script:
    12  # $ curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-solc.sh | sh
    13  
    14  set -e
    15  
    16  LINUX_RELEASES_URL="https://github.com/ethereum/solidity/releases/download/v0.8.17/solc-static-linux"
    17  WINDOWS_RELEASES_URL="https://github.com/ethereum/solidity/releases/download/v0.8.17/solc-windows.exe"
    18  INSTALL_DIRECTORY='/usr/local/bin'
    19  
    20  downloadJSON() {
    21      url="$2"
    22  
    23      echo "Fetching $url.."
    24      if test -x "$(command -v curl)"; then
    25          response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url")
    26          body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g')
    27          code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
    28      elif test -x "$(command -v wget)"; then
    29          temp=$(mktemp)
    30          body=$(wget -q --header='Accept: application/json' -O - --server-response "$url" 2> "$temp")
    31          code=$(awk '/^  HTTP/{print $2}' < "$temp" | tail -1)
    32          rm "$temp"
    33      else
    34          echo "Neither curl nor wget was available to perform http requests."
    35          exit 1
    36      fi
    37      if [ "$code" != 200 ]; then
    38          echo "Request failed with code $code"
    39          exit 1
    40      fi
    41  
    42      eval "$1='$body'"
    43  }
    44  
    45  downloadFile() {
    46      url="$1"
    47      destination="$2"
    48  
    49      echo "Fetching $url.."
    50      if test -x "$(command -v curl)"; then
    51          code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination")
    52      elif test -x "$(command -v wget)"; then
    53          code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^  HTTP/{print $2}' | tail -1)
    54      else
    55          echo "Neither curl nor wget was available to perform http requests."
    56          exit 1
    57      fi
    58  
    59      if [ "$code" != 200 ]; then
    60          echo "Request failed with code $code"
    61          exit 1
    62      fi
    63  }
    64  
    65  initArch() {
    66      ARCH=$(uname -m)
    67      case $ARCH in
    68          amd64) ARCH="amd64";;
    69          x86_64) ARCH="amd64";;
    70          i386) ARCH="386";;
    71          ppc64) ARCH="ppc64";;
    72          ppc64le) ARCH="ppc64le";;
    73          s390x) ARCH="s390x";;
    74          armv6*) ARCH="arm";;
    75          armv7*) ARCH="arm";;
    76          aarch64) ARCH="arm64";;
    77          *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;;
    78      esac
    79      echo "ARCH = $ARCH"
    80  }
    81  
    82  initOS() {
    83      OS=$(uname | tr '[:upper:]' '[:lower:]')
    84      OS_CYGWIN=0
    85      case "$OS" in
    86          darwin) OS='darwin';;
    87          linux) OS='linux';;
    88          freebsd) OS='freebsd';;
    89          mingw*) OS='windows';;
    90          msys*) OS='windows';;
    91  	    cygwin*)
    92              OS='windows'
    93              OS_CYGWIN=1
    94  	    ;;
    95          *) echo "OS ${OS} is not supported by this installation script"; exit 1;;
    96      esac
    97      echo "OS = $OS"
    98  }
    99  
   100  # identify platform based on uname output
   101  initArch
   102  initOS
   103  
   104  # assemble expected release artifact name
   105  if [ "$OS" = "darwin" ]; then
   106      brew update
   107      brew upgrade
   108      brew tap ethereum/ethereum
   109      brew install solidity
   110  else
   111      if [ "${OS}" != "linux" ] && { [ "${ARCH}" = "ppc64" ] || [ "${ARCH}" = "ppc64le" ];}; then
   112          # ppc64 and ppc64le are only supported on Linux.
   113          echo "${OS}-${ARCH} is not supported by this installation script"
   114      fi
   115  
   116      # add .exe if on windows
   117      INSTALL_NAME="solc"
   118      if [ "$OS" = "windows" ]; then
   119          INSTALL_NAME="$INSTALL_NAME.exe"
   120          BINARY_URL="$WINDOWS_RELEASES_URL"
   121      else
   122          BINARY_URL="$LINUX_RELEASES_URL"
   123      fi
   124  
   125      DOWNLOAD_FILE=$(mktemp)
   126  
   127      downloadFile "$BINARY_URL" "$DOWNLOAD_FILE"
   128  
   129      echo "Setting executable permissions."
   130      chmod +x "$DOWNLOAD_FILE"
   131  
   132      if [ "$OS" = "windows" ]; then
   133          echo "Moving executable to $HOME/$INSTALL_NAME"
   134          mv "$DOWNLOAD_FILE" "$HOME/$INSTALL_NAME"
   135      else
   136          echo "Moving executable to $INSTALL_DIRECTORY/$INSTALL_NAME"
   137          sudo mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/$INSTALL_NAME"
   138      fi
   139  fi
   140