Skip to content

Script for users to customize dietpi-banner formatting - #8230

Open
timjolson wants to merge 59 commits into
MichaIng:devfrom
timjolson:dietpi-cli
Open

Script for users to customize dietpi-banner formatting#8230
timjolson wants to merge 59 commits into
MichaIng:devfrom
timjolson:dietpi-cli

Conversation

@timjolson

@timjolson timjolson commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This script lets a user configure their dietpi-banner color codes interactively (displaying samples of different formats).

Future development could include word-wrap and related configurations in one place, offsetting CLI options so they can be sourced and used across other scripts. Something to look at is the CPU temp dietpi-banner output, which has hardcoded colors and formats, but is inside dietpi-globals so does not have user-customization.

timjolson and others added 30 commits July 7, 2026 14:21
…y to accept multiple commands. Added systemd and fail2ban status. Added network usage by namespace. Added disk usage by pattern matching. Added G_TRUNCATE_MID.
…UR saves just the relevant indexes. added some shellcheck bypasses and documentation.
…ead tests from network data usage. Get_Fail2Ban_Status is cleaner without the complicated sudo handling.
* align indentation
* use "declare" only where needed (for assiciative arrays)
* use "declare -g" only where needed: when defining global variables inside a function
* use quotation in bash conditionals and variable assignment only where needed
* use single-quotes consistently if no variable expansion or literal `'` is needed
* prefer $EUID over external `id -u` call
* prefer mawk over awk (which can be the slower gawk if installed)
* prefer bash arithmetic context over `-ge` and alike operators
* skip `|| true` as no `set -e` is used
* merge bash conditionals where possible
* simplify numeric => assiciative config array conversion: alter the new arrays in place instead of using a temporary conversion array: Both arrays are declared as assiciative arrays already before the config is sourced. Hence they remain assiciative arrays, just with the numberic indices added. If any index matches an existing old numeric key, it can be applied as its new assiciative key directly, and the numeric value unset. The mapping arrays were inlined, so ultimately this code can go into dietpi-update patches instead.
* some reordering to reduce the diff
* use lower-case colour array keys
* merge the two unnecessarily split array migration flags
* some more cleanup
dietpi-globals: revert changes to G_GET_WAN_IP until we found a sane solution for namespaces with sudo, and since the banner does not currently use it. Align coding in G_TRUNCATE_MID
* restore dash-compatibility of Get_Cert_Status_Raw
* cleanup Get_Cert_Status: `sudo -n` returns the exit code "1" if sudo permissions are missing, the "no cert found" error code would hence need to swap. However, there is already the exit code 0 handling based on the "No certificate found" output, so make us of that instead. If Get_Cert_Status_Raw runs at all, exit code  0 is now always returned, hence forge banner line based on its output. In case of another exit code, it must have come from a sudo failure, hence print the error about NOPASSWD sudo.
* Move `Print_*` functions below `Get_*` functions, and rename `Get_*` functions which are supposed to print the formatted output to console directly to `Print_*`
* Remove trailing COLOUR_RESET where not required
* Simplify Get_Fail2Ban_Status: process `fail2ban-client` output with a single awk to avoid the large amount of external command calls, and print it directly.
* create variables as local ones where appropriate
* Simplify Print_Network_Usage: The `/sys/class/net/*/statistics` is always world-readable (unless the kernel is manipulated). Skip related checks, and always read it directly if no namespace is used, using the cheaper builtin `read` instead of external `cat` call. Tailore Get_WAN_IP. Parse simpler `ip -br` output instead of `ip -o`. Print curl errors as is. They should be short with `-sSf`, and leaving them untouched helps with debugging.
MichaIng and others added 25 commits July 10, 2026 13:00
I changed it to `echo -e` since the used `%s` format codes printed color codes literally. However, this can be solved with `%b` as well, keeping the min-length format codes of `printf`. Raised the "IP (iface)" min length to 23 characters, matchig complete IPv4 address + classic WiFi interface name.
…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
@MichaIng

Copy link
Copy Markdown
Owner

This is based on top of #8172, right? I'm going to polish/finish the points I raised there today.

@MichaIng MichaIng added Visual 🌹 Issues affecting only the beauty of menus and output, but not the functionality dietpi-banner labels Jul 30, 2026
@timjolson

Copy link
Copy Markdown
Contributor Author

Yes, this uses the associative indices, so needs #8172 merged in to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dietpi-banner Visual 🌹 Issues affecting only the beauty of menus and output, but not the functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants