Skip to content

Commit df929d1

Browse files
authored
Merge pull request #36 from sourceplusplus/issue-20
Issue 20
2 parents 0a72aff + e6c89d3 commit df929d1

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88

99
This project provides a command-line interface to [Source++](https://github.com/sourceplusplus/live-platform), the open-source live coding platform.
1010

11+
# Install
12+
13+
## Quick install
14+
15+
### Linux or macOS
16+
17+
Install the latest version with the following command:
18+
19+
```shell
20+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/sourceplusplus/interface-cli/master/scripts/install.sh)"
21+
```
22+
23+
### Windows
24+
25+
Note: you need to start cmd or PowerShell in administrator mode.
26+
27+
```shell
28+
curl -LO "https://raw.githubusercontent.com/sourceplusplus/interface-cli/master/scripts/install.bat" && .\install.bat
29+
```
30+
31+
## Install by available binaries
32+
33+
Go to the [releases page](https://github.com/sourceplusplus/interface-cli/releases) to download all available binaries,
34+
including macOS, Linux, Windows.
35+
1136
# Usage
1237

1338
Try executing `spp-cli --help` to output the usage instructions like so:

scripts/install.bat

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@REM Installation (Note: you need to start cmd or powershell in administrator mode.)
2+
@echo off
3+
setlocal ENABLEDELAYEDEXPANSION
4+
5+
@REM Get the latest version of spp-cli.
6+
set FLAG="FALSE"
7+
set VERSION= UNKNOWN
8+
curl -s https://api.github.com/repos/sourceplusplus/interface-cli/releases/latest > response.txt
9+
FOR /F "tokens=*" %%g IN ('FIND "tag_name" "response.txt"') do set result=%%g
10+
set "tag_name=%result:"tag_name": "=%"
11+
set "VERSION=%tag_name:",=%"
12+
@echo The latest version of spp-cli is %VERSION%
13+
14+
@REM Download the binary package.
15+
curl -LO "https://github.com/sourceplusplus/interface-cli/releases/download/%VERSION%/spp-cli-%VERSION%-win64.zip"
16+
if EXIST "spp-cli-%VERSION%-win64.zip" (
17+
tar -xf ".\spp-cli-%VERSION%-win64.zip"
18+
19+
mkdir "C:\Program Files\spp-cli"
20+
21+
@REM Add spp-cli to the environment variable PATH.
22+
copy ".\spp-cli.exe" "C:\Program Files\spp-cli\spp-cli.exe"
23+
setx "Path" "C:\Program Files\spp-cli\;%path%" /m
24+
25+
@REM Delete unnecessary files.
26+
del ".\response.txt"
27+
del ".\spp-cli-%VERSION%-win64.zip"
28+
29+
@echo Reopen the terminal and type 'spp-cli --help' to get more information.
30+
) else (
31+
@echo Failed to download spp-cli-%VERSION%-win64.zip
32+
)

scripts/install.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error.
4+
set -u
5+
6+
# Exit the script with a message.
7+
abort() {
8+
printf "%s\n" "$@"
9+
exit 1
10+
}
11+
12+
# Check if there is a bash.
13+
if [ -z "${BASH_VERSION:-}" ]; then
14+
abort "Bash is required to interpret this install script."
15+
fi
16+
17+
# Check OS.
18+
OS="$(uname)"
19+
if [[ "$OS" != "Darwin" && "$OS" != "Linux" ]]; then
20+
abort "The install script is only supported on macOS and Linux."
21+
fi
22+
23+
check_cmd() {
24+
if ! command -v "$@" &> /dev/null
25+
then
26+
abort "You must install "$@" before running the install script."
27+
fi
28+
}
29+
30+
# Check if the commands to be used exist.
31+
for cmd in curl unzip; do
32+
check_cmd $cmd
33+
done
34+
35+
get_latest_release_number() {
36+
curl --silent "https://github.com/sourceplusplus/interface-cli/releases/latest" | sed 's#.*tag/\(.*\)\".*#\1#'
37+
}
38+
39+
# Get the latest version of spp-cli.
40+
VERSION=$(get_latest_release_number)
41+
echo "Installing spp-cli $VERSION"
42+
43+
# Download the binary package.
44+
curl -sSLO "https://github.com/sourceplusplus/interface-cli/releases/download/$VERSION/spp-cli-$VERSION-linux64.zip" > /dev/null
45+
if [ -f "spp-cli-$VERSION-linux64.zip" ]; then
46+
unzip -q spp-cli-$VERSION-linux64.zip
47+
48+
echo "Adding spp-cli to your PATH"
49+
# Add spp-cli to the environment variable PATH.
50+
sudo mv spp-cli /usr/local/bin/spp-cli
51+
52+
# Delete unnecessary files.
53+
rm "./spp-cli-$VERSION-linux64.zip"
54+
echo "Installation complete."
55+
56+
echo "Type 'spp-cli --help' to get more information."
57+
else
58+
abort "Failed to download spp-cli-$VERSION-linux64.zip"
59+
fi

0 commit comments

Comments
 (0)