Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: the install scripts now picks the latest version and binary from… #1255

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/installation/kubernetes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ KubeVela CLI provides an easy way to engage and manage your application delivery
** MacOS/Linux **

```shell script
curl -fsSl https://kubevela.net/script/install.sh | bash
curl -fsSl https://kubevela.io/script/install.sh | bash
```

**Windows**
Expand All @@ -46,7 +46,7 @@ Only the official release version is supported.
:::

```shell script
powershell -Command "iwr -useb https://kubevela.net/script/install.ps1 | iex"
powershell -Command "iwr -useb https://kubevela.io/script/install.ps1 | iex"
```

</TabItem>
Expand Down
6 changes: 3 additions & 3 deletions docs/installation/standalone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ You may be required for root privilege during the installation process if not us
If you don't need the automation with root access, you can download from the [release page](https://github.com/kubevela/velad/releases) and uncompress manually.

```shell
curl -fsSl https://static.kubevela.net/script/install-velad.sh | bash
curl -fsSl https://kubevela.io/install-velad.sh | bash
```

Check `velad` installed in `/usr/local/bin/`
Expand Down Expand Up @@ -265,7 +265,7 @@ so you may be required for root privilege during the installation process.
If you don't need the automation with root access, you can download from the [release page](https://github.com/kubevela/velad/releases) and uncompress manually.

```shell
curl -fsSl https://static.kubevela.net/script/install-velad.sh | bash
curl -fsSl https://kubevela.io/script/install-velad.sh | bash
```

Check `velad` installed in `/usr/local/bin/`
Expand Down Expand Up @@ -416,7 +416,7 @@ Then you need to copy this kubeconfig to your local machine. Let's say you savin
To access the cluster, you also need to install `vela` CLI in your local machine.

```shell
curl -fsSl https://static.kubevela.net/script/install.sh | bash
curl -fsSl https://kubevela.io/script/install.sh | bash
```

#### Access KubeVela
Expand Down
2 changes: 1 addition & 1 deletion static/script/install-kubectl-vela.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
KUBECTL_VELA_HTTP_REQUEST_CLI=curl

# GitHub Organization and repo name to download release
GITHUB_ORG=oam-dev
GITHUB_ORG=kubevela
GITHUB_REPO=kubevela

# Kubectl-Vela CLI filename
Expand Down
205 changes: 205 additions & 0 deletions static/script/install-velad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#!/usr/bin/env bash

# Implemented based on Dapr Cli https://github.com/dapr/cli/tree/master/install

# VelaD location
: ${VELAD_INSTALL_DIR:="/usr/local/bin"}

# sudo is required to copy binary to VELAD_INSTALL_DIR for linux
: ${USE_SUDO:="false"}

# Http request CLI
VELAD_HTTP_REQUEST_CLI=curl

# VelaD filename
VELAD_CLI_FILENAME=velad

VELAD_CLI_FILE="${VELAD_INSTALL_DIR}/${VELAD_CLI_FILENAME}"

VERSION_CHECK_BASE="https://api.github.com/repos/kubevela/velad"
DOWNLOAD_BASE="https://github.com/kubevela/velad/releases/download"

getSystemInfo() {
ARCH=$(uname -m)
case $ARCH in
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86_64) ARCH="amd64";;
esac

OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')

# Most linux distro needs root permission to copy the file to /usr/local/bin
if [ "$OS" == "linux" ] || [ "$OS" == "darwin" ]; then
if [ "$VELAD_INSTALL_DIR" == "/usr/local/bin" ]; then
USE_SUDO="true"
fi
fi
}

verifySupported() {
local supported=(darwin-amd64 linux-amd64 darwin-arm64 linux-arm64)
local current_osarch="${OS}-${ARCH}"

for osarch in "${supported[@]}"; do
if [ "$osarch" == "$current_osarch" ]; then
echo "Your system is ${OS}_${ARCH}"
return
fi
done

echo "No prebuilt binary for ${current_osarch}"
exit 1
}

runAsRoot() {
local CMD="$*"

if [ $EUID -ne 0 -a $USE_SUDO = "true" ]; then
CMD="sudo $CMD"
fi

$CMD
}

checkHttpRequestCLI() {
if type "curl" > /dev/null; then
VELAD_HTTP_REQUEST_CLI=curl
elif type "wget" > /dev/null; then
VELAD_HTTP_REQUEST_CLI=wget
else
echo "Either curl or wget is required"
exit 1
fi
}

checkExistingVelaD() {
if [ -f "$VELAD_CLI_FILE" ]; then
echo -e "\nVelaD is detected:"
$VELAD_CLI_FILE version
echo -e "Reinstalling VelaD - ${VELAD_CLI_FILE}...\n"
else
echo -e "Installing VelaD ...\n"
fi
}

getLatestRelease() {
local latest_release=""
local response=""

if [ "$VELAD_HTTP_REQUEST_CLI" == "curl" ]; then
response=$(curl -s "${VERSION_CHECK_BASE}/releases/latest")
else
latest_release=$(wget -q -O - $velaReleaseUrl)
response=$(wget -q -O - "${VERSION_CHECK_BASE}/releases/latest")
fi

# Check for errors in the response
if [[ "$response" == *"Not Found"* ]]; then
echo "Error: Repository or release not found."
return 1
fi

latest_release=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

# Check if the latest version is empty
if [ -z "$latest_release" ]; then
echo "Error: Unable to retrieve the latest version."
return 1
fi

ret_val=$latest_release
}

downloadFile() {
LATEST_RELEASE_TAG=$1

VELA_CLI_ARTIFACT="${VELAD_CLI_FILENAME}-${LATEST_RELEASE_TAG}-${OS}-${ARCH}.tar.gz"
# convert `-` to `_` to let it work
DOWNLOAD_URL="${DOWNLOAD_BASE}/${LATEST_RELEASE_TAG}/${VELA_CLI_ARTIFACT}"

# Create the temp directory
VELAD_TMP_ROOT=$(mktemp -dt velad-install-XXXXXX)
ARTIFACT_TMP_FILE="$VELAD_TMP_ROOT/$VELA_CLI_ARTIFACT"

echo "Downloading $DOWNLOAD_URL ..."
if [ "$VELAD_HTTP_REQUEST_CLI" == "curl" ]; then
curl -SL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE"
else
wget -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL"
fi

if [ ! -f "$ARTIFACT_TMP_FILE" ]; then
echo "failed to download $DOWNLOAD_URL ..."
exit 1
fi
}

installFile() {
tar xf "$ARTIFACT_TMP_FILE" -C "$VELAD_TMP_ROOT"
local tmp_root_velad="$VELAD_TMP_ROOT/${OS}-${ARCH}/$VELAD_CLI_FILENAME"

if [ ! -f "$tmp_root_velad" ]; then
echo "Failed to unpack VelaD executable."
exit 1
fi

chmod o+x "$tmp_root_velad"
runAsRoot mv "$tmp_root_velad" "$VELAD_INSTALL_DIR"

if [ $? -eq 0 ] && [ -f "$VELAD_CLI_FILE" ]; then
echo "VelaD installed into $VELAD_INSTALL_DIR/$VELAD_CLI_FILENAME successfully."
echo ""
$VELAD_CLI_FILE version
else
echo "Failed to install $VELAD_CLI_FILENAME"
exit 1
fi
}

fail_trap() {
result=$?
if [ "$result" != "0" ]; then
echo "Failed to install VelaD"
echo "Go to https://kubevela.io for more support."
fi
cleanup
exit $result
}

cleanup() {
if [[ -d "${VELAD_TMP_ROOT:-}" ]]; then
rm -rf "$VELAD_TMP_ROOT"
fi
}

installCompleted() {
echo -e "\nFor more information on how to started, please visit:"
echo -e " https://kubevela.io"
}

# -----------------------------------------------------------------------------
# main
# -----------------------------------------------------------------------------
trap "fail_trap" EXIT

getSystemInfo
verifySupported
checkExistingVelaD
checkHttpRequestCLI


if [ -z "$1" ]; then
echo "Getting the latest VelaD..."
getLatestRelease
elif [[ $1 == v* ]]; then
ret_val=$1
else
ret_val=v$1
fi

downloadFile $ret_val
installFile
cleanup

installCompleted
22 changes: 18 additions & 4 deletions static/script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ VELA_CLI_FILENAME=vela

VELA_CLI_FILE="${VELA_INSTALL_DIR}/${VELA_CLI_FILENAME}"

DOWNLOAD_BASE="https://static.kubevela.net/binary/vela"
VERSION_CHECK_BASE="https://api.github.com/repos/kubevela/kubevela"
DOWNLOAD_BASE="https://github.com/kubevela/kubevela/releases/download"

getSystemInfo() {
ARCH=$(uname -m)
Expand Down Expand Up @@ -83,13 +84,26 @@ checkExistingVela() {
}

getLatestRelease() {
local velaReleaseUrl="${DOWNLOAD_BASE}/latest_version"
local velaReleaseUrl="${VERSION_CHECK_BASE}/releases/latest"
local latest_release=""
local response=""

if [ "$VELA_HTTP_REQUEST_CLI" == "curl" ]; then
latest_release=$(curl -s $velaReleaseUrl)
response=$(curl -s $velaReleaseUrl)
else
latest_release=$(wget -q -O - $velaReleaseUrl)
response=$(wget -q -O - $velaReleaseUrl)
fi

if [[ "$response" == *"Not Found"* ]]; then
echo "Error: Repository or release not found."
return 1
fi

latest_release=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

if [ -z "$latest_release" ]; then
echo "Error: Unable to retrieve the latest version."
return 1
fi

ret_val=$latest_release
Expand Down
Loading