github.com/pusher/oauth2_proxy@v3.2.0+incompatible/configure (about)

     1  #!/usr/bin/env bash
     2  
     3  RED='\033[0;31m'
     4  GREEN='\033[0;32m'
     5  BLUE='\033[0;34m'
     6  NC='\033[0m'
     7  
     8  declare -A tools=()
     9  declare -A desired=()
    10  
    11  for arg in "$@"; do
    12    case ${arg%%=*} in
    13      "--with-go")
    14        desired[go]="${arg##*=}"
    15        ;;
    16      "--with-dep")
    17        desired[dep]="${arg##*=}"
    18        ;;
    19      "--help")
    20        printf "${GREEN}$0${NC}\n"
    21        printf "  available options:\n"
    22        printf "  --with-dep=${BLUE}<path_to_dep_binary>${NC}\n"
    23        printf "  --with-go=${BLUE}<path_to_go_binary>${NC}\n"
    24        exit 0
    25        ;;
    26      *)
    27        echo "Unknown option: $arg"
    28        exit 2
    29        ;;
    30      esac
    31  done
    32  
    33  vercomp () {
    34      if [[ $1 == $2 ]]
    35      then
    36          return 0
    37      fi
    38      local IFS=.
    39      local i ver1=($1) ver2=($2)
    40      # fill empty fields in ver1 with zeros
    41      for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
    42      do
    43          ver1[i]=0
    44      done
    45      for ((i=0; i<${#ver1[@]}; i++))
    46      do
    47          if [[ -z ${ver2[i]} ]]
    48          then
    49              # fill empty fields in ver2 with zeros
    50              ver2[i]=0
    51          fi
    52          if ((10#${ver1[i]} > 10#${ver2[i]}))
    53          then
    54              return 1
    55          fi
    56          if ((10#${ver1[i]} < 10#${ver2[i]}))
    57          then
    58              return 2
    59          fi
    60      done
    61      return 0
    62  }
    63  
    64  check_for() {
    65    echo -n "Checking for $1... "
    66    if ! [ -z "${desired[$1]}" ]; then
    67      TOOL_PATH="${desired[$1]}"
    68    else
    69      TOOL_PATH=$(command -v $1)
    70    fi
    71    if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then
    72      printf "${RED}not found${NC}\n"
    73      cd -
    74      exit 1
    75    else
    76      printf "${GREEN}found${NC}\n"
    77      tools[$1]=$TOOL_PATH
    78    fi
    79  }
    80  
    81  check_go_version() {
    82    echo -n "Checking go version... "
    83    GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+\.[0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}')
    84    vercomp $GO_VERSION 1.11
    85    case $? in
    86      0) ;&
    87      1)
    88        printf "${GREEN}"
    89        echo $GO_VERSION
    90        printf "${NC}"
    91        ;;
    92      2)
    93        printf "${RED}"
    94        echo "$GO_VERSION < 1.11"
    95        exit 1
    96        ;;
    97    esac
    98    VERSION=$(${tools[go]} version | ${tools[awk]} '{print $3}')
    99    tools["go_version"]="${VERSION}"
   100  }
   101  
   102  check_docker_version() {
   103    echo -n "Checking docker version... "
   104    DOCKER_VERSION=$(${tools[docker]} version | ${tools[awk]})
   105  }
   106  
   107  check_go_env() {
   108    echo -n "Checking \$GOPATH... "
   109    GOPATH="$(go env GOPATH)"
   110    if [ -z "$GOPATH" ]; then
   111      printf "${RED}invalid${NC} - GOPATH not set\n"
   112      exit 1
   113    fi
   114    printf "${GREEN}valid${NC} - $GOPATH\n"
   115  }
   116  
   117  cd ${0%/*}
   118  
   119  if [ ! -f .env ]; then
   120    rm .env
   121  fi
   122  
   123  check_for make
   124  check_for awk
   125  check_for go
   126  check_go_version
   127  check_go_env
   128  check_for dep
   129  
   130  echo
   131  
   132  cat <<- EOF > .env
   133  	MAKE := "${tools[make]}"
   134    GO := "${tools[go]}"
   135    GO_VERSION := ${tools[go_version]}
   136    DEP := "${tools[dep]}"
   137  EOF
   138  
   139  echo "Environment configuration written to .env"
   140  
   141  cd - > /dev/null