Skip to content

Make icp.sh POSIX-compatible (dash/sh safe) - #614

Open
manuranga wants to merge 1 commit into
wso2:mainfrom
manuranga:fix/icp-sh-posix-compat
Open

Make icp.sh POSIX-compatible (dash/sh safe)#614
manuranga wants to merge 1 commit into
wso2:mainfrom
manuranga:fix/icp-sh-posix-compat

Conversation

@manuranga

@manuranga manuranga commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Problem

The WSO2 Integrator extension launches icp.sh via:

l.spawn("sh", [e], {detached: true, env: ...})

On Ubuntu/Debian, /bin/sh is dash. The shebang (#!/bin/bash) is ignored since the extension invokes the script explicitly with sh. The script uses bash-only array syntax that dash cannot parse:

  • JAVA_OPTS=() — bash array initialization
  • JAVA_OPTS+=() — bash array append
  • "${JAVA_OPTS[@]}" — bash array expansion

dash fails with a hard syntax error at parse time:

/path/to/icp.sh: Syntax error: "(" unexpected

This prevents ICP from starting when launched from the extension on Ubuntu/Debian.

It works on macOS and Fedora/RHEL because /bin/sh is bash on those platforms:

Platform /bin/sh Works?
macOS bash
Fedora/RHEL bash
Ubuntu/Debian dash

Fix

Replace bash arrays with a plain string variable — the only construct that dash cannot handle. The shebang stays as #!/bin/bash (the script uses local and may add other bash features in the future).

When JAVA_OPTS is empty, the unquoted $JAVA_OPTS expands to nothing (no spurious empty argument passed to java).

Verified: dash -n icp.sh passes.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The launcher script distribution/scripts/icp.sh is converted from bash to POSIX-compatible shell by updating the shebang and refactoring argument handling. The JAVA_OPTS variable is changed from a bash array (using += operator and "${JAVA_OPTS[@]}" expansion) to a simple string with direct space-separated assignments. Java process invocation in both background and foreground modes is updated to use unquoted string expansion instead of array expansion. Alpine-specific Netty system properties are preserved in the refactored string format.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description provides clear problem statement, root cause analysis, and solution with verification, but omits most template sections required by the repository. Complete the missing sections from the template: Goals, Approach, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, and Learning.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: converting the bash script to POSIX-compatible sh by removing bash-specific array syntax.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@distribution/scripts/icp.sh`:
- Line 1: The script uses the bash-only keyword "local" which breaks POSIX
/bin/sh; remove each "local" declaration and replace it with a plain assignment
(e.g., myvar="value") or, if you need scoping, run the code in a subshell or
prefix variables with a unique name (e.g., _myvar) to avoid collisions; update
every occurrence of "local" in the script so functions and assignments (the
places where local was used) use POSIX-compatible assignments instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c316131b-ca70-4926-a730-8b4971db6ebc

📥 Commits

Reviewing files that changed from the base of the PR and between 742c83f and ef1b177.

📒 Files selected for processing (1)
  • distribution/scripts/icp.sh

Comment thread distribution/scripts/icp.sh Outdated
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read-only check for non-POSIX `local` declarations in the launcher.
# This should list every line that still needs to be rewritten for sh compatibility.
rg -n '\blocal\b' distribution/scripts/icp.sh

Repository: wso2/integration-control-plane

Length of output: 161


🏁 Script executed:

# Check the shebang on line 1
head -1 distribution/scripts/icp.sh

# Read the file to see the full context of local declarations
cat -n distribution/scripts/icp.sh | head -100

Repository: wso2/integration-control-plane

Length of output: 3776


Remove local declarations to match POSIX sh shebang.

The shebang changed to /bin/sh, but the code still uses the bash-specific local keyword at lines 37, 47, 67, and 78. These declarations will fail in POSIX-compliant sh environments (e.g., dash), preventing the script from running. Replace local declarations with unscoped variable assignment or use alternative approaches compatible with POSIX sh.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@distribution/scripts/icp.sh` at line 1, The script uses the bash-only keyword
"local" which breaks POSIX /bin/sh; remove each "local" declaration and replace
it with a plain assignment (e.g., myvar="value") or, if you need scoping, run
the code in a subshell or prefix variables with a unique name (e.g., _myvar) to
avoid collisions; update every occurrence of "local" in the script so functions
and assignments (the places where local was used) use POSIX-compatible
assignments instead.

The WSO2 Integrator extension invokes this script via `sh icp.sh`
(not `bash icp.sh`), so on Ubuntu where /bin/sh is dash, bash-only
syntax breaks:

- `JAVA_OPTS=()` — bash array init
- `JAVA_OPTS+=(...)` — bash array append
- `"${JAVA_OPTS[@]}"` — bash array expansion

Replace with plain string variable. When JAVA_OPTS is empty, the
unquoted $JAVA_OPTS expands to nothing (no empty arg passed to java).

Verified: `dash -n icp.sh` passes.
@manuranga
manuranga force-pushed the fix/icp-sh-posix-compat branch from ef1b177 to d029ec4 Compare April 28, 2026 08:08
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