github.com/cloudposse/helm@v2.2.3+incompatible/scripts/get (about) 1 #!/bin/bash 2 3 # Copyright 2016 The Kubernetes Authors All rights reserved. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # The install script is based off of the MIT-licensed script from glide, 18 # the package manager for Go: https://github.com/Masterminds/glide.sh/blob/master/get 19 20 PROJECT_NAME="helm" 21 22 : ${HELM_INSTALL_DIR:="/usr/local/bin"} 23 24 # initArch discovers the architecture for this system. 25 initArch() { 26 ARCH=$(uname -m) 27 case $ARCH in 28 armv5*) ARCH="armv5";; 29 armv6*) ARCH="armv6";; 30 armv7*) ARCH="armv7";; 31 aarch64) ARCH="arm64";; 32 x86) ARCH="386";; 33 x86_64) ARCH="amd64";; 34 i686) ARCH="386";; 35 i386) ARCH="386";; 36 esac 37 } 38 39 # initOS discovers the operating system for this system. 40 initOS() { 41 OS=$(echo `uname`|tr '[:upper:]' '[:lower:]') 42 43 case "$OS" in 44 # Minimalist GNU for Windows 45 mingw*) OS='windows';; 46 esac 47 } 48 49 # verifySupported checks that the os/arch combination is supported for 50 # binary builds. 51 verifySupported() { 52 local supported="linux-amd64\ndarwin-amd64\nlinux-386" 53 if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then 54 echo "No prebuild binary for ${OS}-${ARCH}." 55 echo "To build from source, go to https://github.com/kubernetes/helm" 56 exit 1 57 fi 58 59 if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then 60 echo "Either curl or wget is required" 61 exit 1 62 fi 63 } 64 65 # downloadFile downloads the latest binary package and also the checksum 66 # for that binary. 67 downloadFile() { 68 # Use the GitHub API to find the latest version for this project. 69 local latest_url="https://api.github.com/repos/kubernetes/helm/releases/latest" 70 if type "curl" > /dev/null; then 71 TAG=$(curl -s $latest_url | awk '/\"tag_name\":/{gsub( /[,\"]/,"", $2); print $2}') 72 elif type "wget" > /dev/null; then 73 TAG=$(wget -q -O - $latest_url | awk '/\"tag_name\":/{gsub( /[,\"]/,"", $2); print $2}') 74 fi 75 76 HELM_DIST="helm-$TAG-$OS-$ARCH.tar.gz" 77 DOWNLOAD_URL="https://kubernetes-helm.storage.googleapis.com/$HELM_DIST" 78 CHECKSUM_URL="$DOWNLOAD_URL.sha256" 79 HELM_TMP_FILE="/tmp/$HELM_DIST" 80 HELM_SUM_FILE="/tmp/$HELM_DIST.sha256" 81 echo "Downloading $DOWNLOAD_URL" 82 if type "curl" > /dev/null; then 83 curl -Ls "$CHECKSUM_URL" -o "$HELM_SUM_FILE" 84 elif type "wget" > /dev/null; then 85 wget -q -O "$HELM_SUM_FILE" "$CHECKSUM_URL" 86 fi 87 if type "curl" > /dev/null; then 88 curl -L "$DOWNLOAD_URL" -o "$HELM_TMP_FILE" 89 elif type "wget" > /dev/null; then 90 wget -q -O "$HELM_TMP_FILE" "$DOWNLOAD_URL" 91 fi 92 } 93 94 # installFile verifies the SHA256 for the file, then unpacks and 95 # installs it. 96 installFile() { 97 HELM_TMP="/tmp/$PROJECT_NAME" 98 local sum=$(openssl sha -sha256 ${HELM_TMP_FILE} | awk '{print $2}') 99 local expected_sum=$(cat ${HELM_SUM_FILE}) 100 if [ "$sum" != "$expected_sum" ]; then 101 echo "SHA sum of $HELM_TMP does not match. Aborting." 102 exit 1 103 fi 104 105 mkdir -p "$HELM_TMP" 106 tar xf "$HELM_TMP_FILE" -C "$HELM_TMP" 107 HELM_TMP_BIN="$HELM_TMP/$OS-$ARCH/$PROJECT_NAME" 108 echo "Preparing to install into ${HELM_INSTALL_DIR} (sudo)" 109 sudo cp "$HELM_TMP_BIN" "$HELM_INSTALL_DIR" 110 } 111 112 # fail_trap is executed if an error occurs. 113 fail_trap() { 114 result=$? 115 if [ "$result" != "0" ]; then 116 echo "Failed to install $PROJECT_NAME" 117 echo "\tFor support, go to https://github.com/kubernetes/helm." 118 fi 119 exit $result 120 } 121 122 # testVersion tests the installed client to make sure it is working. 123 testVersion() { 124 set +e 125 echo "$PROJECT_NAME installed into $HELM_INSTALL_DIR/$PROJECT_NAME" 126 HELM="$(which $PROJECT_NAME)" 127 if [ "$?" = "1" ]; then 128 echo "$PROJECT_NAME not found. Is $HELM_INSTALL_DIR on your "'$PATH?' 129 exit 1 130 fi 131 set -e 132 echo "Run '$PROJECT_NAME init' to configure $PROJECT_NAME." 133 } 134 135 # Execution 136 137 #Stop execution on any error 138 trap "fail_trap" EXIT 139 set -e 140 initArch 141 initOS 142 verifySupported 143 downloadFile 144 installFile 145 testVersion