Skip to content

(#9400 P1a) Replace POSIX [ ] with bash [[ ]] across build framework#9462

Merged
igorpecovnik merged 15 commits intomainfrom
fix/p1a-single-to-double-brackets
Mar 5, 2026
Merged

(#9400 P1a) Replace POSIX [ ] with bash [[ ]] across build framework#9462
igorpecovnik merged 15 commits intomainfrom
fix/p1a-single-to-double-brackets

Conversation

@iav
Copy link
Contributor

@iav iav commented Mar 2, 2026

Summary

Part of #9400 — bash syntax safety improvements.

P1a: Replace POSIX [ ] with bash [[ ]] across the build framework.

Why [[ ]] is safer than [ ]

  • [[ ]] is a bash keyword (not an external command), so unquoted variables inside it do not undergo word-splitting or glob expansion — eliminating a class of subtle bugs
  • && / || can be used inside [[ ]] instead of chaining separate [ ] && [ ] tests
  • Pattern matching (=~) and glob patterns (== with *) are supported natively
  • Numeric comparisons (-ge, -lt, etc.) work identically in both forms

Changes

15 files × 1 commit each (per project convention):

File Changes
lib/functions/image/partitioning.sh 3
lib/functions/host/prepare-host.sh 1
lib/functions/main/config-prepare.sh 1
lib/functions/configuration/main-config.sh 6
lib/functions/rootfs/distro-specific.sh 4
lib/functions/rootfs/distro-agnostic.sh 1 (+ collapse two [ ] && [ ] into one [[ && ]])
lib/functions/image/initrd.sh 1
lib/functions/image/fingerprint.sh 1
lib/functions/bsp/utils-bsp.sh 1
lib/functions/compilation/kernel-debs.sh 1
extensions/lowmem.sh 2
extensions/gxlimg.sh 2
config/sources/families/rockchip.conf 1 (+ quotes unquoted $1)
config/sources/families/spacemit.conf 1 (+ quotes unquoted ${2}boot0)
lib/functions/bsp/armbian-bsp-cli-deb.sh 43

Additional fixes bundled where naturally adjacent:

  • === in string comparisons (preferred style in [[ ]])
  • Paired [ A ] && [ B ] collapsed into single [[ A && B ]]
  • Unquoted variables inside [ ] tests that were at risk of word-splitting are now quoted

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Infrastructure improvements to build and configuration scripts across multiple system components to strengthen code robustness, consistency, and overall maintainability. These updates enhance script safety and reliability throughout the build process without introducing new features, altering user-facing functionality, affecting the end-user experience, or changing overall system behavior.

iav and others added 15 commits March 2, 2026 04:58
Replace POSIX `[ ]` with bash `[[ ]]` on three remaining single-bracket
conditionals: two numeric comparisons on sfdisk version (lines 251, 270)
and one -z test with unquoted variable (line 485, also adds quoting).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on one string comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on one array expansion check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o [[ ]]

Replace POSIX `[ ]` with bash `[[ ]]` on six conditionals: file existence
checks, string comparisons, and -n tests. Also normalise `=` to `==` in
the string comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…[ ]]

Replace POSIX `[ ]` with bash `[[ ]]` on four conditionals: file/path
existence checks and an array length comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…[ ]]

Replace two chained POSIX `[ ]` with a single bash `[[ ]]` using `&&`
inside the double brackets.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on one string comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on one -n test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on one directory existence check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…[[ ]]

Replace POSIX `[ ]` with bash `[[ ]]` on one numeric argument-count check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on two file existence checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]` on two file existence checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]`; also quote the unquoted `$1`
positional parameter inside the file test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace POSIX `[ ]` with bash `[[ ]]`; also quote the unquoted `${2}boot0`
expansion to prevent word-splitting on the path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…[[ ]]

Replace all 43 POSIX `[ ]` tests with bash `[[ ]]` across five board-side
package hook functions (preinst, postinst_base, postinst_finish,
postinst_update_uboot_bootscript, get_bootscript_info).

Normalise `=` to `==` in the `"$1" == "upgrade"` comparison.
Collapse paired `[ A ] && [ B ]` into a single `[[ A && B ]]` where possible.
Variables that were previously unquoted inside `[ ]` (e.g. ${BOOTSCRIPT_DST},
${BOOTSCRIPT_BACKUP_VERSION}) are now properly quoted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@iav iav requested review from a team and igorpecovnik as code owners March 2, 2026 03:14
@iav iav requested review from martinayotte and removed request for a team March 2, 2026 03:14
@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines 05 Milestone: Second quarter release labels Mar 2, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between efb4c68 and 775f380.

📒 Files selected for processing (15)
  • config/sources/families/rockchip.conf
  • config/sources/families/spacemit.conf
  • extensions/gxlimg.sh
  • extensions/lowmem.sh
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
  • lib/functions/bsp/utils-bsp.sh
  • lib/functions/compilation/kernel-debs.sh
  • lib/functions/configuration/main-config.sh
  • lib/functions/host/prepare-host.sh
  • lib/functions/image/fingerprint.sh
  • lib/functions/image/initrd.sh
  • lib/functions/image/partitioning.sh
  • lib/functions/main/config-prepare.sh
  • lib/functions/rootfs/distro-agnostic.sh
  • lib/functions/rootfs/distro-specific.sh

📝 Walkthrough

Walkthrough

This PR systematically replaces POSIX-style single-bracket test operators with Bash extended test operators across 15 shell script files, while improving variable quoting and normalizing path concatenation for safer evaluation.

Changes

Cohort / File(s) Summary
Config Source Families
config/sources/families/rockchip.conf, config/sources/families/spacemit.conf
Updated test operators from [ ] to [[ ]] with added variable quoting for safer shell evaluation in u-boot platform checks.
Extensions
extensions/gxlimg.sh, extensions/lowmem.sh
Replaced POSIX-style test operators with Bash extended tests in firmware extraction and lowmem configuration checks.
BSP Functions
lib/functions/bsp/armbian-bsp-cli-deb.sh, lib/functions/bsp/utils-bsp.sh
Systematically updated 44 test conditions from [ ... ] to [[ ... ]] across bootscript handling, post-install tasks, file existence checks, and permission-related conditionals with consistent quoting improvements.
Compilation & Configuration
lib/functions/compilation/kernel-debs.sh, lib/functions/configuration/main-config.sh
Updated test operators in argument count checks and file existence validation; normalized path concatenation style and improved quoting for f2fs kernel config checks.
Host & Image Functions
lib/functions/host/prepare-host.sh, lib/functions/image/fingerprint.sh, lib/functions/image/initrd.sh, lib/functions/image/partitioning.sh
Converted single-bracket tests to extended bracket tests in offline flag checks, argument validation, target directory checks, and version comparisons with added quoting for variables.
Main & Rootfs Functions
lib/functions/main/config-prepare.sh, lib/functions/rootfs/distro-agnostic.sh, lib/functions/rootfs/distro-specific.sh
Replaced [ ... ] with [[ ... ]] in kernel driver skip checks, DNS directory validation, and distro keyring/module existence checks with consistent quoting normalization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 From brackets old to brackets new,
The tests now bash-robust and true,
With quoted paths so safe and sound,
Our shell scripts dance without a bound! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.48% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly and specifically describes the main objective of the PR: replacing POSIX single-bracket tests with bash double-bracket conditionals across the build framework. It accurately summarizes the primary change without being vague or misleading.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/p1a-single-to-double-brackets

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.

@github-actions github-actions bot added Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Framework Framework components labels Mar 2, 2026
@github-actions github-actions bot added the Ready to merge Reviewed, tested and ready for merge label Mar 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions bot removed the Needs review Seeking for review label Mar 5, 2026
@igorpecovnik igorpecovnik merged commit ea547d6 into main Mar 5, 2026
13 checks passed
@igorpecovnik igorpecovnik deleted the fix/p1a-single-to-double-brackets branch March 5, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Framework Framework components Hardware Hardware related like kernel, U-Boot, ... Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines

Development

Successfully merging this pull request may close these issues.

2 participants