-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Add Linux bash scripts for installation and management #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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).
WalkthroughFive 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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--usageto 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
rmdirwhich 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 +fiscripts/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 fiscripts/linux/update-cliproxyapi.sh (3)
12-12: Remove unused color variableYELLOW.The
YELLOWcolor 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 unusedREPO_URLvariable.The
REPO_URLconstant is defined but never used. The script only updates from an existingCLONE_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
&∧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" + fiscripts/linux/start-cliproxyapi.sh (1)
71-71: Usefindinstead oflsfor more robust file discovery.Line 71 uses
ls -tin command substitution, which can fail if log filenames contain special characters or spaces. Preferfindfor 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
📒 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" |
There was a problem hiding this comment.
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.
| 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}" |
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this 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>/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 |
There was a problem hiding this comment.
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>/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 "$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
+
+ BINARY_FILE=$(find . -type f -name "cliproxyapi*" ! -name "*.gz" ! -name "*.zip" | head -n1)
</file context>
Summary
Added Linux-ready equivalents of Windows PowerShell scripts in
scripts/linux/:install-cliproxyapi.shstart-cliproxyapi.shupdate-cliproxyapi.shuninstall-cliproxyapi.shcliproxyapi-oauth.shFeatures
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.
Written for commit 85b7906. Summary will update automatically on new commits.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.