github.com/aneshas/cli@v0.0.0-20180104210444-aec958fa47db/install (about)

     1  #!/bin/sh
     2  set -e
     3  
     4  # Install script to install fn
     5  
     6  version=`curl --silent https://api.github.com/repos/fnproject/cli/releases/latest  | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"'`
     7  
     8  command_exists() {
     9    command -v "$@" > /dev/null 2>&1
    10  }
    11  
    12  case "$(uname -m)" in
    13    *64)
    14      ;;
    15    *)
    16      echo >&2 'Error: you are not using a 64bit platform.'
    17      echo >&2 'Functions CLI currently only supports 64bit platforms.'
    18      exit 1
    19      ;;
    20  esac
    21  
    22  if command_exists fn ; then
    23    echo >&2 'Warning: "fn" command appears to already exist.'
    24    echo >&2 'If you are just upgrading your functions cli client, ignore this and wait a few seconds.'
    25    echo >&2 'You may press Ctrl+C now to abort this process.'
    26    ( set -x; sleep 5 )
    27  fi
    28  
    29  user="$(id -un 2>/dev/null || true)"
    30  
    31  sh_c='sh -c'
    32  if [ "$user" != 'root' ]; then
    33    if command_exists sudo; then
    34      sh_c='sudo -E sh -c'
    35    elif command_exists su; then
    36      sh_c='su -c'
    37    else
    38      echo >&2 'Error: this installer needs the ability to run commands as root.'
    39      echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
    40      exit 1
    41    fi
    42  fi
    43  
    44  curl=''
    45  if command_exists curl; then
    46    curl='curl -sSL -o'
    47  elif command_exists wget; then
    48    curl='wget -qO'
    49  elif command_exists busybox && busybox --list-modules | grep -q wget; then
    50    curl='busybox wget -qO'
    51  else
    52      echo >&2 'Error: this installer needs the ability to run wget or curl.'
    53      echo >&2 'We are unable to find either "wget" or "curl" available to make this happen.'
    54      exit 1
    55  fi
    56  
    57  url='https://github.com/fnproject/cli/releases/download'
    58  
    59  # perform some very rudimentary platform detection
    60  case "$(uname)" in
    61    Linux)
    62      $sh_c "$curl /usr/local/bin/fn $url/$version/fn_linux"
    63      $sh_c "chmod +x /usr/local/bin/fn"
    64      fn --version
    65      ;;
    66    Darwin)
    67      $sh_c "$curl /usr/local/bin/fn $url/$version/fn_mac"
    68      $sh_c "chmod +x /usr/local/bin/fn"
    69      fn --version
    70      ;;
    71    WindowsNT)
    72      $sh_c "$curl $url/$version/fn.exe"
    73      # TODO how to make executable? chmod?
    74      fn.exe --version
    75      ;;
    76    *)
    77      cat >&2 <<'EOF'
    78  
    79    Either your platform is not easily detectable or is not supported by this
    80    installer script (yet - PRs welcome! [fn/install]).
    81    Please visit the following URL for more detailed installation instructions:
    82  
    83      https://github.com/fnproject/fn
    84  
    85  EOF
    86      exit 1
    87  esac
    88  
    89  cat >&2 <<'EOF'
    90  
    91          ______
    92         / ____/___
    93        / /_  / __ \
    94       / __/ / / / /
    95      /_/   /_/ /_/`
    96  
    97  EOF
    98  exit 0