Harden generated install.sh/install.ps1 per shellcheck and PSScriptAnalyzer - #433
Merged
Merged
Conversation
Bourne (sh) generator - shellcheck fixes, keeping backticks and expr (not $(...) / $(( )) ) since the script must run on true Bourne shell on Solaris 9 and AIX 6.x: - Quote variable expansions that were vulnerable to word-splitting/ globbing (tmp_dir/stderr paths, project, download_dir, etc.) - Fix reversed '2>&1 >/dev/null' redirects in do_wget/do_curl/do_perl/ do_python so stderr is actually silenced - Replace 'tr '[A-Z]' '[a-z]'' with 'tr 'A-Z' 'a-z'' (bracketed classes are taken literally by POSIX tr) - Replace bashism 'source /etc/os-release' with '.' (source is undefined in POSIX sh) - Drop no-op self-assignments (e.g. https_proxy=$https_proxy) - Simplify useless echo/backtick round-trip in do_download - Quote the OPTIND shift substitution - Use printf instead of echo for the two debug blocks that rely on backslash escape expansion PowerShell generator - PSScriptAnalyzer fixes: - Fix a real bug: stray duplicate [string] type attribute on the $project parameter in Get-ProjectMetadata - Get-Win32OS caches to $script:win32OS instead of $global:win32OS since this all runs inside a new-module scriptblock - Swap $null to the left of -eq/-ne comparisons - Replace 'gi' and 'foreach' aliases with full cmdlet names - Rename Custom-GetFileHash/Is-FIPS to approved verbs (Get-CustomFileHash/Test-Fips) - Document the intentionally-empty console encoding catch block - Rewrite the omnitruck text-response parser as an explicit ForEach-Object -Begin/-Process/-End pipeline Ignore locally generated install.sh/install.ps1 test artifacts. Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
tpowell-progress
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Runs
shellcheck -s shagainst the generated Bourne (install.sh) script andPSScriptAnalyzeragainst the generated PowerShell (install.ps1) script, and fixes the real correctness/portability issues found in each generator template.Bourne (sh) generator
Kept backticks (not
$(...)) andexpr(not$(( ))) throughout, sinceinstall.sh's own header requires it to run on true Bourne shell on Solaris 9 and AIX 6.x, where neither is available.$tmp_dir/stderr,$project,$download_dir, etc.)2>&1 >/dev/nullredirects indo_wget/do_curl/do_perl/do_pythonso stderr is actually captured/silenced as intendedtr '[A-Z]' '[a-z]'withtr 'A-Z' 'a-z'— POSIXtrtreats bracketed classes literally, not as rangessource /etc/os-releasewith.—sourceis undefined in POSIX shhttps_proxy=$https_proxy)do_downloadOPTINDshift substitutionecho "\n...\n$var"toprintffor portable escape-sequence expansionPowerShell generator
[string]type attribute on the$projectparameter inGet-ProjectMetadataGet-Win32OSnow caches to$script:win32OSinstead of$global:win32OS, since this all executes inside anew-modulescriptblock and shouldn't leak into the caller's global session state$nullto the left side of-eq/-necomparisonsgiandforeachaliases with full cmdlet namesCustom-GetFileHash/Is-FIPSto approved verbs (Get-CustomFileHash/Test-Fips)catchblock instead of leaving it silently emptyForEach-Object -Begin/-Process/-Endpipeline instead of the positional-scriptblockforeach {}{}{}idiomExplicitly left alone (verified as intentional / false positive, not fixed)
SC2006(backticks vs$(...)) andSC2003(expr) — required for Solaris 9 / AIX 6.x/bin/shcompatibilityPSAvoidUsingWriteHost— this is a one-shot console install script, not a reusable module; direct console output is correct herePSAvoidUsingWMICmdlet(Get-WMIQuery) — already prefersGet-CimInstanceand only falls back toGet-WmiObjectfor older/restricted environmentsPSUseShouldProcessForStateChangingFunctions(New-Uri) — false positive, it only constructs aSystem.UriobjectPSUseSingularNouns(Get-ProjectMetadata,Test-Fips) — false positives on irregular/acronym nounsPSUseDeclaredVarsMoreThanAssignments($hash) — known analyzer limitation withForEach-Object -Begin/-Process/-Endvariable sharingTesting
sh -n install.sh— syntax OKshellcheck -s sh -S style install.sh— all remaining findings are the intentionally-skipped categories above (verified none of the real bug categories remain)[System.Management.Automation.Language.Parser]::ParseFile— parses cleanlyInvoke-ScriptAnalyzer -Severity Warning,Error— all remaining findings are the intentionally-skipped/false-positive categories aboveinstall.sh/install.ps1(local generator test output) to.gitignoreTypes of changes
Checklist