github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/fn/install.sh (about)

     1  #!/bin/sh
     2  set -e
     3  
     4  # Install script to install fn
     5  
     6  release="0.2.72"
     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/iron-io/functions/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/$release/fn_linux"
    63      $sh_c "chmod +x /usr/local/bin/fn"
    64      fn --version
    65      exit 0
    66      ;;
    67    Darwin)
    68      $sh_c "$curl /usr/local/bin/fn $url/$release/fn_mac"
    69      $sh_c "chmod +x /usr/local/bin/fn"
    70      fn --version
    71      exit 0
    72      ;;
    73    WindowsNT)
    74      $sh_c "$curl $url/$release/fn.exe"
    75      # TODO how to make executable? chmod?
    76      fn.exe --version
    77      exit 0
    78      ;;
    79  esac
    80  
    81  cat >&2 <<'EOF'
    82  
    83    Either your platform is not easily detectable or is not supported by this
    84    installer script (yet - PRs welcome! [fn/install]).
    85    Please visit the following URL for more detailed installation instructions:
    86  
    87      https://github.com/iron-io/functions
    88  
    89  EOF
    90  exit 1