Skip to content

Conversation

@ujang19
Copy link

@ujang19 ujang19 commented Dec 11, 2025

Summary

Added Linux-ready equivalents of Windows PowerShell scripts in scripts/linux/:

Script Description
install-cliproxyapi.sh Complete installer (prebuilt download or source build)
start-cliproxyapi.sh Server management (start/stop/restart/status/logs)
update-cliproxyapi.sh Update to latest version
uninstall-cliproxyapi.sh Clean uninstallation with options
cliproxyapi-oauth.sh OAuth login helper for all providers

Features

  • Auto-detect architecture (amd64/arm64)
  • Support both prebuilt binary download and source compilation
  • Background daemon mode with PID tracking
  • Colorful output with status indicators
  • Interactive OAuth menu

Testing

Tested on Ubuntu 22.04 LTS - all scripts working correctly.


Contribution from @websee-id


Summary by cubic

Added Linux bash scripts to install, manage, update, and uninstall CLIProxyAPI-Plus, plus an OAuth login helper. This brings parity with the Windows scripts and makes Linux setup and control straightforward.

  • New Features
    • install-cliproxyapi.sh: auto install via prebuilt or source; creates config and adds to PATH.
    • start-cliproxyapi.sh: start/stop/restart/status/logs with background mode and PID tracking.
    • update-cliproxyapi.sh: update from source or latest release (amd64/arm64 auto-detect).
    • uninstall-cliproxyapi.sh: remove binary, config, logs; optional full cleanup of auth files.
    • cliproxyapi-oauth.sh: interactive or flag-based logins for providers (Gemini, Copilot, Claude, Qwen, etc.).

Written for commit 85b7906. Summary will update automatically on new commits.

Summary by CodeRabbit

  • New Features
    • Added OAuth authentication CLI with interactive provider selection and bulk login options
    • Added automated installation script with support for both prebuilt binaries and source builds
    • Added service manager supporting start, stop, restart, status checks, and log viewing
    • Added uninstall utility with selective cleanup options for configuration and authentication data
    • Added automatic update mechanism to download and apply the latest application binary

✏️ Tip: You can customize this high-level summary in your review settings.

Added Linux-ready equivalents of Windows PowerShell scripts:
- install-cliproxyapi.sh: Complete installer (prebuilt/source build)
- start-cliproxyapi.sh: Server management (start/stop/restart/status)
- update-cliproxyapi.sh: Update to latest version
- uninstall-cliproxyapi.sh: Clean uninstallation
- cliproxyapi-oauth.sh: OAuth login helper for all providers

All scripts support the same functionality as their Windows counterparts
with proper Linux conventions (bash, systemd-friendly background mode).
@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

Five new Bash scripts added to manage CLIProxyAPI-Plus on Linux: OAuth login CLI, installation automation, service lifecycle control, uninstallation, and binary updates. Scripts support multiple modes (interactive/non-interactive), fallback logic (prebuilt vs. source builds), configuration management, and colored terminal output.

Changes

Cohort / File(s) Summary
Linux CLI Management Suite
scripts/linux/install-cliproxyapi.sh, scripts/linux/start-cliproxyapi.sh, scripts/linux/uninstall-cliproxyapi.sh, scripts/linux/update-cliproxyapi.sh
Installation automation with fallback from source to prebuilt; service lifecycle management (start, stop, status, logs, restart) with PID and port tracking; binary updates via prebuilt download or source rebuild with git; complete uninstallation with optional auth file cleanup.
OAuth Authentication CLI
scripts/linux/cliproxyapi-oauth.sh
Interactive and non-interactive OAuth login flow supporting multiple providers; provider mapping to CLI arguments; central login function with colored output and final auth summary.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • install-cliproxyapi.sh: Review fallback logic (prebuilt vs. source, tool availability checks), architecture detection, binary extraction, and config file generation.
  • update-cliproxyapi.sh: Verify git fetch/pull/reset logic, GitHub API asset selection, binary replacement safety, and cleanup of temporary files.
  • start-cliproxyapi.sh: Validate PID management, process detection, background/foreground execution, and health check implementation.
  • uninstall-cliproxyapi.sh: Confirm complete cleanup paths, conditional auth file removal, and config sanitization (especially jq fallback).
  • cliproxyapi-oauth.sh: Check provider mapping consistency, error handling in binary invocation, and interactive menu flow.

Poem

🐰 Five scripts hop into place,
Installation, starts, and updates to embrace!
OAuth logins dance in the shell,
While uninstalls clean up quite well—
Clickety-clack, your CLI's in grace! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changeset, which introduces a comprehensive set of Linux Bash scripts for installation and management of CLIProxyAPI-Plus.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (8)
scripts/linux/cliproxyapi-oauth.sh (1)

53-66: Allow help/usage message via standard flags.

The argument parsing silently discards unknown flags (line 64, *) shift ;;). Consider supporting --help, -h, or --usage to display usage information to users who might pass invalid arguments.

scripts/linux/uninstall-cliproxyapi.sh (2)

70-72: Add error handling for jq operation and verify command availability.

Line 70 checks if jq exists with command -v jq, but doesn't verify that the jq operation on line 71 succeeded. If the JSON manipulation fails, the config is left in an inconsistent state.

-if [ -f "$FACTORY_CONFIG" ] && command -v jq &>/dev/null; then
-    jq '.custom_models = []' "$FACTORY_CONFIG" > "$FACTORY_CONFIG.tmp" && mv "$FACTORY_CONFIG.tmp" "$FACTORY_CONFIG"
-    echo -e "${GREEN}[+] Cleared custom_models from Droid config${NC}"
-fi
+if [ -f "$FACTORY_CONFIG" ] && command -v jq &>/dev/null; then
+    if jq '.custom_models = []' "$FACTORY_CONFIG" > "$FACTORY_CONFIG.tmp"; then
+        mv "$FACTORY_CONFIG.tmp" "$FACTORY_CONFIG"
+        echo -e "${GREEN}[+] Cleared custom_models from Droid config${NC}"
+    else
+        rm -f "$FACTORY_CONFIG.tmp"
+        echo -e "${YELLOW}[!] Could not update factory config${NC}"
+    fi
+fi

66-66: Handle incomplete directory cleanup gracefully.

Line 66 uses rmdir which silently fails if the directory is not empty. If the directory cleanup doesn't work, orphaned files may remain. Consider checking if cleanup succeeded or log a warning.

-if [ "$REMOVE_ALL" = true ]; then
-    rm -f "$CONFIG_DIR"/*.json && echo -e "${GREEN}[+] Auth files removed${NC}"
-    rmdir "$CONFIG_DIR" 2>/dev/null
-fi
+if [ "$REMOVE_ALL" = true ]; then
+    rm -f "$CONFIG_DIR"/*.json && echo -e "${GREEN}[+] Auth files removed${NC}"
+    if rmdir "$CONFIG_DIR" 2>/dev/null; then
+        echo -e "${GREEN}[+] Config directory removed${NC}"
+    else
+        echo -e "${YELLOW}[!] Config directory not empty, keeping as-is${NC}"
+    fi
+fi
scripts/linux/install-cliproxyapi.sh (1)

80-104: Add explicit error handling for prebuilt binary extraction and fallback logic.

Lines 95 silently ignores extraction failures with || true, which masks problems. Additionally, the fallback to source build (line 90) is triggered based on missing download URL, but also should check if extraction/binary discovery succeeded.

 if [ "$HAS_JQ" = true ]; then
     RELEASE_INFO=$(curl -s -H "User-Agent: Bash" "$RELEASE_API")
     DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r ".assets[] | select(.name | contains(\"$ARCH_SUFFIX\")) | .browser_download_url" | head -n1)
 else
     RELEASE_INFO=$(curl -s -H "User-Agent: Bash" "$RELEASE_API")
     DOWNLOAD_URL=$(echo "$RELEASE_INFO" | grep -o "https://[^\"]*${ARCH_SUFFIX}[^\"]*" | head -n1)
 fi
 
 if [ -z "$DOWNLOAD_URL" ] || [ "$DOWNLOAD_URL" = "null" ]; then
     write_warning "No prebuilt found, building from source..."
     FORCE_SOURCE=true
 else
     echo "    Downloading..."
     curl -sL -o "$TEMP_DIR/archive.tar.gz" "$DOWNLOAD_URL"
     cd "$TEMP_DIR"
-    tar -xzf archive.tar.gz 2>/dev/null || unzip -q archive.tar.gz 2>/dev/null || true
+    if ! tar -xzf archive.tar.gz 2>/dev/null && ! unzip -q archive.tar.gz 2>/dev/null; then
+        write_warning "Failed to extract binary, building from source..."
+        FORCE_SOURCE=true
+    else
-    BINARY_FILE=$(find . -type f -name "cliproxyapi*" ! -name "*.gz" ! -name "*.zip" | head -n1)
-    if [ -n "$BINARY_FILE" ]; then
-        chmod +x "$BINARY_FILE"
-        mv "$BINARY_FILE" "$BIN_DIR/$BINARY_NAME"
-        write_success "Binary installed: $BIN_DIR/$BINARY_NAME"
-    fi
-    rm -rf "$TEMP_DIR"
+        BINARY_FILE=$(find . -type f -name "cliproxyapi*" ! -name "*.gz" ! -name "*.zip" | head -n1)
+        if [ -n "$BINARY_FILE" ]; then
+            chmod +x "$BINARY_FILE"
+            mv "$BINARY_FILE" "$BIN_DIR/$BINARY_NAME"
+            write_success "Binary installed: $BIN_DIR/$BINARY_NAME"
+        else
+            write_warning "Binary not found in archive, building from source..."
+            FORCE_SOURCE=true
+        fi
+        rm -rf "$TEMP_DIR"
+    fi
 fi
scripts/linux/update-cliproxyapi.sh (3)

12-12: Remove unused color variable YELLOW.

The YELLOW color variable is defined but never used in the script. Remove the dead code or use it for warning messages.

-RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
+RED='\033[0;31m'; GREEN='\033[0;32m'

15-15: Remove unused REPO_URL variable.

The REPO_URL constant is defined but never used. The script only updates from an existing CLONE_DIR, not by cloning fresh. Remove the unused constant.

-REPO_URL="https://github.com/router-for-me/CLIProxyAPIPlus.git"
 RELEASE_API="https://api.github.com/repos/router-for-me/CLIProxyAPIPlus/releases/latest"

80-80: Clarify command chaining and improve backup safety.

Line 80 chains commands with mixed && and ; operators. The intent is to back up the old binary, then install the new one atomically, but the structure is unclear. Additionally, backup failure is silently ignored (2>/dev/null), risking data loss if the cp fails.

-    BINARY_FILE=$(find . -type f -name "cliproxyapi*" ! -name "*.gz" ! -name "*.zip" | head -n1)
-    [ -n "$BINARY_FILE" ] && cp "$BINARY_PATH" "$BINARY_PATH.old" 2>/dev/null; chmod +x "$BINARY_FILE"; mv "$BINARY_FILE" "$BINARY_PATH"
+    BINARY_FILE=$(find . -type f -name "cliproxyapi*" ! -name "*.gz" ! -name "*.zip" | head -n1)
+    if [ -n "$BINARY_FILE" ]; then
+        if ! cp "$BINARY_PATH" "$BINARY_PATH.old" 2>/dev/null; then
+            echo -e "${RED}[-] Failed to backup existing binary${NC}"
+            exit 1
+        fi
+        chmod +x "$BINARY_FILE"
+        mv "$BINARY_FILE" "$BINARY_PATH"
+    fi
scripts/linux/start-cliproxyapi.sh (1)

71-71: Use find instead of ls for more robust file discovery.

Line 71 uses ls -t in command substitution, which can fail if log filenames contain special characters or spaces. Prefer find for robustness.

-    LATEST=$(ls -t "$LOG_DIR"/*.log 2>/dev/null | head -n1)
+    LATEST=$(find "$LOG_DIR" -maxdepth 1 -name "*.log" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -n1 | cut -d' ' -f2-)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b2f888 and 85b7906.

📒 Files selected for processing (5)
  • scripts/linux/cliproxyapi-oauth.sh (1 hunks)
  • scripts/linux/install-cliproxyapi.sh (1 hunks)
  • scripts/linux/start-cliproxyapi.sh (1 hunks)
  • scripts/linux/uninstall-cliproxyapi.sh (1 hunks)
  • scripts/linux/update-cliproxyapi.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.11.0)
scripts/linux/start-cliproxyapi.sh

[warning] 89-89: Quote this to prevent word splitting.

(SC2046)

scripts/linux/install-cliproxyapi.sh

[warning] 62-62: DOWNLOAD_CMD appears unused. Verify use (or export if used externally).

(SC2034)

scripts/linux/update-cliproxyapi.sh

[warning] 12-12: YELLOW appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 15-15: REPO_URL appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (1)
scripts/linux/start-cliproxyapi.sh (1)

52-52: Verify health check logic for API availability.

Line 52 checks for HTTP 200 or 401 as indicators of API responsiveness. While 401 (Unauthorized) does indicate the endpoint exists, verify this is intentional—most health checks expect 2xx status codes. If 401 responses can legitimately occur without proper auth, consider documenting this behavior.

command -v git &> /dev/null || { write_error "Git not installed"; exit 1; }
write_success "Git found"

command -v curl &> /dev/null && DOWNLOAD_CMD="curl" || DOWNLOAD_CMD="wget"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove unused DOWNLOAD_CMD variable.

The DOWNLOAD_CMD variable is set on line 62 but never used. The script hardcodes curl -s directly throughout. Remove the dead code.

-command -v curl &> /dev/null && DOWNLOAD_CMD="curl" || DOWNLOAD_CMD="wget"
 command -v jq &> /dev/null && HAS_JQ=true || HAS_JQ=false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
command -v curl &> /dev/null && DOWNLOAD_CMD="curl" || DOWNLOAD_CMD="wget"
command -v jq &> /dev/null && HAS_JQ=true || HAS_JQ=false
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 62-62: DOWNLOAD_CMD appears unused. Verify use (or export if used externally).

(SC2034)

🤖 Prompt for AI Agents
In scripts/linux/install-cliproxyapi.sh around line 62, the DOWNLOAD_CMD
variable is assigned but never used; remove the dead assignment line (command -v
curl &> /dev/null && DOWNLOAD_CMD="curl" || DOWNLOAD_CMD="wget") so the script
no longer defines an unused variable, and verify there are no other references
to DOWNLOAD_CMD elsewhere in the file before committing.

nohup "$BINARY" --config "$CONFIG" >> "$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
sleep 2
ps -p $(cat "$PID_FILE") &>/dev/null && echo -e "${GREEN}[+] Started (PID: $(cat $PID_FILE))${NC}\nEndpoint: http://localhost:$PORT/v1" || echo -e "${RED}[-] Failed to start${NC}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Quote $PID_FILE to prevent word splitting in command substitution.

Line 89 uses $(cat $PID_FILE) without quotes. If the PID file path contains spaces (unlikely but possible), this breaks. Quote the variable: $(cat "$PID_FILE").

-        ps -p $(cat "$PID_FILE") &>/dev/null && echo -e "${GREEN}[+] Started (PID: $(cat $PID_FILE))${NC}\nEndpoint: http://localhost:$PORT/v1" || echo -e "${RED}[-] Failed to start${NC}"
+        ps -p $(cat "$PID_FILE") &>/dev/null && echo -e "${GREEN}[+] Started (PID: $(cat "$PID_FILE"))${NC}\nEndpoint: http://localhost:$PORT/v1" || echo -e "${RED}[-] Failed to start${NC}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ps -p $(cat "$PID_FILE") &>/dev/null && echo -e "${GREEN}[+] Started (PID: $(cat $PID_FILE))${NC}\nEndpoint: http://localhost:$PORT/v1" || echo -e "${RED}[-] Failed to start${NC}"
ps -p $(cat "$PID_FILE") &>/dev/null && echo -e "${GREEN}[+] Started (PID: $(cat "$PID_FILE"))${NC}\nEndpoint: http://localhost:$PORT/v1" || echo -e "${RED}[-] Failed to start${NC}"
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 89-89: Quote this to prevent word splitting.

(SC2046)

🤖 Prompt for AI Agents
In scripts/linux/start-cliproxyapi.sh around line 89, the command substitution
uses $(cat $PID_FILE) unquoted which can cause word-splitting if the PID file
path contains spaces; update the line to quote the variable everywhere it’s used
(use $(cat "$PID_FILE") and "$PID_FILE" in ps -p if applicable) so the PID file
path is treated as a single token and command substitutions are safe.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="scripts/linux/update-cliproxyapi.sh">

<violation number="1" location="scripts/linux/update-cliproxyapi.sh:77">
P2: Silent failure on archive extraction. Both `tar` and `unzip` errors are suppressed with `2&gt;/dev/null`, and `|| true` ensures the script continues regardless. If extraction fails, the subsequent `find` will return empty and the broken command on line 77 will execute with empty arguments.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR


curl -sL -o "$TEMP_DIR/archive.tar.gz" "$DOWNLOAD_URL"
cd "$TEMP_DIR"
tar -xzf archive.tar.gz 2>/dev/null || unzip -q archive.tar.gz 2>/dev/null || true
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Silent failure on archive extraction. Both tar and unzip errors are suppressed with 2>/dev/null, and || true ensures the script continues regardless. If extraction fails, the subsequent find will return empty and the broken command on line 77 will execute with empty arguments.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/linux/update-cliproxyapi.sh, line 77:

<comment>Silent failure on archive extraction. Both `tar` and `unzip` errors are suppressed with `2&gt;/dev/null`, and `|| true` ensures the script continues regardless. If extraction fails, the subsequent `find` will return empty and the broken command on line 77 will execute with empty arguments.</comment>

<file context>
@@ -0,0 +1,93 @@
+    
+    curl -sL -o &quot;$TEMP_DIR/archive.tar.gz&quot; &quot;$DOWNLOAD_URL&quot;
+    cd &quot;$TEMP_DIR&quot;
+    tar -xzf archive.tar.gz 2&gt;/dev/null || unzip -q archive.tar.gz 2&gt;/dev/null || true
+    
+    BINARY_FILE=$(find . -type f -name &quot;cliproxyapi*&quot; ! -name &quot;*.gz&quot; ! -name &quot;*.zip&quot; | head -n1)
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant