-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·170 lines (146 loc) · 3.9 KB
/
install.sh
File metadata and controls
executable file
·170 lines (146 loc) · 3.9 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
set -euo pipefail
os=$(uname)
arch=$(uname -m)
dist=$(uname -o)
api_url_prefix="${API_URL_PREFIX:-https://api.github.com/repos/SwissDataScienceCenter/renku-cli/releases}"
version=""
check_latest=0
verbosity=${VERBOSITY:-0}
tdir="."
target="/usr/local/bin"
os_id=""
if type -P mktemp > /dev/null; then
tdir=$(mktemp -d -t renku-cli-install.XXXXXXX)
fi
trap cleanup 1 2 3 6 ERR
debug() {
printf "%s\n" "$*" >&2
}
debug_v() {
[[ $verbosity -eq 0 ]] || debug "$*"
}
cleanup() {
if ! [ "$tdir" == "." ]; then
debug_v "Cleanup temporary files: $tdir"
rm -rf "$tdir"
fi
exit
}
assert_exec() {
local program="$1"
if ! type -P "$1" >/dev/null; then
debug "$1 is not installed. Please install $1 and run this script again."
exit 1
fi
}
print_help() {
debug "Install script for renku-cli for macos and linux"
debug
debug "Usage: $(basename "$0") [-h][-c][-v <version>]"
debug "Options:"
debug " -h print this help"
debug " -c check for latest version"
debug " -v verbose mode"
debug " -t <tag_name>"
debug " Install the given version instead of latest"
}
find_latest_release() {
# get latest release
local latest_response=$(curl -sSL "$api_url_prefix/latest")
local version=$(echo $latest_response | jq -r '.tag_name')
local version_num="${version:1}"
local suffix=""
case "$os" in
Linux)
suffix="unknown-linux-musl"
;;
Darwin)
suffix="apple-darwin"
;;
*)
debug "Unknown os: $os"
exit 1
esac
case "$arch" in
x86_64)
suffix="x86_64-${suffix}"
;;
aarch64)
suffix="aarch64-${suffix}"
;;
arm64)
suffix="aarch64-${suffix}"
;;
*)
debug "Unknown architecture: $arch"
exit 1
esac
local name_prefix="rnk-${suffix}-v${version_num}"
local url=$(echo $latest_response | jq -r ".assets[]|select(.name | startswith(\"$name_prefix\"))|.browser_download_url")
if [ -z "$url" ]; then
echo "No download url could be found for $name_prefix."
exit 1
fi
echo $version_num $url
}
while getopts "ht:cv" arg; do
case $arg in
h)
print_help
exit 0
;;
v)
verbosity=1
;;
t)
version=$OPTARG
debug_v "Set version: $version"
;;
c)
check_latest=1
;;
esac
done
# The aarch64 executables won't work on Android
if [ "$dist" == "Android" ]; then
debug "Sorry, Android is not yet supported."
exit 1
fi
## check for curl
assert_exec "curl"
## check for jq
assert_exec jq
## check for cut, grep (should be available)
assert_exec "cut"
assert_exec "grep"
if [ -r /etc/os-release ]; then
os_id=$(cat /etc/os-release | grep "^ID=" | cut -d'=' -f2 | tr -d '[:space:]')
fi
if [ $check_latest -eq 1 ]; then
debug_v "Check for latest version only"
find_latest_release
exit 0
else
# Check for nixos
if [ "$os_id" == "nixos" ]; then
debug "For NixOS, please install via:"
debug " nix profile install github:SwissDataScienceCenter/renku-cli"
debug "or use the flake in your nixos configuration."
debug "See https://github.com/SwissDataScienceCenter/renku-cli/blob/main/docs/install.md#nix"
else
## check for sudo first
assert_exec "sudo"
read version url < <(find_latest_release)
debug "Getting renku-cli $version ..."
debug_v "from: $url"
curl -# -sSL --fail -o "$tdir/rnk.tar.gz" "$url"
tar -xzf "$tdir/rnk.tar.gz" -C "$tdir"
chmod 755 "$tdir/rnk"
debug "Installing to $target"
sudo mkdir -p "$target"
sudo cp "$tdir/rnk" "$target/rnk"
debug "Done."
fi
fi
cleanup