Skip to content

fix(build.func): expand glob in SSH key "Scan Folder/Glob" so it can find keys#15873

Merged
tremor021 merged 2 commits into
community-scripts:mainfrom
TowyTowy:fix/build-func-ssh-glob-scan
Jul 19, 2026
Merged

fix(build.func): expand glob in SSH key "Scan Folder/Glob" so it can find keys#15873
tremor021 merged 2 commits into
community-scripts:mainfrom
TowyTowy:fix/build-func-ssh-glob-scan

Conversation

@TowyTowy

Copy link
Copy Markdown
Contributor

✍️ Description

The advanced-install SSH key menu offers "folder — Scan another folder (path or glob)", but the input is split with:

shopt -s nullglob
read -r -a _scan_files <<<"$glob_path"
shopt -u nullglob

read performs no pathname expansion (nullglob has no effect on it), so _scan_files holds the literal pattern and ssh_build_choices_from_files() runs [[ -f ... ]] against it. Both advertised inputs therefore always fail: a glob like /root/.ssh/*.pub is tested as a literal filename, and a plain folder fails -f because it is a directory. The option unconditionally ends in "No keys found" and has never been able to import a key (behavior introduced in #9540).

This PR expands the pattern with compgen -G — the same glob-existence idiom as #15841 — and treats a directory input as dir/*, so both input forms shown in the input box work.

Standalone repro (folder containing one.pub, two backup.pub, known_hosts):

input: /tmp/keys/*.pub   -> old code finds 0 key files, fixed code finds 2
input: /tmp/keys         -> old code finds 0 key files, fixed code finds 2

shellcheck findings on misc/build.func: 34 before, 34 after (no new findings); bash -n clean under bash 5.2. Testing scope: verified via the standalone repro (buggy and fixed blocks lifted verbatim) and shellcheck; not run through the full whiptail flow on a live Proxmox host.

Disclosure: this fix was prepared with AI assistance (Claude); the bug, repro, and diff were verified by running the shown commands.

🔗 Related Issue

Fixes # (none filed — found via shellcheck-guided audit; behavior introduced in #9540)

✅ Prerequisites (X in brackets)

  • Self-review completed – Code follows project standards.
  • Tested thoroughly – Changes work as expected (scope as stated above).
  • No security risks – No hardcoded secrets, unnecessary privilege escalations, or permission issues.

🛠️ Type of Change (X in brackets)

  • 🐞 Bug fix – Resolves an issue without breaking functionality.
  • New feature – Adds new, non-breaking functionality.
  • 💥 Breaking change – Alters existing functionality in a way that may require updates.
  • 🆕 New script – A fully functional and tested script or script set.
  • 🌍 Website update – Changes to script metadata (PocketBase/website data).
  • 🔧 Refactoring / Code Cleanup – Improves readability or maintainability without changing functionality.
  • 📝 Documentation update – Changes to README, AppName.md, CONTRIBUTING.md, or other docs.

The advanced SSH key source menu offers "folder — Scan another folder
(path or glob)", but the input was split with read -r -a, which performs
no pathname expansion (the surrounding shopt -s nullglob has no effect on
read). ssh_build_choices_from_files() then ran [[ -f ... ]] against the
literal pattern (or the directory itself), so every folder or glob input
ended in "No keys found" and the option could never import a key.

Expand the pattern with compgen -G instead (same idiom as community-scripts#15841) and
treat a directory input as dir/*, so both advertised input forms work.

Co-Authored-By: Claude <noreply@anthropic.com>
@TowyTowy
TowyTowy requested a review from a team as a code owner July 18, 2026 10:15
Comment thread misc/build.func Outdated
does the same thing as proposed PR but in less lines
@tremor021
tremor021 merged commit e1ce55b into community-scripts:main Jul 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants