From 9461fc7d913a9bc69eced343430deca0b30e5a16 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 25 Sep 2025 13:44:47 +0200 Subject: [PATCH 01/16] feature: make a script that is easier to do one-line install across OS's --- .github/workflows/install-script-tests.yml | 41 ++++++++ install-cli.sh | 106 +++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 .github/workflows/install-script-tests.yml create mode 100644 install-cli.sh diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml new file mode 100644 index 000000000..273dba632 --- /dev/null +++ b/.github/workflows/install-script-tests.yml @@ -0,0 +1,41 @@ +name: Install Script Tests + +on: + push: + paths: + - 'install-cli.sh' + - '.github/workflows/install-script-tests.yaml' + pull_request: + paths: + - 'install-cli.sh' + - '.github/workflows/install-script-tests.yaml' + +jobs: + test-script: + name: Test Bash Script on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Set up Bash on Windows + if: runner.os == 'Windows' + uses: msys2/setup-msys2@v2 + with: + install: bash + + - name: Run script on Linux/macOS + if: runner.os != 'Windows' + run: bash install-cli.sh + + - name: Run script on Windows (MSYS2 Bash) + if: runner.os == 'Windows' + shell: msys2 {0} + run: bash install-cli.sh + + - name: Verify installation + run: kosli version \ No newline at end of file diff --git a/install-cli.sh b/install-cli.sh new file mode 100644 index 000000000..2dae57289 --- /dev/null +++ b/install-cli.sh @@ -0,0 +1,106 @@ +#!/bin/sh +set -u + +# This script downloads the OS- and architecture-specific Kosli CLI binary, +# extracts it, and moves the executable to a directory in your PATH. + +# --- Configuration --- +CLI_OS="unknown" +ARCH="unknown" +VERSION="" +FILE_NAME="kosli" + +# --- Version Selection --- +if [ $# -eq 1 ]; then + VERSION=$1 + echo "Downloading specified version $VERSION of Kosli CLI..." +else + echo "Detecting the latest version of Kosli CLI..." + # Fetches the latest release tag from the GitHub API + LATEST_TAG=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + if [ -z "$LATEST_TAG" ]; then + echo "Error: Could not fetch the latest version tag from GitHub." + exit 1 + fi + VERSION=$LATEST_TAG + echo "Latest version is $VERSION. Downloading..." +fi +echo "" + +# Strip the 'v' prefix for use in the filename, e.g., v2.11.22 -> 2.11.22 +VERSION_FILENAME=$(echo "$VERSION" | sed 's/^v//') + +# --- OS and Architecture Detection --- +if uname -s | grep -q -E -i "(cygwin|mingw|msys|windows)"; then + CLI_OS="windows" + ARCH="amd64" + FILE_NAME="${FILE_NAME}.exe" +elif uname -s | grep -q -i "darwin"; then + CLI_OS="darwin" + if [ "$(uname -m)" = "arm64" ]; then + ARCH="arm64" + else + ARCH="amd64" + fi +else + CLI_OS="linux" + MACHINE_TYPE="$(uname -m)" + case $MACHINE_TYPE in + amd64 | x86_64 | x64) + ARCH="amd64" + ;; + aarch64 | arm64) + ARCH="arm64" + ;; + *) + echo "Error: Unsupported Linux architecture: $MACHINE_TYPE" + echo "Kosli CLI is only available for amd64 and arm64 on Linux." + exit 1 + ;; + esac +fi + +# --- Download and Extract --- +# The download is a .tar.gz file which needs to be extracted +URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.tar.gz" +echo "Downloading from: $URL" + +# Download and extract in one go +if ! curl -L --fail "$URL" | tar zx; then + echo "Error: Download or extraction failed. Please check the URL and your network connection." + exit 1 +fi + +# --- Installation --- +# Move the extracted binary to a directory in the user's PATH +echo "Installing Kosli CLI..." +set -- "/usr/local/bin" "/usr/bin" "/opt/bin" +while [ -n "$1" ]; do + # Check if destination directory exists and is in the PATH + if [ -d "$1" ] && echo "$PATH" | grep -q "$1"; then + if mv "$FILE_NAME" "$1/"; then + echo "" + echo "✅ Kosli CLI was successfully installed in $1" + echo "Running 'kosli version' to verify:" + kosli version + exit 0 + else + echo "" + echo "Attempting to install with sudo..." + echo "We'd like to install the Kosli CLI executable in '$1'. Please enter your password if prompted." + if sudo mv "$FILE_NAME" "$1/"; then + echo "" + echo "✅ Kosli CLI was successfully installed in $1" + echo "Running 'kosli version' to verify:" + kosli version + exit 0 + fi + fi + fi + shift +done + +echo "" +echo "Error: Could not install Kosli CLI." +echo "Please move the '$FILE_NAME' executable manually to a directory in your \$PATH." +exit 1 \ No newline at end of file From 15711dcc045a1641f5c9755d6ceeccee31b87d76 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 25 Sep 2025 13:50:05 +0200 Subject: [PATCH 02/16] Fix download URL handling for Windows and Linux in install script --- install-cli.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install-cli.sh b/install-cli.sh index 2dae57289..e4f8bbe01 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -62,7 +62,11 @@ fi # --- Download and Extract --- # The download is a .tar.gz file which needs to be extracted -URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.tar.gz" +if [ "$CLI_OS" = "windows" ]; then + URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.zip" +else + URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.tar.gz" +fi echo "Downloading from: $URL" # Download and extract in one go From 9314bbbd1e2dae923be0bc84c034ac5500ed51fd Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 25 Sep 2025 13:52:20 +0200 Subject: [PATCH 03/16] Improve error handling for download failures in install script --- install-cli.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/install-cli.sh b/install-cli.sh index e4f8bbe01..6862c3fb6 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -61,18 +61,22 @@ else fi # --- Download and Extract --- -# The download is a .tar.gz file which needs to be extracted +# The download is a .tar.gz or .zip file which needs to be extracted if [ "$CLI_OS" = "windows" ]; then URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.zip" + # Download and extract for Windows + if ! curl -L --fail "$URL" -o kosli.zip; then + echo "Error: Download failed. Please check the URL and your network connection." + exit 1 + fi + unzip -o kosli.zip else URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.tar.gz" -fi -echo "Downloading from: $URL" - -# Download and extract in one go -if ! curl -L --fail "$URL" | tar zx; then - echo "Error: Download or extraction failed. Please check the URL and your network connection." - exit 1 + # Download and extract for Linux and Darwin + if ! curl -L --fail "$URL" | tar zx; then + echo "Error: Download or extraction failed. Please check the URL and your network connection." + exit 1 + fi fi # --- Installation --- From 6d88f763580d1b1dc93ce678c8b922e6180ad8e8 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Fri, 26 Sep 2025 09:24:13 +0200 Subject: [PATCH 04/16] refactor: simplify Windows script execution in install tests --- .github/workflows/install-script-tests.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 273dba632..08e8b033b 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -22,20 +22,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 - - name: Set up Bash on Windows - if: runner.os == 'Windows' - uses: msys2/setup-msys2@v2 - with: - install: bash - - name: Run script on Linux/macOS - if: runner.os != 'Windows' + shell: bash run: bash install-cli.sh - - name: Run script on Windows (MSYS2 Bash) - if: runner.os == 'Windows' - shell: msys2 {0} - run: bash install-cli.sh - - name: Verify installation + shell: bash run: kosli version \ No newline at end of file From b08d04551a4b55cc4dcf95ca0dbb1280a895f5f2 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Fri, 26 Sep 2025 09:28:28 +0200 Subject: [PATCH 05/16] fix: correct file extension from .yaml to .yml in workflow paths --- .github/workflows/install-script-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 08e8b033b..3efe57fef 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -4,11 +4,11 @@ on: push: paths: - 'install-cli.sh' - - '.github/workflows/install-script-tests.yaml' + - '.github/workflows/install-script-tests.yml' pull_request: paths: - 'install-cli.sh' - - '.github/workflows/install-script-tests.yaml' + - '.github/workflows/install-script-tests.yml' jobs: test-script: From 383a4dc3301adb95babd845febba6055345e2916 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Mon, 29 Sep 2025 12:24:47 +0200 Subject: [PATCH 06/16] feat: enable manual triggering of install script tests --- .github/workflows/install-script-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 3efe57fef..cbecf549c 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -9,6 +9,7 @@ on: paths: - 'install-cli.sh' - '.github/workflows/install-script-tests.yml' + workflow_dispatch: jobs: test-script: From 1767d69d8381df6d7045f96bb5bfb62814f4e5aa Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 30 Sep 2025 12:21:22 +0200 Subject: [PATCH 07/16] fix: improve error handling in install script --- install-cli.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install-cli.sh b/install-cli.sh index 6862c3fb6..0ff3aa7c5 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -1,5 +1,5 @@ #!/bin/sh -set -u +set -eu # This script downloads the OS- and architecture-specific Kosli CLI binary, # extracts it, and moves the executable to a directory in your PATH. @@ -111,4 +111,5 @@ done echo "" echo "Error: Could not install Kosli CLI." echo "Please move the '$FILE_NAME' executable manually to a directory in your \$PATH." +echo "For example, you can run: sudo mv \"$FILE_NAME\" /usr/local/bin/" exit 1 \ No newline at end of file From e090e3e506375accba4157fbe5bdb95c15f6bdaa Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 2 Oct 2025 16:29:05 +0200 Subject: [PATCH 08/16] feat: add debug mode and improve version detection in install script --- install-cli.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/install-cli.sh b/install-cli.sh index 0ff3aa7c5..6102ec1b8 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -9,48 +9,88 @@ CLI_OS="unknown" ARCH="unknown" VERSION="" FILE_NAME="kosli" +DEBUG=false + +# --- Debug function --- +debug_print() { + if [ "$DEBUG" = true ]; then + echo "DEBUG: $1" >&2 + fi +} + +# --- Parse arguments --- +while [ $# -gt 0 ]; do + case $1 in + --debug) + DEBUG=true + debug_print "Debug mode enabled" + shift + ;; + *) + VERSION=$1 + debug_print "Version specified: $VERSION" + shift + ;; + esac +done # --- Version Selection --- -if [ $# -eq 1 ]; then - VERSION=$1 +if [ -n "$VERSION" ]; then echo "Downloading specified version $VERSION of Kosli CLI..." + debug_print "Using specified version: $VERSION" else echo "Detecting the latest version of Kosli CLI..." + debug_print "Fetching latest version from GitHub API" # Fetches the latest release tag from the GitHub API LATEST_TAG=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + debug_print "GitHub API response tag: $LATEST_TAG" if [ -z "$LATEST_TAG" ]; then echo "Error: Could not fetch the latest version tag from GitHub." exit 1 fi VERSION=$LATEST_TAG echo "Latest version is $VERSION. Downloading..." + debug_print "Set VERSION to: $VERSION" fi echo "" # Strip the 'v' prefix for use in the filename, e.g., v2.11.22 -> 2.11.22 VERSION_FILENAME=$(echo "$VERSION" | sed 's/^v//') +debug_print "VERSION_FILENAME after stripping 'v': $VERSION_FILENAME" # --- OS and Architecture Detection --- +debug_print "Detecting OS and architecture" +debug_print "uname -s output: $(uname -s)" +debug_print "uname -m output: $(uname -m)" + if uname -s | grep -q -E -i "(cygwin|mingw|msys|windows)"; then CLI_OS="windows" ARCH="amd64" FILE_NAME="${FILE_NAME}.exe" + debug_print "Detected Windows OS" elif uname -s | grep -q -i "darwin"; then CLI_OS="darwin" + debug_print "Detected Darwin/macOS" if [ "$(uname -m)" = "arm64" ]; then ARCH="arm64" + debug_print "Detected ARM64 architecture" else ARCH="amd64" + debug_print "Detected AMD64 architecture" fi else CLI_OS="linux" + debug_print "Detected Linux OS" MACHINE_TYPE="$(uname -m)" + debug_print "Machine type: $MACHINE_TYPE" case $MACHINE_TYPE in amd64 | x86_64 | x64) ARCH="amd64" + debug_print "Mapped to AMD64 architecture" ;; aarch64 | arm64) ARCH="arm64" + debug_print "Mapped to ARM64 architecture" ;; *) echo "Error: Unsupported Linux architecture: $MACHINE_TYPE" @@ -60,54 +100,77 @@ else esac fi +debug_print "Final values - CLI_OS: $CLI_OS, ARCH: $ARCH, FILE_NAME: $FILE_NAME" + # --- Download and Extract --- # The download is a .tar.gz or .zip file which needs to be extracted if [ "$CLI_OS" = "windows" ]; then URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.zip" + debug_print "Windows URL constructed: $URL" + echo "Downloading from: $URL" # Download and extract for Windows + debug_print "Starting Windows download and extraction" if ! curl -L --fail "$URL" -o kosli.zip; then echo "Error: Download failed. Please check the URL and your network connection." exit 1 fi + debug_print "Download completed, extracting zip file" unzip -o kosli.zip + debug_print "Extraction completed" else URL="https://github.com/kosli-dev/cli/releases/download/${VERSION}/kosli_${VERSION_FILENAME}_${CLI_OS}_${ARCH}.tar.gz" + debug_print "Unix URL constructed: $URL" + echo "Downloading from: $URL" # Download and extract for Linux and Darwin + debug_print "Starting Unix download and extraction" if ! curl -L --fail "$URL" | tar zx; then echo "Error: Download or extraction failed. Please check the URL and your network connection." exit 1 fi + debug_print "Download and extraction completed" fi # --- Installation --- # Move the extracted binary to a directory in the user's PATH echo "Installing Kosli CLI..." +debug_print "Starting installation process" +debug_print "Current PATH: $PATH" set -- "/usr/local/bin" "/usr/bin" "/opt/bin" while [ -n "$1" ]; do + debug_print "Checking directory: $1" # Check if destination directory exists and is in the PATH if [ -d "$1" ] && echo "$PATH" | grep -q "$1"; then + debug_print "Directory $1 exists and is in PATH" + debug_print "Attempting to move $FILE_NAME to $1" if mv "$FILE_NAME" "$1/"; then echo "" echo "✅ Kosli CLI was successfully installed in $1" echo "Running 'kosli version' to verify:" + debug_print "Installation successful, running version check" kosli version exit 0 else echo "" echo "Attempting to install with sudo..." echo "We'd like to install the Kosli CLI executable in '$1'. Please enter your password if prompted." + debug_print "Regular move failed, trying with sudo" if sudo mv "$FILE_NAME" "$1/"; then echo "" echo "✅ Kosli CLI was successfully installed in $1" echo "Running 'kosli version' to verify:" + debug_print "Sudo installation successful, running version check" kosli version exit 0 fi + debug_print "Sudo move also failed for $1" fi + else + debug_print "Directory $1 either doesn't exist or is not in PATH" fi shift done +debug_print "All installation attempts failed" echo "" echo "Error: Could not install Kosli CLI." echo "Please move the '$FILE_NAME' executable manually to a directory in your \$PATH." From 9e9c0c24534c26ab805a41f9609d60042d55a375 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 2 Oct 2025 16:32:44 +0200 Subject: [PATCH 09/16] fix: improve OS and architecture detection in install script --- install-cli.sh | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/install-cli.sh b/install-cli.sh index 6102ec1b8..6862b8525 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -63,15 +63,17 @@ debug_print "Detecting OS and architecture" debug_print "uname -s output: $(uname -s)" debug_print "uname -m output: $(uname -m)" -if uname -s | grep -q -E -i "(cygwin|mingw|msys|windows)"; then +UNAME_S=$(uname -s) +if echo "$UNAME_S" | grep -q -E -i "(cygwin|mingw|msys|windows)"; then CLI_OS="windows" ARCH="amd64" FILE_NAME="${FILE_NAME}.exe" debug_print "Detected Windows OS" -elif uname -s | grep -q -i "darwin"; then +elif echo "$UNAME_S" | grep -q -i "darwin"; then CLI_OS="darwin" debug_print "Detected Darwin/macOS" - if [ "$(uname -m)" = "arm64" ]; then + UNAME_M=$(uname -m) + if [ "$UNAME_M" = "arm64" ]; then ARCH="arm64" debug_print "Detected ARM64 architecture" else @@ -135,16 +137,17 @@ fi echo "Installing Kosli CLI..." debug_print "Starting installation process" debug_print "Current PATH: $PATH" -set -- "/usr/local/bin" "/usr/bin" "/opt/bin" -while [ -n "$1" ]; do - debug_print "Checking directory: $1" + +# Check directories one by one instead of using set -- +for dir in "/usr/local/bin" "/usr/bin" "/opt/bin"; do + debug_print "Checking directory: $dir" # Check if destination directory exists and is in the PATH - if [ -d "$1" ] && echo "$PATH" | grep -q "$1"; then - debug_print "Directory $1 exists and is in PATH" - debug_print "Attempting to move $FILE_NAME to $1" - if mv "$FILE_NAME" "$1/"; then + if [ -d "$dir" ] && echo "$PATH" | grep -q "$dir"; then + debug_print "Directory $dir exists and is in PATH" + debug_print "Attempting to move $FILE_NAME to $dir" + if mv "$FILE_NAME" "$dir/"; then echo "" - echo "✅ Kosli CLI was successfully installed in $1" + echo "✅ Kosli CLI was successfully installed in $dir" echo "Running 'kosli version' to verify:" debug_print "Installation successful, running version check" kosli version @@ -152,22 +155,21 @@ while [ -n "$1" ]; do else echo "" echo "Attempting to install with sudo..." - echo "We'd like to install the Kosli CLI executable in '$1'. Please enter your password if prompted." + echo "We'd like to install the Kosli CLI executable in '$dir'. Please enter your password if prompted." debug_print "Regular move failed, trying with sudo" - if sudo mv "$FILE_NAME" "$1/"; then + if sudo mv "$FILE_NAME" "$dir/"; then echo "" - echo "✅ Kosli CLI was successfully installed in $1" + echo "✅ Kosli CLI was successfully installed in $dir" echo "Running 'kosli version' to verify:" debug_print "Sudo installation successful, running version check" kosli version exit 0 fi - debug_print "Sudo move also failed for $1" + debug_print "Sudo move also failed for $dir" fi else - debug_print "Directory $1 either doesn't exist or is not in PATH" + debug_print "Directory $dir either doesn't exist or is not in PATH" fi - shift done debug_print "All installation attempts failed" From b9b6390277c61109045c74a93fb47e1da33fb95d Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 2 Oct 2025 16:37:13 +0200 Subject: [PATCH 10/16] Tidy up description of steps in the CI job --- .github/workflows/install-script-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index cbecf549c..10ee93660 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -23,7 +23,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 - - name: Run script on Linux/macOS + - name: Run install scriptt shell: bash run: bash install-cli.sh From bc83abd7a1e7657082a9c9a12918ed2db8d418ae Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Thu, 2 Oct 2025 16:45:58 +0200 Subject: [PATCH 11/16] fix: correct typo in install script step and enable debug mode --- .github/workflows/install-script-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 10ee93660..25c059738 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -23,9 +23,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 - - name: Run install scriptt + - name: Run install script shell: bash - run: bash install-cli.sh + run: bash install-cli.sh --debug - name: Verify installation shell: bash From 2e99e89cf38af7ce91939148e589c441521016bf Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Fri, 3 Oct 2025 08:56:33 +0200 Subject: [PATCH 12/16] fix: enhance GitHub API response handling for latest version detection --- install-cli.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install-cli.sh b/install-cli.sh index 6862b8525..206425ee9 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -42,7 +42,11 @@ else echo "Detecting the latest version of Kosli CLI..." debug_print "Fetching latest version from GitHub API" # Fetches the latest release tag from the GitHub API - LATEST_TAG=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest") + debug_print "GitHub API response: $METADATA" + TAG_NAME=$(echo "$METADATA" | grep '"tag_name":') + debug_print "GitHub API response tag: $TAG_NAME" + LATEST_TAG=$(echo "$TAG_NAME" | sed -E 's/.*"([^"]+)".*/\1/') debug_print "GitHub API response tag: $LATEST_TAG" if [ -z "$LATEST_TAG" ]; then echo "Error: Could not fetch the latest version tag from GitHub." From 45d397c7eb1c67859fbf2a98391b97e15510c12f Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Fri, 3 Oct 2025 09:04:03 +0200 Subject: [PATCH 13/16] fix: improve retry mechanism for fetching latest version from GitHub API --- install-cli.sh | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/install-cli.sh b/install-cli.sh index 206425ee9..124da35a0 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -41,20 +41,38 @@ if [ -n "$VERSION" ]; then else echo "Detecting the latest version of Kosli CLI..." debug_print "Fetching latest version from GitHub API" - # Fetches the latest release tag from the GitHub API - METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest") - debug_print "GitHub API response: $METADATA" - TAG_NAME=$(echo "$METADATA" | grep '"tag_name":') - debug_print "GitHub API response tag: $TAG_NAME" - LATEST_TAG=$(echo "$TAG_NAME" | sed -E 's/.*"([^"]+)".*/\1/') - debug_print "GitHub API response tag: $LATEST_TAG" - if [ -z "$LATEST_TAG" ]; then - echo "Error: Could not fetch the latest version tag from GitHub." - exit 1 - fi - VERSION=$LATEST_TAG - echo "Latest version is $VERSION. Downloading..." - debug_print "Set VERSION to: $VERSION" + + # Retry mechanism for fetching the latest version + RETRY_COUNT=0 + MAX_RETRIES=5 + while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do + METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest") + debug_print "GitHub API response: $METADATA" + + # Check if the response contains the expected tag_name + if echo "$METADATA" | grep -q '"tag_name":'; then + TAG_NAME=$(echo "$METADATA" | grep '"tag_name":') + debug_print "GitHub API response tag: $TAG_NAME" + LATEST_TAG=$(echo "$TAG_NAME" | sed -E 's/.*"([^"]+)".*/\1/') + debug_print "GitHub API response tag: $LATEST_TAG" + if [ -z "$LATEST_TAG" ]; then + echo "Error: Could not fetch the latest version tag from GitHub." + exit 1 + fi + VERSION=$LATEST_TAG + echo "Latest version is $VERSION. Downloading..." + debug_print "Set VERSION to: $VERSION" + break + else + echo "Warning: GitHub API response did not contain a valid tag_name. Retrying in 5 seconds..." + sleep 5 + RETRY_COUNT=$((RETRY_COUNT + 1)) + if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then + echo "Error: GitHub rate limit exceeded too many times." + exit 1 + fi + fi + done fi echo "" From 810d62286b82a3bc5b57eab536264c8f432cd5c5 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Mon, 6 Oct 2025 12:59:18 +0200 Subject: [PATCH 14/16] fix: add GitHub token support to install script for authenticated API requests --- .github/workflows/install-script-tests.yml | 2 +- install-cli.sh | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 25c059738..d26d13d08 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -25,7 +25,7 @@ jobs: - name: Run install script shell: bash - run: bash install-cli.sh --debug + run: bash install-cli.sh --debug --token ${{ secrets.GITHUB_TOKEN }} - name: Verify installation shell: bash diff --git a/install-cli.sh b/install-cli.sh index 124da35a0..36a5b70a4 100644 --- a/install-cli.sh +++ b/install-cli.sh @@ -10,6 +10,7 @@ ARCH="unknown" VERSION="" FILE_NAME="kosli" DEBUG=false +GITHUB_TOKEN="" # --- Debug function --- debug_print() { @@ -26,6 +27,16 @@ while [ $# -gt 0 ]; do debug_print "Debug mode enabled" shift ;; + --token) + if [ -n "${2:-}" ]; then + GITHUB_TOKEN="$2" + debug_print "GitHub token provided" + shift 2 + else + echo "Error: --token requires a value" + exit 1 + fi + ;; *) VERSION=$1 debug_print "Version specified: $VERSION" @@ -46,7 +57,13 @@ else RETRY_COUNT=0 MAX_RETRIES=5 while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do - METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest") + if [ -n "$GITHUB_TOKEN" ]; then + debug_print "Using GitHub token for API request" + METADATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/kosli-dev/cli/releases/latest") + else + debug_print "Using unauthenticated API request" + METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest") + fi debug_print "GitHub API response: $METADATA" # Check if the response contains the expected tag_name From 7848564d3a20f3abb0ab78b254c29cc21bfad007 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Mon, 6 Oct 2025 13:48:03 +0200 Subject: [PATCH 15/16] fix: update installation instructions for Kosli CLI to include script and Docker usage --- .../content/getting_started/install.md | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/docs.kosli.com/content/getting_started/install.md b/docs.kosli.com/content/getting_started/install.md index 5616c54e5..52425120f 100644 --- a/docs.kosli.com/content/getting_started/install.md +++ b/docs.kosli.com/content/getting_started/install.md @@ -11,6 +11,28 @@ Kosli CLI can be installed from package managers, by Curling pre-built binaries, or can be used from the distributed Docker images. {{< tabs "installKosli" >}} +{{< tab "Script" >}} +You can download the correct Kosli CLI for your platform, given that you can run bash on it, by invoking this one-line script: + +```shell {.command} +curl -fL https://raw.githubusercontent.com/kosli-dev/cli/refs/heads/main/install-cli.sh | sh +``` +{{< /tab >}} + +{{< tab "Docker" >}} +You can run the Kosli CLI with docker: +```shell {.command} +docker run --rm ghcr.io/kosli-dev/cli:v{{< cli-version >}} +``` +The `entrypoint` for this container is the kosli command. + +To run any kosli command you append it to the `docker run` command above – +without the `kosli` keyword. For example to run `kosli version`: +```shell {.command} +docker run --rm ghcr.io/kosli-dev/cli:v{{< cli-version >}} version +``` +{{< /tab >}} + {{< tab "Homebrew" >}} If you have [Homebrew](https://brew.sh/) (available on MacOS, Linux or Windows Subsystem for Linux), you can install the Kosli CLI by running: @@ -64,20 +86,7 @@ For example, on Mac with AMD: curl -L https://github.com/kosli-dev/cli/releases/download/v{{< cli-version >}}/kosli_{{< cli-version >}}_darwin_amd64.tar.gz | tar zx sudo mv kosli /usr/local/bin/kosli ``` -{{< /tab >}} - -{{< tab "Docker" >}} -You can run the Kosli CLI with docker: -```shell {.command} -docker run --rm ghcr.io/kosli-dev/cli:v{{< cli-version >}} -``` -The `entrypoint` for this container is the kosli command. -To run any kosli command you append it to the `docker run` command above – -without the `kosli` keyword. For example to run `kosli version`: -```shell {.command} -docker run --rm ghcr.io/kosli-dev/cli:v{{< cli-version >}} version -``` {{< /tab >}} {{< tab "From source" >}} From d58d72c1cee1fd37bc828b5c25cc52fd29cfe226 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Mon, 6 Oct 2025 14:50:47 +0200 Subject: [PATCH 16/16] fix: update wording in installation instructions for clarity --- docs.kosli.com/content/getting_started/install.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs.kosli.com/content/getting_started/install.md b/docs.kosli.com/content/getting_started/install.md index 52425120f..d07e53400 100644 --- a/docs.kosli.com/content/getting_started/install.md +++ b/docs.kosli.com/content/getting_started/install.md @@ -12,7 +12,7 @@ by Curling pre-built binaries, or can be used from the distributed Docker images {{< tabs "installKosli" >}} {{< tab "Script" >}} -You can download the correct Kosli CLI for your platform, given that you can run bash on it, by invoking this one-line script: +You can download the correct Kosli CLI for your platform, given that you can run shell scripts on it, by invoking this one-line script: ```shell {.command} curl -fL https://raw.githubusercontent.com/kosli-dev/cli/refs/heads/main/install-cli.sh | sh