Skip to content

Dietpi banner upgrades - #8172

Open
timjolson wants to merge 68 commits into
MichaIng:devfrom
timjolson:dietpi-banner
Open

Dietpi banner upgrades#8172
timjolson wants to merge 68 commits into
MichaIng:devfrom
timjolson:dietpi-banner

Conversation

@timjolson

Copy link
Copy Markdown
Contributor

Enhancing dietpi-banner.

  • Changed custom entry to accept multiple commands
  • Added network usage by namespace
  • Added disk usage by pattern matching
  • Added systemd and fail2ban status
  • Standardized printing
  • Organized color resources
  • Added G_TRUNCATE_MID

@timjolson

timjolson commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Outstanding items I know of:

  • no IPv6 detection for the network traffic, only ipv4
  • dynamic disk space usage is independent of the pre-existing disk space entries (what do we do with the existing options?)
  • wrapping has not been tested or dealt with
  • IP address and network information (retrieval and parsing) use different methods than are pre-existing in the script - need to work through what might be more robust / efficient and consolidate to helper functions
  • no handling of permissions checking is in place yet
  • there sometimes is an issue with the terminal not being properly cleared when running dietpi-banner 1, probably applies to dietpi-banner 0, as well. The issue occurs often when using VSCode and has not been verified in other terminals.

@MichaIng MichaIng added this to the v10.6 milestone Jun 15, 2026
Comment thread dietpi/func/dietpi-banner Outdated

@MichaIng MichaIng left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A great extension! But there is some cleanup/polishing needed to reduce the overhead (in code an UI), and make it work for expected use cases.

Comment thread dietpi/func/dietpi-banner
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
@MichaIng
MichaIng force-pushed the dietpi-banner branch 2 times, most recently from 3dde41b to 78d815c Compare July 7, 2026 15:46
Comment thread dietpi/func/dietpi-globals Outdated
@MichaIng
MichaIng force-pushed the dietpi-banner branch 2 times, most recently from 68a40de to 2cdb0c2 Compare July 9, 2026 16:18
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
@MichaIng

MichaIng commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Just as an overview, the things I'd still want to do before merging. But will do so before DietPi v10.6 release (which will be delayed anyway because of a spontaneous holiday trip consuming some time this week):

  • Move array index migration to https://github.com/MichaIng/DietPi/blob/master/.update/patches, so we do not need to carry the code here, but just do this once with a sed loop or so.
  • Migrate existing /boot/dietpi/.dietpi-banner_custom and aDESCRIPTION[10] into the new custom command array.
  • Migrate/Replace aENABLED[disk_rootfs] and aENABLED[disk_userdata] with aDISK_SPACE_PATTERNS.
  • When adding a disk space pattern, findmnt -nro TARGET --real output lines, which are not matched yet, are offered in the menu directly, with "custom" allowing to enter a custom pattern. I'd also list all active pattern in the primary menu, showing the inputbox to edit them on select, removing them by emptying the inputbox, + the "Add" entry.
  • Instead of scraping the df output, findmnt -nro TARGET,USED,SIZE,USE% --real might be the cleaner alternative. Though, interestingly it is much slower as I just recognized, taking about 3x more time to process. Alternative is df -h --output=target,used,size,pcent, and we skip the redundancy math + skip separate percent calculation? There is no reason to assume used or size wouldn't be available. Or if used wouldn't be for some special mounts, avail wouldn't be available either. If higher precision and/or aligned unit is wanted the -m flag could be used instead of -h to get MiB values, which can then be converted to GiB slightly simpler.
  • Add IPv6 support for network usage and Fail2Ban stats.
  • Reduce sudo calls in Print_Network_Usage: If namespaces are used, check via sudo -n -v once whether the current user can use sudo. If so, do the whole namespace processing loop in a single sudo -n dash -c 'declare -f func; func' 2>&1 call. Else, process the default namespace only.

Comment thread dietpi/func/dietpi-banner Outdated
Comment thread dietpi/func/dietpi-banner Outdated
@MichaIng

MichaIng commented Jul 11, 2026

Copy link
Copy Markdown
Owner

I went through the open points you mentioned at the top. Regarding clearing the terminal in VS Code: See G_TERM_CLEAR() in dietpi-globals: It uses ANSI escape sequences, \n and \e[H to move the content into the scrollback buffer (where available) and move the cursor back to the top, rather than clear. I found it preferrable to keep the possibility to scroll back, rather then erasing the content. But it performs worse on certain terminals, where the content is visibly moved line by line. Possible that this does not work well in some dev terminals.

@MichaIng MichaIng closed this Jul 11, 2026
@MichaIng MichaIng reopened this Jul 11, 2026
timjolson and others added 21 commits July 31, 2026 01:20
…ttern submenu. added migration of disk_rootfs and disk_userdata (removed them from the menu).
…hed aCUSTOM_COMMANDS to use associative indices to take advantage of Print_Item_State for display consistency; still TODO: update the submenu for associative indexing
…upgraded custom commands submenu to match the style of disk_usage patterns submenu; added custom command migration (needs testing)
…s handled in Print_Banner, and `dietpi-banner 0` should not care
* "systemd" is explicitly written with a lower-case "s". It would be "okay" to use an upper-case "s" at the beginning of a sentence, but we keep strict lower-case everywhere else in DietPi texts as well. To quote the makers: "The only situation where we find it OK to use an uppercase letter in the name (but don't like it either) is if you start a sentence with systemd."
* Use single-quotes for string, where no variable expension is intended, except in (the left-side of) bash conditionals "[[ ]]", where quotation has no effect.
* newline after loop condition before "do", same like after if condition before "then"
* Skip double-quotes when assigning a single variable or command substitution, as it is not needed in this case. Skip as well for "case" input pattern, where it is not needed either.
* Replace some on-line if-then(-else) with && (||)
* Skip "-n" and "-z" in bash conditionals, only use "!" to check for empty expressions. Also avoid redundant "${var:-}" to replace an empty variable with an empty string, redundant in modern shells.
* Avoid muting STDERR where it is not expected (findmnt call), especially for testing/beta phase
* Use "$" for variable calls in bash arithmetics as well. It is not needed, but makes it easier to distinguish between variable calls and assignments when reviewing a script, especially if editors do syntax highlighting, or when searching for those via grep.
* Use %s for printf placeholders instead of %b, if no ANSI code expansion or similar is expected.
* Use -v flag explicitly when "unset"ing variables. Very rare chance that the same name is used for a function, especially in a called (instead of sourced) script, but I started with this convention at some point.
* Always print closing CLI_LINE, as it was done before. The multi-line blocks with subheader print a leading CLI_LINE but no trailing one.
* Restore empty line before credits, update notifications, dietpi-* commands, but remove additional newline after banner (the migration messages will be removed, all done during dietpi-update). If a color reset is missing somewhere, we should fix it in the respective Print_* command, but so far I couldn't find any, especially after Print_Custom_Commands uses Print_Item_State as well.
…" is used

The dark gray really is dark. For info which was explicitly selected by users, use the default white/bright grey, like all of the upper entry values do. This is already different from the "highlight" and "alert" colors used for all other output states where "weak" was used, so this does not cause overlaps. Keep "weak" color for the credits only as before. If we want to use it more widely in the banner, IMO never for keys or values, only for separation/ordering symbols or such things.
The ASCII V and W contain literal upper-case V characters.
* IPv6 are not trivial to match selectively, due to the possible shortenings of 0000 hextets, even on both ends.
* For Fail2Ban stats, it makes sense to match those widely, to not miss if e.g. the localhost itself got banned. The output syntax is luckily specific enough for this to still reliably only match the banned IPs.
* "ip -br a" has simple output format as well, with the 1st IP being the 3rd argument. There is no need to filter this, it is either an IP or empty.
* For matching public IPs, the regex for IPv6 can be narrowed down much, since only the 2000::/3 block is globally routable.
* Merge Get_WAN_IP and printing the IP address line into Print_Data_Usage, to deduplicate the ns_cmd_prefix crafting. Sadly, the whole function cannot simply be called with the namespace prefix, since we'd need to add all used functions and variables into the subshell, too. It would require some reorder for this to be reasonable, e.g. to obtain only the raw values with a simple dash-compatible function, and craft the colored output lines afterwards in the parent function. But this can be done in a future PR.
* Make some variables local, and omit or rename some others
@MichaIng

MichaIng commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Ah dammit, I never think about that rebasing always causes a pain when aiming to sync it back to a(nother) local client 🙈. Sorry.

Comment thread CONTRIBUTING.md Outdated
MichaIng added 5 commits July 31, 2026 01:29
W was accidentally excluded
Make MENU_ITEMS array readonly, along with some other variables that are not intended to be change. Remove "unknown menu selection" error and "every other valid one" match instead. There is not really a way whiptail can return a value other than what MENU_ITEMS contains, and it makes maintainance/adding new items easier. If we'd really want to make a failsafe check for debugging purpose, we should instead check whether the returned value is in the MENU_ITEMS array.
It overrides "--real" and shows tmpfs and udev mountpoints that way, which are not commonly interesting for disk space info.
@MichaIng

Copy link
Copy Markdown
Owner

Okay, only left point from my end is to move the migration into dietpi-update patches. I'll do that tomorrow.

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.

DietPi-Banner | Add Custom Scripts

2 participants