Script for users to customize dietpi-banner formatting - #8230
Open
timjolson wants to merge 59 commits into
Open
Conversation
…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.
…lors inside custom commands
…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.
…being unfriendly.
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.
…t paths before patterns
…ng results. truncate disk display names
…d a safer delimiter
…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)
…the banner is displayed
…s handled in Print_Banner, and `dietpi-banner 0` should not care
Owner
|
This is based on top of #8172, right? I'm going to polish/finish the points I raised there today. |
Contributor
Author
|
Yes, this uses the associative indices, so needs #8172 merged in to work. |
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.
This script lets a user configure their
dietpi-bannercolor 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 theCPU tempdietpi-banner output, which has hardcoded colors and formats, but is insidedietpi-globalsso does not have user-customization.