Skip to content

Commit 1bb3dc4

Browse files
authored
feat: add get.sh script (#3310)
1 parent 7aa5861 commit 1bb3dc4

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,7 @@ You just have to download the binary compatible with your platform to a director
5151
#### Linux
5252

5353
```bash
54-
# Check out the latest release available on github <https://github.com/scaleway/scaleway-cli/releases/latest>
55-
VERSION="2.5.4"
56-
57-
# Download the release from github
58-
sudo curl -o /usr/local/bin/scw -L "https://github.com/scaleway/scaleway-cli/releases/download/v${VERSION}/scaleway-cli_${VERSION}_linux_amd64"
59-
# Naming changed lately, the url prior to 2.5.4 was https://github.com/scaleway/scaleway-cli/releases/download/v${VERSION}/scw-${VERSION}-linux-x86_64
60-
61-
# Allow executing file as program
62-
sudo chmod +x /usr/local/bin/scw
63-
64-
# Init the CLI
65-
scw init
54+
curl -s https://raw.githubusercontent.com/scaleway/scaleway-cli/master/scripts/get.sh | sh
6655
```
6756

6857
#### Windows

scripts/get.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh -e
2+
3+
CHOOSE_ANOTHER_INSTALLATION_METHOD="Please choose another installation method https://github.com/scaleway/scaleway-cli#installation."
4+
5+
# Detect the operating system and CPU architecture
6+
echo "Detecting your operating system and CPU architecture..." >&2
7+
8+
case "$(uname -s)" in
9+
Darwin) os="darwin" ;;
10+
FreeBSD) os="freebsd" ;;
11+
Linux) os="linux" ;;
12+
*)
13+
echo "$(uname -s) is not supported by this installation script. $CHOOSE_ANOTHER_INSTALLATION_METHOD" >&2
14+
exit 1
15+
;;
16+
esac
17+
18+
case "$(uname -m)" in
19+
x86_64) arch="amd64" ;;
20+
armv8*) arch="arm64" ;;
21+
armv*) arch="arm" ;;
22+
i386) arch="386" ;;
23+
*)
24+
echo "$(uname -m) is not supported by this installation script. $CHOOSE_ANOTHER_INSTALLATION_METHOD" >&2
25+
exit 1
26+
;;
27+
esac
28+
29+
# Check if curl or wget is available
30+
echo "Checking if curl or wget is available..." >&2
31+
32+
has_curl=$(which curl || true)
33+
has_wget=$(which wget || true)
34+
35+
if [ -z "$has_curl" ] && [ -z "$has_wget" ]; then
36+
echo "You need curl or wget to proceed." >&2
37+
exit 1
38+
fi
39+
40+
# Get the latest release from GitHub API
41+
echo "Fetching the latest release from GitHub..." >&2
42+
43+
if [ -n "$has_curl" ]; then
44+
latest_release_json=$(curl -s https://api.github.com/repos/scaleway/scaleway-cli/releases/latest)
45+
elif [ -n "$has_wget" ]; then
46+
latest_release_json=$(wget -q -O - https://api.github.com/repos/scaleway/scaleway-cli/releases/latest)
47+
fi
48+
49+
latest=$(echo "$latest_release_json" | grep "browser_download_url.*${os}_${arch}" | cut -d : -f 2,3 | tr -d \" | tr -d " ")
50+
if [ -z "$latest" ]; then
51+
echo "Unable to find the latest ${os}_${arch} release. https://github.com/scaleway/scaleway-cli/releases" >&2
52+
exit 1
53+
fi
54+
55+
# Check if sudo or root permissions are available
56+
echo "Checking if sudo or root permissions are available..." >&2
57+
58+
is_root=$(id -u)
59+
has_sudo=$(which sudo || true)
60+
61+
if [ "$is_root" -eq 0 ]; then
62+
sudo=""
63+
elif [ -n "$has_sudo" ]; then
64+
sudo="sudo"
65+
echo "The installation script will use sudo to proceed. You may be asked to enter your password." >&2
66+
else
67+
echo "You need sudo or root permissions to proceed." >&2
68+
exit 1
69+
fi
70+
71+
# Download the latest release
72+
echo "Downloading the latest release..." >&2
73+
74+
if [ -n "$has_curl" ]; then
75+
$sudo curl -s -L "$latest" -o /usr/local/bin/scw
76+
elif [ -n "$has_wget" ]; then
77+
$sudo wget -q -O /usr/local/bin/scw "$latest"
78+
fi
79+
80+
echo "Setting executable permissions..." >&2
81+
$sudo chmod +x /usr/local/bin/scw
82+
83+
# Success
84+
echo "\033[0;32mScaleway CLI has been successfully installed! Start using it with: \033[1;32mscw --help\033[0m"

0 commit comments

Comments
 (0)