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