install: Add cleanup step#3759
Merged
patrickelectric merged 1 commit intobluerobotics:masterfrom Feb 4, 2026
Merged
Conversation
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Reviewer's GuideAdds a reusable function to compute available disk space in MB and introduces a pre-installation disk cleanup sequence (apt caches, apt lists, non-English locales) before enforcing a minimum free-space check in the installer. Sequence diagram for installer disk space computation and cleanupsequenceDiagram
participant Installer as install_sh
participant FS as filesystem
participant AptCache as apt_cache
participant AptLists as apt_lists
participant Locale as locales
Installer->>FS: stat -f / --format %a
FS-->>Installer: free_blocks
Installer->>FS: stat -f / --format %S
FS-->>Installer: block_size
Installer->>Installer: compute AVAILABLE_SPACE_MB
Installer->>Installer: set NECESSARY_SPACE_MB = 1024
Installer->>Installer: echo available and required space
Installer->>AptCache: check /var/cache/apt
alt cache dir exists
Installer->>AptCache: du -sh /var/cache/apt
AptCache-->>Installer: size
Installer->>AptCache: apt-get clean
end
Installer->>AptLists: check /var/lib/apt/lists
alt lists dir exists
Installer->>AptLists: du -sh /var/lib/apt/lists
AptLists-->>Installer: size
Installer->>AptLists: rm -rf /var/lib/apt/lists/*
end
Installer->>Locale: check /usr/share/locale
alt locale dir exists
Installer->>Locale: du -sh /usr/share/locale
Locale-->>Installer: size
Installer->>Locale: find non en* dirs and rm -rf
end
Installer->>Installer: echo Disk cleanup complete
Installer->>FS: stat -f / (recompute)
FS-->>Installer: free_blocks, block_size
Installer->>Installer: compute AVAILABLE_SPACE_MB after cleanup
Installer->>Installer: echo Available space after cleanup
alt insufficient space
Installer->>Installer: echo error and exit 1
else sufficient space
Installer->>Installer: continue installation
end
Flow diagram for pre-installation disk space check and cleanupflowchart TD
A[start_install_script] --> B[echo Checking for available space]
B --> C[call get_available_space_mb]
C --> D[set AVAILABLE_SPACE_MB]
D --> E[set NECESSARY_SPACE_MB = 1024]
E --> F[echo Available and required space]
F --> G[echo Attempting to free up disk space]
G --> H{dir /var/cache/apt exists}
H -- yes --> H1[echo Cleaning /var/cache/apt size]
H1 --> H2[apt-get clean]
H -- no --> I
H2 --> I{dir /var/lib/apt/lists exists}
I -- yes --> I1[echo Cleaning /var/lib/apt/lists size]
I1 --> I2[rm -rf /var/lib/apt/lists/*]
I -- no --> J
I2 --> J{dir /usr/share/locale exists}
J -- yes --> J1[echo Cleaning non english locale files size]
J1 --> J2[find /usr/share/locale ! -name en* -exec rm -rf]
J -- no --> K
J2 --> K[echo Disk cleanup complete]
K --> L[call get_available_space_mb]
L --> M[set AVAILABLE_SPACE_MB after cleanup]
M --> N[echo Available space after cleanup]
N --> O{AVAILABLE_SPACE_MB < NECESSARY_SPACE_MB}
O -- yes --> P[echo Not enough free space and exit 1]
O -- no --> Q[continue installation]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The disk cleanup logic runs unconditionally on every install; consider only triggering the cleanup when AVAILABLE_SPACE_MB is below NECESSARY_SPACE_MB to avoid surprising data removal on systems that already have sufficient free space.
- The
rm -rfof all non-en*locales under/usr/share/localeis quite aggressive and may break non-English environments; it might be safer to either narrow the paths, make this opt-in, or gate it behind a configuration flag.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The disk cleanup logic runs unconditionally on every install; consider only triggering the cleanup when AVAILABLE_SPACE_MB is below NECESSARY_SPACE_MB to avoid surprising data removal on systems that already have sufficient free space.
- The `rm -rf` of all non-`en*` locales under `/usr/share/locale` is quite aggressive and may break non-English environments; it might be safer to either narrow the paths, make this opt-in, or gate it behind a configuration flag.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Williangalvani
approved these changes
Feb 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.
Summary by Sourcery
Add a pre-installation disk space check with automatic cleanup to ensure sufficient free space before installing.
Enhancements: