Skip to content

Commit b51dcc1

Browse files
committed
adjust install script to deal with new tarfiles
1 parent 3acaca9 commit b51dcc1

2 files changed

Lines changed: 27 additions & 63 deletions

File tree

docs/install.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ existing tag.
108108
The convenient way is to use the `installer.sh` script that is
109109
provided from this repository. It will download the correct binary
110110
from the release page and put it in `/usr/local/bin` on your system.
111-
It requires `curl` and `sudo` to copy the binary to `/usr/local/bin`.
111+
It requires `curl`, `jq` and finally `sudo` to copy the binary to
112+
`/usr/local/bin`.
112113

113114
```
114115
curl -sfSL https://raw.githubusercontent.com/SwissDataScienceCenter/renku-cli/main/install.sh | bash

install.sh

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ os=$(uname)
66
arch=$(uname -m)
77
dist=$(uname -o)
88
api_url_prefix="${API_URL_PREFIX:-https://api.github.com/repos/SwissDataScienceCenter/renku-cli/releases}"
9-
dl_url_prefix="${DL_URL_PREFIX:-https://github.com/SwissDataScienceCenter/renku-cli/releases}"
10-
binary_name="${BINARY_NAME:-rnk}"
119
version=""
1210
check_latest=0
1311
verbosity=${VERBOSITY:-0}
14-
jq=""
1512
tdir="."
1613
target="/usr/local/bin"
1714
os_id=""
@@ -47,15 +44,6 @@ assert_exec() {
4744
fi
4845
}
4946

50-
curl_silent() {
51-
if [ "$verbosity" -eq 0 ]; then
52-
curl -sSL -o /dev/null --stderr /dev/null --fail "$@"
53-
else
54-
debug "curl -sSL --fail $@"
55-
curl -sSL -o /dev/null --fail "$@"
56-
fi
57-
}
58-
5947
print_help() {
6048
debug "Install script for renku-cli for macos and linux"
6149
debug
@@ -68,34 +56,19 @@ print_help() {
6856
debug " Install the given version instead of latest"
6957
}
7058

71-
find_latest_release_name() {
72-
if [ -n "$version" ]; then
73-
echo "$version"
74-
else
75-
# get latest release
76-
local latest_response=$(curl -sSL "$api_url_prefix/latest")
77-
if [[ -z "$latest_response" ]] || [[ "$latest_response" =~ .*404.* ]]; then
78-
debug_v "No latest release. Use nightly."
79-
echo "nightly"
80-
else
81-
debug_v "Latest release response: $latest_response"
82-
if [ -z "$jq" ]; then
83-
echo $latest_response | tr ',' '\n' | grep "tag_name" | cut -d':' -f2 | tr -d '[:space:]'
84-
else
85-
echo $latest_response | jq -r '.tag_name'
86-
fi
87-
fi
88-
fi
89-
}
59+
find_latest_release() {
60+
# get latest release
61+
local latest_response=$(curl -sSL "$api_url_prefix/latest")
62+
local version=$(echo $latest_response | jq -r '.tag_name')
63+
local version_num="${version:1}"
9064

91-
find_binary_name() {
92-
local v=$(echo $version | tr -d 'v')
9365
local suffix=""
9466
case "$os" in
9567
Linux)
68+
suffix="unknown-linux-musl"
9669
;;
9770
Darwin)
98-
suffix="darwin-"
71+
suffix="apple-darwin"
9972
;;
10073
*)
10174
debug "Unknown os: $os"
@@ -104,32 +77,27 @@ find_binary_name() {
10477

10578
case "$arch" in
10679
x86_64)
107-
suffix="${suffix}amd64"
80+
suffix="x86_64-${suffix}"
10881
;;
10982
aarch64)
110-
suffix="${suffix}aarch64"
83+
suffix="aarch64-${suffix}"
11184
;;
11285
arm64)
113-
suffix="${suffix}aarch64"
86+
suffix="aarch64-${suffix}"
11487
;;
11588
*)
11689
debug "Unknown architecture: $arch"
11790
exit 1
11891
esac
11992

120-
if [ "$os_id" == "alpine" ]; then
121-
suffix="${suffix}-musl"
122-
fi
12393

124-
if [ "$v" == "nightly" ]; then
125-
debug_v "Obtain correct version for nightly"
126-
v=$(curl -sSL --fail "https://raw.githubusercontent.com/SwissDataScienceCenter/renku-cli/main/Cargo.toml" | grep "^version" | cut -d'=' -f2 | tr -d '[:space:]' | tr -d '"')
127-
suffix="${suffix}-$v"
128-
else
129-
suffix="${suffix}-$v"
94+
local name_prefix="rnk-${suffix}-${version_num}"
95+
local url=$(echo $latest_response | jq -r ".assets[]|select(.name | startswith(\"$name_prefix\"))|.browser_download_url")
96+
if [ -z "$url" ]; then
97+
echo "No download url could be found for $name_prefix."
98+
exit 1
13099
fi
131-
132-
echo "rnk_${suffix}"
100+
echo $version_num $url
133101
}
134102

135103
while getopts "ht:cv" arg; do
@@ -151,13 +119,6 @@ while getopts "ht:cv" arg; do
151119
esac
152120
done
153121

154-
## check for jq otherwise use grep
155-
if ! type -P rjq >/dev/null; then
156-
debug_v "jq is not installed, use grep instead"
157-
else
158-
jq="jq"
159-
fi
160-
161122
# The aarch64 executables won't work on Android
162123
if [ "$dist" == "Android" ]; then
163124
debug "Sorry, Android is not yet supported."
@@ -166,6 +127,8 @@ fi
166127

167128
## check for curl
168129
assert_exec "curl"
130+
## check for jq
131+
assert_exec jq
169132
## check for cut, grep (should be available)
170133
assert_exec "cut"
171134
assert_exec "grep"
@@ -176,7 +139,7 @@ fi
176139

177140
if [ $check_latest -eq 1 ]; then
178141
debug_v "Check for latest version only"
179-
find_latest_release_name
142+
find_latest_release
180143
exit 0
181144
else
182145
# Check for nixos
@@ -189,17 +152,17 @@ else
189152
## check for sudo first
190153
assert_exec "sudo"
191154

192-
version=$(find_latest_release_name)
193-
binary=$(find_binary_name)
194-
url="$dl_url_prefix/download/$version/$binary"
195-
debug "Getting renku-cli $version..."
155+
read version url < <(find_latest_release)
156+
debug "Getting renku-cli $version ..."
196157
debug_v "from: $url"
197-
curl -# -sSL --fail -o "$tdir/rnk" "$url"
158+
curl -# -sSL --fail -o "$tdir/rnk.tar.gz" "$url"
159+
tar -xzf "$tdir/rnk.tar.gz" -C "$tdir"
160+
198161
chmod 755 "$tdir/rnk"
199162

200163
debug "Installing to $target"
201164
sudo mkdir -p "$target"
202-
sudo cp "$tdir/rnk" "$target/$binary_name"
165+
sudo cp "$tdir/rnk" "$target/rnk"
203166
debug "Done."
204167
fi
205168
fi

0 commit comments

Comments
 (0)