Skip to content

fix: reliable Ubuntu version check and safe apt glob removal in setup.sh - #231

Merged
PDowney merged 3 commits into
masterfrom
copilot/fix-ubuntu-version-comparison
May 2, 2026
Merged

PDowney merged 3 commits into
masterfrom
copilot/fix-ubuntu-version-comparison

Conversation

Copilot AI commented May 2, 2026

Copy link
Copy Markdown
Contributor

Two shell scripting hazards in setup.sh: bc-based floating-point version comparison (unreliable) and unquoted apt glob patterns (unsafe shell expansion).

Software Version Updates

Changed Versions

  • No version changes — shell logic fixes only.

Version Diff

- UBUNTU_VERSION="$(lsb_release -sr)"
- Noble=24.04
- if (( $(bc <<<"$UBUNTU_VERSION != $Noble") )); then
+ UBUNTU_VERSION_INT="$(tr -d '.' <<<"$UBUNTU_VERSION")"
+ NOBLE_INT=2404
+ if (( UBUNTU_VERSION_INT != NOBLE_INT )); then

- apt-get remove apache2* php7* php8* -y
+ apt-get remove --purge 'apache2*' 'php7*' 'php8*' -y

Verification Checklist

  • Version numbers are correctly formatted
  • Version numbers are stable releases (not beta/RC)
  • No syntax errors in variables file

Notes

Ubuntu version check — strips the decimal from lsb_release -sr output (24.042404) and compares as integers with (( )), eliminating the bc dependency and floating-point ambiguity. Variable renamed to NOBLE_INT per project UPPER_CASE convention.

apt cleanup — adds --purge to remove residual config files, and quotes glob patterns to prevent unintended shell expansion before apt-get receives them.

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The version comparison uses floating-point arithmetic via `bc` which may produce unreliable results. Use integer comparison instead by removing the decimal point: `UBUNTU_VERSION_INT=$(echo \\\"$UBUNTU_VERSION\\\" | tr -d '.')` and `Noble_INT=2404`, then compare with `(( UBUNTU_VERSION_INT != Noble_INT ))`.","fixFiles":[{"filePath":"setup.sh","diff":"diff --git a/setup.sh b/setup.sh\n--- a/setup.sh\n+++ b/setup.sh\n@@ -37,9 +37,10 @@\n \n # Check if Ubuntu is 24.04 LTS Release. If not, exit.\n UBUNTU_VERSION=\"$(lsb_release -sr)\"\n-Noble=24.04\n+UBUNTU_VERSION_INT=\"$(echo \"$UBUNTU_VERSION\" | tr -d '.')\"\n+Noble_INT=2404\n \n-if (( $(bc <<<\"$UBUNTU_VERSION != $Noble\") )); then\n+if (( UBUNTU_VERSION_INT != Noble_INT )); then\n   echo \"ALERT:\"\n   echo \"EngineScript does not support Ubuntu $UBUNTU_VERSION. We recommend using Ubuntu 24.04 LTS\"\n   exit 1\n"}]},{"message":"Using glob patterns directly in apt-get remove can be dangerous and may not work as expected. Consider using `apt-get remove --purge 'apache2*' 'php7*' 'php8*' -y` with quotes, or use a more explicit approach with `dpkg -l | grep` to find and remove packages.","fixFiles":[{"filePath":"setup.sh","diff":"diff --git a/setup.sh b/setup.sh\n--- a/setup.sh\n+++ b/setup.sh\n@@ -197,7 +197,7 @@\n fi\n \n # Cleanup\n-apt-get remove apache2* php7* php8* -y\n+apt-get remove --purge 'apache2*' 'php7*' 'php8*' -y\n \n # Update & Upgrade\n apt update --allow-releaseinfo-change -y\n"}]}]

Copilot AI changed the title [WIP] Fix unreliable Ubuntu version comparison in setup script fix: reliable Ubuntu version check and safe apt glob removal in setup.sh May 2, 2026
Copilot finished work on behalf of PDowney May 2, 2026 05:26
Copilot AI requested a review from PDowney May 2, 2026 05:26
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sonarqubecloud

sonarqubecloud Bot commented May 2, 2026

Copy link
Copy Markdown

@PDowney
PDowney marked this pull request as ready for review May 2, 2026 06:12
Copilot AI review requested due to automatic review settings May 2, 2026 06:12
@PDowney
PDowney merged commit f14a828 into master May 2, 2026
12 checks passed
@github-actions
github-actions Bot deleted the copilot/fix-ubuntu-version-comparison branch May 2, 2026 06:13

Copilot AI 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.

Pull request overview

This PR hardens setup.sh, the repository’s top-level bootstrap script for provisioning an EngineScript Ubuntu host, by making the Ubuntu release check independent of bc and by preventing shell expansion during package cleanup.

Changes:

  • Replace the bc-based Ubuntu 24.04 comparison with an integer comparison derived from lsb_release -sr.
  • Quote the package patterns passed to apt-get remove and add --purge so cleanup is safer and more predictable.

Comment thread setup.sh
Comment on lines +40 to +43
UBUNTU_VERSION_INT="$(tr -d '.' <<<"$UBUNTU_VERSION")"
NOBLE_INT=2404

if (( $(bc <<<"$UBUNTU_VERSION != $Noble") )); then
if (( UBUNTU_VERSION_INT != NOBLE_INT )); then
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.

3 participants