github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/scripts/install_from_binaries.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # Command line options and their respective defaults
     5  tmpdir="/tmp" 		# temp directory, e.g. $HOME/tmp
     6  dstdir="/usr/local/bin"	# installation destination
     7  completions="false"	# install and enable _only_ CLI autocompletions (ie., skip installing binaries)
     8  release="latest" 	# e.g.: v1.3.15, v1.3.16, latest (default: latest)
     9  
    10  script=$(basename $0)
    11  
    12  SUDO=sudo
    13  [[ $(id -u) == 0 ]] && SUDO=""
    14  
    15  usage="NAME:
    16    $script - install 'ais' (CLI) and 'aisloader' from release binaries
    17  
    18  USAGE:
    19    ./$script [options...]
    20  
    21  OPTIONS:
    22    --tmpdir <dir>  	work directory, e.g. $HOME/tmp
    23    --dstdir <dir>  	installation destination
    24    --release      	e.g., 3.10, 3.11, latest (default: latest)
    25    --completions		install and enable _only_ CLI autocompletions (ie., skip installing binaries)
    26    -h, --help      	show this help
    27  "
    28  
    29  while (( "$#" )); do
    30    case "${1}" in
    31      -h|--help) echo -n "${usage}"; exit;;
    32  
    33      --tmpdir) tmpdir=$2; shift; shift;;
    34      --dstdir) dstdir=$2; shift; shift;;
    35      --release) release=$2; shift; shift;;
    36      --completions) completions="true"; shift;;
    37      *) echo "fatal: unknown argument '${1}'"; exit 1;;
    38    esac
    39  done
    40  
    41  cleanup() {
    42    rc=$?
    43    popd >/dev/null
    44    if [[ ${rc} == 0 ]]; then
    45      echo
    46      echo "Done."
    47    fi
    48    rm -rf $tmp_dir
    49    exit $rc
    50  }
    51  
    52  install_completions() {
    53    echo "Downloading CLI autocompletions (bash & zsh)..."
    54    curl -Lo bash https://raw.githubusercontent.com/NVIDIA/aistore/main/cmd/cli/autocomplete/bash
    55    curl -Lo zsh https://raw.githubusercontent.com/NVIDIA/aistore/main/cmd/cli/autocomplete/zsh
    56  
    57    echo "NOTE:"
    58  
    59    #
    60    # NOTE: cmd/cli/autocomplete/install.sh provides for zsh completions and more options.
    61    #
    62  
    63    source ./bash
    64    $SUDO cp ./bash /etc/bash_completion.d/ais
    65    if [[ $? -eq 0 ]]; then
    66      echo "   *** CLI autocompletions are now copied to /etc/bash_completion.d/ais ***"
    67      echo "   *** To enable, simply run: source /etc/bash_completion.d/ais         ***"
    68    fi
    69  }
    70  
    71  if [ ! -w "$tmpdir" ]; then
    72    echo "$tmpdir is not writable - exiting"
    73    exit 1
    74  fi
    75  
    76  tmp_dir=$(mktemp -d -t ais-cli-XXXXXXX --tmpdir=$tmpdir) || exit $?
    77  pushd $tmp_dir >/dev/null
    78  
    79  trap cleanup EXIT
    80  
    81  if [[ ${completions} == "true" ]]; then
    82    install_completions
    83    exit 0
    84  fi
    85  
    86  if [ ! -w "$dstdir" ]; then
    87    echo "$dstdir is not writable - exiting"
    88    exit 1
    89  fi
    90  
    91  echo "Installing aisloader => $dstdir/aisloader"
    92  case ${release} in
    93    latest|"")
    94      curl -LO https://github.com/NVIDIA/aistore/releases/latest/download/aisloader-linux-amd64.tar.gz
    95      tar -xzvf aisloader-linux-amd64.tar.gz
    96      ;;
    97    v1.3.15|3.13)
    98      curl -LO https://github.com/NVIDIA/aistore/releases/download/v1.3.15/aisloader-linux-amd64.tar.gz
    99      tar -xzvf aisloader-linux-amd64.tar.gz
   100      ;;
   101    *)
   102      curl -Lo ais https://github.com/NVIDIA/aistore/releases/download/$release/aisloader-linux-amd64
   103      chmod +x aisloader
   104      ;;
   105  esac
   106  $SUDO mv ./aisloader $dstdir/.
   107  
   108  echo "Installing CLI => $dstdir/ais"
   109  case ${release} in
   110    latest|"")
   111      curl -LO https://github.com/NVIDIA/aistore/releases/latest/download/ais-linux-amd64.tar.gz
   112      tar -xzvf ais-linux-amd64.tar.gz
   113      ;;
   114    v1.3.15|3.13)
   115      curl -LO https://github.com/NVIDIA/aistore/releases/download/v1.3.15/ais-linux-amd64.tar.gz
   116      tar -xzvf ais-linux-amd64.tar.gz
   117      ;;
   118    *)
   119      curl -Lo ais https://github.com/NVIDIA/aistore/releases/download/$release/ais-linux-amd64
   120      chmod +x ais
   121      ;;
   122  esac
   123  $SUDO mv ./ais $dstdir/.
   124  
   125  install_completions