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