You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/08/08 13:15:23 UTC

[skywalking-cli] branch master updated: Add scripts for quick install (#106)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 0494541  Add scripts for quick install (#106)
0494541 is described below

commit 0494541890cd44a9be23e7fe091f9d0f84986613
Author: Team317 <52...@users.noreply.github.com>
AuthorDate: Sun Aug 8 21:15:17 2021 +0800

    Add scripts for quick install (#106)
---
 README.md           | 38 +++++++++++++++++++-----
 scripts/install.bat | 70 ++++++++++++++++++++++++++++++++++++++++++++
 scripts/install.sh  | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 926a14d..0456abd 100644
--- a/README.md
+++ b/README.md
@@ -11,12 +11,33 @@ The CLI (Command Line Interface) for [Apache SkyWalking](https://github.com/apac
 SkyWalking CLI is a command interaction tool for the SkyWalking user or OPS team, as an alternative besides using browser GUI.
 It is based on SkyWalking [GraphQL query protocol](https://github.com/apache/skywalking-query-protocol), same as GUI.
 
-# Download
-Go to the [download page](https://skywalking.apache.org/downloads/) to download all available binaries, including MacOS, Linux, Windows.
-If you want to try the latest features, however, you can compile the latest codes yourself, as the guide below. 
+## Install
 
-# Install
-As SkyWalking CLI is using `Makefile`, compiling the project is as easy as executing a command in the root directory of the project.
+### Quick install
+
+#### Linux or macOS
+
+Install the latest version with the following command:
+
+```shell
+/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apache/skywalking-cli/tree/master/scripts/install.sh)"
+```
+
+#### Windows
+
+Note: you need to start cmd or powershell in administrator mode.
+
+```shell
+curl -LO "https://raw.githubusercontent.com/apache/skywalking-cli/tree/master/scripts/install.bat" && .\install.bat
+```
+
+### Install by available binaries
+
+Go to the [download page](https://skywalking.apache.org/downloads/) to download all available binaries, including macOS, Linux, Windows.
+
+### Build from source
+
+If you want to try the latest features, you can compile the latest source code and build `swctl` by yourself. Since SkyWalking CLI is using `Makefile`, compiling the project is as easy as executing a command in the root directory of the project.
 
 ```shell
 git clone https://github.com/apache/skywalking-cli
@@ -24,9 +45,10 @@ cd skywalking-cli
 make
 ```
 
-Then copy the `./bin/swctl-latest-(darwin|linux|windows)-amd64` to your `PATH` directory according to your OS,
-usually `/usr/bin/` or `/usr/local/bin`, or you can copy it to any directory you like,
-and add that directory to `PATH`, we recommend you to rename the `swctl-latest-(darwin|linux|windows)-amd64` to `swctl`.
+Then copy the `./bin/swctl-latest-(darwin|linux|windows)-amd64` to your `PATH` directory according to your OS, usually `/usr/bin/` or `/usr/local/bin`. 
+
+You can also copy it to any directory you like, then add that directory to `PATH`. **We recommend you to rename the `swctl-latest-(darwin|linux|windows)-amd64` to `swctl`.**
+
 
 # Commands
 Commands in SkyWalking CLI are organized into two levels, in the form of `swctl --option <level1> --option <level2> --option`,
diff --git a/scripts/install.bat b/scripts/install.bat
new file mode 100644
index 0000000..116a0de
--- /dev/null
+++ b/scripts/install.bat
@@ -0,0 +1,70 @@
+@REM Licensed to the Apache Software Foundation (ASF) under one or more
+@REM contributor license agreements.  See the NOTICE file distributed with
+@REM this work for additional information regarding copyright ownership.
+@REM The ASF licenses this file to You under the Apache License, Version 2.0
+@REM (the "License"); you may not use this file except in compliance with
+@REM the License.  You may obtain a copy of the License at
+@REM
+@REM     http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing, software
+@REM distributed under the License is distributed on an "AS IS" BASIS,
+@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@REM See the License for the specific language governing permissions and
+@REM limitations under the License.
+
+@REM Installation (Note: you need to start cmd or powershell in administrator mode.)
+@echo off
+setlocal ENABLEDELAYEDEXPANSION
+
+@REM  Get the latest version of swctl.
+set FLAG="FALSE"
+set VERSION= UNKNOW
+curl -LO "https://raw.githubusercontent.com/apache/skywalking-website/master/data/releases.yml"
+if EXIST "releases.yml" (
+    for /F "tokens=1,2,*" %%i in ('FINDSTR "name version" "./releases.yml"') do (
+        if !FLAG! EQU "TRUE" (
+            set FLAG="FALSE"
+            set VERSION=%%k
+        )
+        if "%%k" == "SkyWalking CLI" (set FLAG="TRUE")
+    )
+)
+set VERSION=%VERSION:~1%
+@echo The latest version of swctl is %VERSION%
+
+if "%VERSION%" NEQ "UNKNOW" (
+
+    @REM Download the binary package.
+    curl -LO "https://apache.website-solution.net/skywalking/cli/%VERSION%/skywalking-cli-%VERSION%-bin.tgz"
+    if EXIST "skywalking-cli-%VERSION%-bin.tgz" (
+        tar -zxvf ".\skywalking-cli-%VERSION%-bin.tgz"
+
+        @REM Verify the integrity of the downloaded file.
+        curl -LO "https://downloads.apache.org/skywalking/cli/%VERSION%/skywalking-cli-%VERSION%-bin.tgz.sha512"
+        CertUtil -hashfile skywalking-cli-%VERSION%-bin.tgz sha512 | findstr /X "[0-9a-zA-Z]*" > verify.txt
+        for /F "tokens=*" %%i in ( 'type ".\verify.txt"' ) do ( set VERIFY1="%%i  skywalking-cli-%VERSION%-bin.tgz" )
+        for /F "tokens=*" %%i in ( 'type ".\skywalking-cli-%VERSION%-bin.tgz.sha512"' ) do ( set VERIFY2="%%i" )
+        if "!VERIFY1!" EQU "!VERIFY2!" (
+            @echo Through verification, the file is complete.
+            mkdir "C:\Program Files\swctl-cli"
+
+            @REM Add swctl to the environment variable PATH.
+            copy ".\skywalking-cli-%VERSION%-bin\bin\swctl-%VERSION%-windows-amd64" "C:\Program Files\swctl-cli\swctl.exe"
+            setx "Path" "C:\Program Files\swctl-cli\;%path%" /m
+
+            @REM Delete unnecessary files.
+            del ".\skywalking-cli-%VERSION%-bin.tgz" ".\verify.txt" 
+            del ".\skywalking-cli-%VERSION%-bin.tgz.sha512" ".\releases.yml"
+            rd /S /Q ".\skywalking-cli-%VERSION%-bin"
+            
+            @echo Reopen the terminal and type 'swctl --help' to get more information.
+        ) else (
+            @echo The file is incomplete.
+        )
+    ) else (
+        @echo Failed to download skywalking-cli-%VERSION%-bin.tgz
+    )
+) else (
+    @echo Can't get the latest version. The install script may be invalid, try other install methods please.
+)
\ No newline at end of file
diff --git a/scripts/install.sh b/scripts/install.sh
new file mode 100644
index 0000000..a1ccef5
--- /dev/null
+++ b/scripts/install.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error.
+set -u
+
+# Exit the script with a message.
+abort() {
+  printf "%s\n" "$@"
+  exit 1
+}
+
+# Check if there is a bash.
+if [ -z "${BASH_VERSION:-}" ]; then
+  abort "Bash is required to interpret this install script."
+fi
+
+# Check OS.
+OS="$(uname)"
+if [[ "$OS" != "Darwin" && "$OS" != "Linux" ]]; then
+  abort "The install script is only supported on macOS and Linux."
+fi
+
+check_cmd() {
+    if ! command -v "$@" &> /dev/null 
+    then
+        abort "You must install "$@" before running the install script."
+    fi
+}
+
+# Check if the commands to be used exist.
+for cmd in shasum curl tar awk; do
+  check_cmd $cmd
+done
+
+# Convert the string to lower case.
+OS=$(echo $OS | awk '{print tolower($0)}')
+
+# Get the latest version of swctl.
+VERSION=$(curl "https://raw.githubusercontent.com/apache/skywalking-website/master/data/releases.yml" | grep --after-context=7 "name: SkyWalking CLI" | grep "version" | grep -o "[0-9].[0-9].[0-9]")
+if [ "$VERSION" != "" ]; then
+    echo "The latest version of swctl is $VERSION"
+    
+    # Download the binary package.
+    curl -sSLO "https://apache.website-solution.net/skywalking/cli/$VERSION/skywalking-cli-$VERSION-bin.tgz" > /dev/null
+    if [ -f "skywalking-cli-$VERSION-bin.tgz" ]; then
+        # Verify the integrity of the downloaded file.
+        curl -sSLO "https://downloads.apache.org/skywalking/cli/$VERSION/skywalking-cli-$VERSION-bin.tgz.sha512" > /dev/null
+        VERIFY=$(shasum -a512 -c "skywalking-cli-$VERSION-bin.tgz.sha512")
+        if [ "${VERIFY#* }" = "OK" ]; then
+            echo "The downloaded file is complete."
+            tar -zxvf skywalking-cli-$VERSION-bin.tgz
+            
+            # Add swctl to the environment variable PATH.
+            sudo cp skywalking-cli-$VERSION-bin/bin/swctl-$VERSION-$OS-amd64 /usr/local/bin/swctl
+            
+            # Delete unnecessary files.
+            sudo rm -rf "./skywalking-cli-$VERSION-bin.tgz.sha512" "./skywalking-cli-$VERSION-bin.tgz" "./skywalking-cli-$VERSION-bin"
+ 
+            echo "Type 'swctl --help' to get more information."
+        else
+            abort "The downloaded file is incomplete."
+        fi
+    else
+        abort "Failed to download skywalking-cli-$VERSION-bin.tgz"
+    fi
+else
+    echo $VERSION
+    abort "Can't get the latest version. The install script may be invalid, try other install methods please."
+fi
\ No newline at end of file