Skip to content

Commit 9461fc7

Browse files
feature: make a script that is easier to do one-line install across OS's
1 parent 8cb3b5a commit 9461fc7

2 files changed

Lines changed: 147 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Install Script Tests
2+
3+
on:
4+
push:
5+
paths:
6+
- 'install-cli.sh'
7+
- '.github/workflows/install-script-tests.yaml'
8+
pull_request:
9+
paths:
10+
- 'install-cli.sh'
11+
- '.github/workflows/install-script-tests.yaml'
12+
13+
jobs:
14+
test-script:
15+
name: Test Bash Script on ${{ matrix.os }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
matrix:
19+
os: [ubuntu-latest, macos-latest, windows-latest]
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v5
24+
25+
- name: Set up Bash on Windows
26+
if: runner.os == 'Windows'
27+
uses: msys2/setup-msys2@v2
28+
with:
29+
install: bash
30+
31+
- name: Run script on Linux/macOS
32+
if: runner.os != 'Windows'
33+
run: bash install-cli.sh
34+
35+
- name: Run script on Windows (MSYS2 Bash)
36+
if: runner.os == 'Windows'
37+
shell: msys2 {0}
38+
run: bash install-cli.sh
39+
40+
- name: Verify installation
41+
run: kosli version

install-cli.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/sh
2+
set -u
3+
4+
# This script downloads the OS- and architecture-specific Kosli CLI binary,
5+
# extracts it, and moves the executable to a directory in your PATH.
6+
7+
# --- Configuration ---
8+
CLI_OS="unknown"
9+
ARCH="unknown"
10+
VERSION=""
11+
FILE_NAME="kosli"
12+
13+
# --- Version Selection ---
14+
if [ $# -eq 1 ]; then
15+
VERSION=$1
16+
echo "Downloading specified version $VERSION of Kosli CLI..."
17+
else
18+
echo "Detecting the latest version of Kosli CLI..."
19+
# Fetches the latest release tag from the GitHub API
20+
LATEST_TAG=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
21+
if [ -z "$LATEST_TAG" ]; then
22+
echo "Error: Could not fetch the latest version tag from GitHub."
23+
exit 1
24+
fi
25+
VERSION=$LATEST_TAG
26+
echo "Latest version is $VERSION. Downloading..."
27+
fi
28+
echo ""
29+
30+
# Strip the 'v' prefix for use in the filename, e.g., v2.11.22 -> 2.11.22
31+
VERSION_FILENAME=$(echo "$VERSION" | sed 's/^v//')
32+
33+
# --- OS and Architecture Detection ---
34+
if uname -s | grep -q -E -i "(cygwin|mingw|msys|windows)"; then
35+
CLI_OS="windows"
36+
ARCH="amd64"
37+
FILE_NAME="${FILE_NAME}.exe"
38+
elif uname -s | grep -q -i "darwin"; then
39+
CLI_OS="darwin"
40+
if [ "$(uname -m)" = "arm64" ]; then
41+
ARCH="arm64"
42+
else
43+
ARCH="amd64"
44+
fi
45+
else
46+
CLI_OS="linux"
47+
MACHINE_TYPE="$(uname -m)"
48+
case $MACHINE_TYPE in
49+
amd64 | x86_64 | x64)
50+
ARCH="amd64"
51+
;;
52+
aarch64 | arm64)
53+
ARCH="arm64"
54+
;;
55+
*)
56+
echo "Error: Unsupported Linux architecture: $MACHINE_TYPE"
57+
echo "Kosli CLI is only available for amd64 and arm64 on Linux."
58+
exit 1
59+
;;
60+
esac
61+
fi
62+
63+
# --- Download and Extract ---
64+
# The download is a .tar.gz file which needs to be extracted
65+
URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.tar.gz"
66+
echo "Downloading from: $URL"
67+
68+
# Download and extract in one go
69+
if ! curl -L --fail "$URL" | tar zx; then
70+
echo "Error: Download or extraction failed. Please check the URL and your network connection."
71+
exit 1
72+
fi
73+
74+
# --- Installation ---
75+
# Move the extracted binary to a directory in the user's PATH
76+
echo "Installing Kosli CLI..."
77+
set -- "/usr/local/bin" "/usr/bin" "/opt/bin"
78+
while [ -n "$1" ]; do
79+
# Check if destination directory exists and is in the PATH
80+
if [ -d "$1" ] && echo "$PATH" | grep -q "$1"; then
81+
if mv "$FILE_NAME" "$1/"; then
82+
echo ""
83+
echo "✅ Kosli CLI was successfully installed in $1"
84+
echo "Running 'kosli version' to verify:"
85+
kosli version
86+
exit 0
87+
else
88+
echo ""
89+
echo "Attempting to install with sudo..."
90+
echo "We'd like to install the Kosli CLI executable in '$1'. Please enter your password if prompted."
91+
if sudo mv "$FILE_NAME" "$1/"; then
92+
echo ""
93+
echo "✅ Kosli CLI was successfully installed in $1"
94+
echo "Running 'kosli version' to verify:"
95+
kosli version
96+
exit 0
97+
fi
98+
fi
99+
fi
100+
shift
101+
done
102+
103+
echo ""
104+
echo "Error: Could not install Kosli CLI."
105+
echo "Please move the '$FILE_NAME' executable manually to a directory in your \$PATH."
106+
exit 1

0 commit comments

Comments
 (0)