github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/hack/lib/install.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2019 The KubeEdge Authors.
     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  # check if kubectl installed
    18  function check_kubectl {
    19    echo "checking kubectl"
    20    which kubectl >/dev/null 2>&1
    21    if [[ $? -ne 0 ]]; then
    22      echo "kubectl not installed, exiting."
    23      exit 1
    24    else
    25      echo -n "found kubectl, " && kubectl version --short --client
    26    fi
    27  }
    28  
    29  # check if kind installed
    30  function check_kind {
    31    echo "checking kind"
    32    which kind >/dev/null 2>&1
    33    if [[ $? -ne 0 ]]; then
    34      echo "installing kind ."
    35      GO111MODULE="on" go get sigs.k8s.io/kind@v0.7.0
    36      if [[ $? -ne 0 ]]; then
    37        echo "kind installed failed, exiting."
    38        exit 1
    39      fi
    40  
    41      # avoid modifing go.sum and go.mod when installing the kind
    42      git checkout -- go.mod go.sum
    43  
    44      export PATH=$PATH:$GOPATH/bin
    45    else
    46      echo -n "found kind, version: " && kind version
    47    fi
    48  }
    49  
    50  verify_go_version(){
    51    if [[ -z "$(command -v go)" ]]; then
    52      echo "Can't find 'go' in PATH, please fix and retry.
    53  See http://golang.org/doc/install for installation instructions."
    54      exit 1
    55    fi
    56  
    57    local go_version
    58    IFS=" " read -ra go_version <<< "$(go version)"
    59    local minimum_go_version
    60    minimum_go_version=go1.12.1
    61    if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
    62      echo "Detected go version: ${go_version[*]}.
    63  Kubernetes requires ${minimum_go_version} or greater.
    64  Please install ${minimum_go_version} or later."
    65      exit 1
    66    fi
    67  }
    68  
    69  verify_docker_installed(){
    70    # verify the docker installed
    71    command -v docker >/dev/null || {
    72      echo "must install the docker first"
    73      exit 1
    74    }
    75  }
    76