github.com/ETCDEVTeam/janus@v0.2.4-0.20180611132348-f6c8fba730fa/get.sh (about)

     1  #!/bin/sh
     2  
     3  # Sources cited:
     4  # - https://raw.githubusercontent.com/goreleaser/get/master/get
     5  
     6  # Use:
     7  #
     8  # Install janus executable to system PATH.
     9  #
    10  # curl -sL https://raw.githubusercontent.com/ETCDEVTeam/janus/master/get.sh | bash
    11  # export PATH=$PATH:$PWD/janusbin
    12  
    13  set -e
    14  
    15  TAR_FILE="/tmp/janus.tar.gz"
    16  TAR_FILE_SIG="/tmp/janus.tar.gz.sig"
    17  ISAAC_GPG_FILE="/tmp/isaac-gpg.txt"
    18  ISAAC_GPG_URL="https://raw.githubusercontent.com/ethereumproject/volunteer/7a78a94307d67a0b20e418568b7bccac83c3d143/Volunteer-Public-Keys/isaac.ardis%40gmail.com"
    19  DOWNLOAD_URL="https://github.com/ETCDEVTeam/janus/releases/download"
    20  test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
    21  
    22  last_version() {
    23    # The new and improved sans-GithubAPI-rate-limited curler.
    24    # https://github.com/goreleaser/goreleaser/issues/157
    25    curl -sL -o /dev/null -w %{url_effective} https://github.com/ETCDEVTeam/janus/releases/latest | rev | cut -f1 -d'/'| rev
    26  }
    27  
    28  download() {
    29    test -z "$VERSION" && VERSION="$(last_version)"
    30    test -z "$VERSION" && {
    31      echo "Unable to get janus version." >&2
    32      exit 1
    33    }
    34    echo "Version: $VERSION"
    35    rm -f "$TAR_FILE"
    36    download_target="$DOWNLOAD_URL/$VERSION/janus_${VERSION}_$(uname -s)_$(uname -m).tar.gz"
    37    echo "Downloading Janus: $download_target"
    38    curl -s -L -o "$TAR_FILE" \
    39      "$download_target"
    40  
    41    # Get and verify signature.
    42    rm -f "$TAR_FILE_SIG"
    43    sig_target="$DOWNLOAD_URL/$VERSION/janus_${VERSION}_$(uname -s)_$(uname -m).tar.gz.sig"
    44    echo "Downloading signature: $sig_target"
    45    curl -s -L -o "$TAR_FILE_SIG" \
    46      "$sig_target"
    47  
    48    # Ensure our newly downloaded files exists.
    49    if ! [ -f "$TAR_FILE" ]; then
    50            echo "Tar file not found."
    51            exit 1
    52    fi
    53    if ! [ -f "$TAR_FILE_SIG" ]; then
    54            echo "Tar sig file not found."
    55            exit 1
    56    fi
    57  }
    58  
    59  verify() {
    60    # Verify signature if gpg is available.
    61    if command -v gpg 2> /dev/null; then
    62            echo "Downloading Isaac's key file: $ISAAC_GPG_URL"
    63            curl -s -L -o "$ISAAC_GPG_FILE" \
    64              "$ISAAC_GPG_URL"
    65  
    66            gpg --import "$ISAAC_GPG_FILE"
    67            gpg --verify "$TAR_FILE_SIG" "$TAR_FILE"
    68    fi
    69  }
    70  
    71  install() {
    72    echo "Extracting janus..."
    73    tar -xf "$TAR_FILE"
    74  
    75    echo "Moving 'janus' binary to ./janusbin/janus"
    76    mkdir janusbin
    77    mv janus janusbin/
    78  
    79    echo "Please ensure janus is added to PATH."
    80    echo "Use:"
    81    echo " - export PATH=$PATH:$PWD/janusbin"
    82  }
    83  
    84  download
    85  verify
    86  install