diff --git a/README.md b/README.md index fd32e0d..ea06039 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,31 @@ This project provides a command-line interface to [Source++](https://github.com/sourceplusplus/live-platform), the open-source live coding platform. +# Install + +## Quick install + +### Linux or macOS + +Install the latest version with the following command: + +```shell +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/sourceplusplus/interface-cli/master/scripts/install.sh)" +``` + +### Windows + +Note: you need to start cmd or PowerShell in administrator mode. + +```shell +curl -LO "https://raw.githubusercontent.com/sourceplusplus/interface-cli/master/scripts/install.bat" && .\install.bat +``` + +## Install by available binaries + +Go to the [releases page](https://github.com/sourceplusplus/interface-cli/releases) to download all available binaries, +including macOS, Linux, Windows. + # Usage Try executing `spp-cli --help` to output the usage instructions like so: diff --git a/scripts/install.bat b/scripts/install.bat new file mode 100644 index 0000000..5141782 --- /dev/null +++ b/scripts/install.bat @@ -0,0 +1,32 @@ +@REM Installation (Note: you need to start cmd or powershell in administrator mode.) +@echo off +setlocal ENABLEDELAYEDEXPANSION + +@REM Get the latest version of spp-cli. +set FLAG="FALSE" +set VERSION= UNKNOWN +curl -s https://api.github.com/repos/sourceplusplus/interface-cli/releases/latest > response.txt +FOR /F "tokens=*" %%g IN ('FIND "tag_name" "response.txt"') do set result=%%g +set "tag_name=%result:"tag_name": "=%" +set "VERSION=%tag_name:",=%" +@echo The latest version of spp-cli is %VERSION% + +@REM Download the binary package. +curl -LO "https://github.com/sourceplusplus/interface-cli/releases/download/%VERSION%/spp-cli-%VERSION%-win64.zip" +if EXIST "spp-cli-%VERSION%-win64.zip" ( + tar -xf ".\spp-cli-%VERSION%-win64.zip" + + mkdir "C:\Program Files\spp-cli" + + @REM Add spp-cli to the environment variable PATH. + copy ".\spp-cli.exe" "C:\Program Files\spp-cli\spp-cli.exe" + setx "Path" "C:\Program Files\spp-cli\;%path%" /m + + @REM Delete unnecessary files. + del ".\response.txt" + del ".\spp-cli-%VERSION%-win64.zip" + + @echo Reopen the terminal and type 'spp-cli --help' to get more information. +) else ( + @echo Failed to download spp-cli-%VERSION%-win64.zip +) diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..75f776a --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# 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 curl unzip; do + check_cmd $cmd +done + +get_latest_release_number() { + curl --silent "https://github.com/sourceplusplus/interface-cli/releases/latest" | sed 's#.*tag/\(.*\)\".*#\1#' +} + +# Get the latest version of spp-cli. +VERSION=$(get_latest_release_number) +echo "Installing spp-cli $VERSION" + +# Download the binary package. +curl -sSLO "https://github.com/sourceplusplus/interface-cli/releases/download/$VERSION/spp-cli-$VERSION-linux64.zip" > /dev/null +if [ -f "spp-cli-$VERSION-linux64.zip" ]; then + unzip -q spp-cli-$VERSION-linux64.zip + + echo "Adding spp-cli to your PATH" + # Add spp-cli to the environment variable PATH. + sudo mv spp-cli /usr/local/bin/spp-cli + + # Delete unnecessary files. + rm "./spp-cli-$VERSION-linux64.zip" + echo "Installation complete." + + echo "Type 'spp-cli --help' to get more information." +else + abort "Failed to download spp-cli-$VERSION-linux64.zip" +fi