Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
da9f1fb
Standardized printing. Organized color resources. Changed custom entr…
timjolson Jun 8, 2026
6710a86
removed extra `declare`s and -g `global`
timjolson Jun 28, 2026
ae0add1
adjusted example command for formatting and it serves as a test of co…
timjolson Jun 28, 2026
68b18dd
custom command failures provide the exit code
timjolson Jun 28, 2026
e59f0ae
Re-labeled colors for semantic indexing. removed extra formats. aCOLO…
timjolson Jun 28, 2026
2a4b17d
added colors reference
timjolson Jun 28, 2026
be989f9
combined sudo and ns command prefixes since they were only ever used …
timjolson Jun 28, 2026
9796927
fixed syntax for shellcheck warning
timjolson Jun 28, 2026
cd7654a
fixed indents
timjolson Jun 28, 2026
22d48d4
added BANNER_GET_WAN_IP so dietpi-banner can have it's own behavior
timjolson Jun 28, 2026
cce4c40
fail2ban status now uses 'fail2ban-client banned'. removed unneeded r…
timjolson Jun 29, 2026
2de0933
on network usage, only do sudo if netns is requested
timjolson Jun 29, 2026
246cfad
Add example G_TRUNCATE_MID
timjolson Jun 29, 2026
0eacc21
improved disk space handling with fallbacks for missing data
timjolson Jun 29, 2026
0a5d05b
fix indents
timjolson Jun 29, 2026
510858d
refactored for associative indexing. includes a migration feature
timjolson Jun 29, 2026
ad499c2
fixed shellchecks
timjolson Jun 29, 2026
905cb3f
to accomodate associative indexing, added enumeration option to G_WHI…
timjolson Jun 29, 2026
29418e5
keys were set in 3 places, so made the defaults more automated/dynami…
timjolson Jun 29, 2026
9a96bf8
removed duplicate entry
timjolson Jun 30, 2026
9325cc8
cleaned up shellcheck failures
timjolson Jun 30, 2026
b9d6506
added migration for legacy aCOLOUR preferences
timjolson Jul 1, 2026
851a63b
added error handling for No IPs blocked (or Fail2ban not running)
timjolson Jul 4, 2026
3ed1dc3
dietpi-banner: code alignments and simplification
MichaIng Jul 7, 2026
5d3ccc2
dietpi-banner: some restructure
MichaIng Jul 7, 2026
c3e0863
dietpi-banner: some more alignment
MichaIng Jul 7, 2026
02f00cc
dietpi-globals: simplify G_WHIP_CHECKLIST_ENUM handling
MichaIng Jul 7, 2026
da43989
fixed truncate length comparison and improved the output for shorter …
timjolson Jul 8, 2026
03ef77d
cleaned up netns data and reduced sudo usage
timjolson Jul 8, 2026
faf7c97
dietpi-banner: some fixes and changes
MichaIng Jul 9, 2026
eb98749
dietpi-banner: shorten some option keys
MichaIng Jul 9, 2026
ce76422
dietpi-banner: fix disk usage
MichaIng Jul 9, 2026
7d7ce5a
dietpi-banner: little cleanup
MichaIng Jul 9, 2026
6ea2a13
dietpi-banner: revert extra empty line
MichaIng Jul 9, 2026
44a69d7
dietpi-banner: align comment with what the line looks like
MichaIng Jul 10, 2026
6cc71f6
Made IP4_re mawk friendly. Fixed netns IPs not being detected due to …
timjolson Jul 9, 2026
6bdd62c
removed unused 'width' parameter
timjolson Jul 9, 2026
ea320cf
Updated truncat doc
timjolson Jul 10, 2026
7cf10a1
dietpi-banner: re-apply fixed alignment for network stats
MichaIng Jul 10, 2026
bae63d5
Print_Disk_Usage now uses a single findmnt call and processes explici…
timjolson Jul 19, 2026
f40f0ee
fixed display typos
timjolson Jul 20, 2026
0a7761f
split explicit disk mounts from patterns. de-duplicate exactly matchi…
timjolson Jul 20, 2026
914ce86
added configured but not matched mounts to the disk usage output. use…
timjolson Jul 20, 2026
78a8045
re-used Bytes_To_GiB
timjolson Jul 20, 2026
77bc1e3
re-used Bytes_To_GiB
timjolson Jul 20, 2026
75343bd
upgraded disk usage menu to list available mounts. simplified disk pa…
timjolson Jul 21, 2026
42b2ce8
added transient migration (every run) of .dietpi-banner_custom; switc…
timjolson Jul 21, 2026
e969102
upgraded custom commands for associative array and Print_Item_State; …
timjolson Jul 22, 2026
5bd6cb3
added custom command migration warning
timjolson Jul 22, 2026
5593399
Fixed migrated command not running after going through the menu.
timjolson Jul 22, 2026
2df5573
quote custom command outputs for safety
timjolson Jul 22, 2026
16fa623
keep migration warnings when user has gone through the menu and then …
timjolson Jul 22, 2026
ed26433
cleaning up separator lines
timjolson Jul 23, 2026
fd9bbba
LAN ip was not being printed with `dietpi-banner 0`. aENABLED check i…
timjolson Jul 25, 2026
1d2961f
reset text color after the banner
timjolson Jul 25, 2026
29de14f
organized and updated CONTRIBUTING.md
timjolson Jul 25, 2026
06a431c
fixed Disk Usage not working with word-wrap due to format codes being…
timjolson Jul 29, 2026
10fd9f6
dietpi-banner: code alignments
MichaIng Jul 30, 2026
ac02106
dietpi-banner: another code and output alignment
MichaIng Jul 30, 2026
7722cb6
dietpi-banner: use default color for some infos where currently "weak…
MichaIng Jul 30, 2026
7b71c6b
dietpi-banner: fix ASCII letter detection
MichaIng Jul 30, 2026
6a9cfa0
dietpi-banner: add IPv6 support and simplify network usage function
MichaIng Jul 30, 2026
d041c3d
dietpi-banner: fix variable names
MichaIng Jul 30, 2026
cac2d7e
dietpi-banner: little ASCII pattern fix
MichaIng Jul 30, 2026
644bb17
dietpi-banner: typo
MichaIng Jul 30, 2026
caf97a4
dietpi-banner: little simplification
MichaIng Jul 30, 2026
7a1fbb6
dietpi-banner: remove -D flag from findmnt
MichaIng Jul 30, 2026
e738639
Update CONTRIBUTING.md
MichaIng Jul 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 61 additions & 62 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ Guidance:
### Core concepts

- Globals: scripts source `dietpi/func/dietpi-globals` for shared helpers and
environment setup (`G_INIT`, `G_EXIT`, color vars, etc.). Read this file
environment setup (`G_INIT()`, `G_EXIT()`, color vars, etc.). Read this file
first to understand helper semantics and cancel/error behavior.
- UI: prefer `G_WHIP_*` dialog helpers for menus, input and confirmations to
maintain a consistent user experience across scripts.
- Error-handling: use `G_EXEC` to wrap any command call, so DietPi's error
- Error-handling: use `G_EXEC()` to wrap any command call, so DietPi's error
handler and consistent console output apply. Validate root permissions and
write access using `G_CHECK_ROOT_USER` / `G_CHECK_ROOTFS_RW` where required.
write access using `G_CHECK_ROOT_USER()` / `G_CHECK_ROOTFS_RW()` where required.
- Persistence: Write arrays or variables into a preference file `/boot/dietpi/.<prog_settings>`.
Persist arrays as indexed assignments (e.g. `aARRAY[index]=1`). Convert ESC bytes to `\e`
when saving text if needed. Load the preferences with `. "/boot/dietpi/.<prog_settings>"`
Expand All @@ -76,65 +76,49 @@ DietPi provides many `G_` prefixed helpers in `dietpi/func/dietpi-globals`. Usag
consistent and reduce reviewer friction.

Below are the most useful ones for contributors and how to use them safely.
- `G_INIT` — initialize script runtime, sets up the working directory, exit
- `G_INIT()` — initialize script runtime, sets up the working directory, exit
traps, consistent locale for parsing external command outputs, and handles
concurrent execution checks. Call early after sourcing `dietpi-globals`.

- `G_EXEC` — robust command executor with built-in retries and an interactive
- `G_EXEC()` — robust command executor with built-in retries and an interactive
error handler. Use instead of direct `rm`/`systemctl` in scripts so
failures are presented to the user and logged consistently. Optional
env vars: `$G_EXEC_DESC`, `$G_EXEC_RETRIES`, `$G_EXEC_OUTPUT`.

- `G_CONFIG_INJECT` — targeted config-file editing helper. Use to atomically
replace, uncomment, or add config lines using predictable patterns rather
than ad-hoc `sed` calls.

- `G_WHIP_*` family — dialog and UI helpers: (`G_WHIP_MSG`, `G_WHIP_YESNO`,
`G_WHIP_MENU`, `G_WHIP_CHECKLIST`, `G_WHIP_INPUTBOX`, `G_WHIP_PASSWORD`,
`G_WHIP_VIEWFILE`).
Prefer these for user interaction to maintain consistent UX and behavior.

- `G_CHECK_ROOT_USER`, `G_CHECK_ROOTFS_RW` — validate that the script runs
- `G_CHECK_ROOT_USER()`, `G_CHECK_ROOTFS_RW()` — validate that the script runs
with necessary privileges and writable rootfs before performing writes.
Using `G_CHECK_ROOT_USER "$@"`, if the script does not have root permissions,
re-executes with `sudo`. "$@" passes all CLI arguments to the `sudo-ed` script.

- `G_GET_NET`, `G_GET_WAN_IP` — network helpers that return standardized
- `G_CONFIG_INJECT()` — targeted config-file editing helper. Use to atomically
replace, uncomment, or add config lines using predictable patterns rather
than ad-hoc `sed` calls.

- `G_GET_NET()`, `G_GET_WAN_IP()` — network helpers that return standardized
values; use `-q` to hide error messages.

- `G_DIETPI-NOTIFY` / `G_BUG_REPORT` — helpers to generate formatted bug
- `G_DIETPI-NOTIFY()` / `G_BUG_REPORT()` — helpers to generate formatted bug
reports and diagnostics. Use when capturing logs for PRs / issues.

#### G_WHIP specifics

These details are commonly needed when implementing menus and input boxes.

- `G_WHIP_INPUTBOX`:
- Use `$G_WHIP_INPUTBOX_REGEX` to provide an optional validation regex and
`$G_WHIP_INPUTBOX_REGEX_TEXT` to describe allowed input (human-friendly).
By default, any non-empty input is allowed.
- `$G_WHIP_DEFAULT_ITEM` pre-fills the input field. The helper loops until
input matches the regex or the user cancels (`|| return`).
- On success the entered value is returned in `$G_WHIP_RETURNED_VALUE`.

- `G_WHIP_YESNO`:
- Presents a Yes/No dialog. Exit status `0` indicates Yes/Ok; non-zero is
No/Cancel.
- Use for confirmations before destructive actions. Combine with
`G_EXEC` for safe command execution on confirmation.

- `$G_WHIP_DEFAULT_ITEM`:
- Controls the pre-selected menu item or prefilled input box value.
- When using `G_WHIP_MENU`, set it to a label matching one of the menu
entries to pre-select that entry (exact match is used).

- `$G_WHIP_SIZE_X_MAX`:
- Optional integer to limit dialog width (chars). Useful for dialogs with
very few content or checklists, where too wide dialog boxes may look weird.
By default, all `G_WHIP` dialogs are max 120 characters wide, capped by the
terminal width.
- Set it before calling a `G_WHIP_*` helper; the helper respects it when
calculating `$WHIP_SIZE_X`.
- `G_WHIP_*` family — dialog and UI helpers: (`G_WHIP_MSG()`, `G_WHIP_YESNO()`,
`G_WHIP_MENU()`, `G_WHIP_CHECKLIST()`, `G_WHIP_INPUTBOX()`, `G_WHIP_PASSWORD()`,
`G_WHIP_VIEWFILE()`). Prefer these for user interaction to maintain
consistent UX and behavior. Quick notes:

- **Return value**: `$G_WHIP_RETURNED_VALUE` holds the helper result — a
single value for inputbox and menus, or an array of enabled indices for checklists.
- **Default item**: `$G_WHIP_DEFAULT_ITEM` sets the pre-selected value. For
`G_WHIP_MENU()` it must exactly match a menu label.
- **Checklist structure**: `$G_WHIP_CHECKLIST_ARRAY` entries are triples:
`'tag' 'Description' 'on/off'`. Use safe tags (letters, digits, underscore)
to avoid parsing issues.
- **Enumerated checklists**: set `G_WHIP_CHECKLIST_ENUM=1` to display numeric
indices in the UI to avoid long, complex, or non-safe keys.
- **Input validation**: `G_WHIP_INPUTBOX()` supports `$G_WHIP_INPUTBOX_REGEX`
and `$G_WHIP_INPUTBOX_REGEX_TEXT` to validate and describe allowed input.
The helper loops until input matches the regex or the user cancels (`|| return`).
- **Dialog sizing**: use `$G_WHIP_SIZE_X_MAX` to limit dialog width; helpers
respect terminal width and default to a max of 120 chars.

### Menu extension pattern (safe, minimal)

Expand All @@ -159,7 +143,7 @@ Below are minimal, copy-paste-ready examples that follow DietPi conventions.
G_INIT
```

- `G_WHIP_MENU` (single choice):
- `G_WHIP_MENU()` a menu of items the user can scroll through (choose one):
```
G_WHIP_MENU_ARRAY=( 'Start' 'Start the service' 'Stop' 'Stop the service' )
G_WHIP_DEFAULT_ITEM='Start'
Expand All @@ -170,60 +154,75 @@ Below are minimal, copy-paste-ready examples that follow DietPi conventions.
esac
```

- `$G_WHIP_CHECKLIST_ARRAY` (multi-select):
- `G_WHIP_CHECKLIST()` a list of items the user can enabled/disabled (multi-select):
```
G_WHIP_CHECKLIST_ARRAY=()
G_WHIP_CHECKLIST_ARRAY+=( '5' 'Enable Foo' "${aENABLED[5]:=0}" )
G_WHIP_CHECKLIST_ARRAY+=( '6' 'Enable Bar' "${aENABLED[6]:=0}" )
# Set G_WHIP_CHECKLIST_ENUM=1 to display numeric indices in the UI
G_WHIP_CHECKLIST 'Choose features to enable:' || return
for i in $G_WHIP_RETURNED_VALUE; do aENABLED[$i]=1; done
Save > "$FP_SAVEFILE"
```

- `G_WHIP_INPUTBOX` (validated input):
- `G_WHIP_INPUTBOX()` a text entry box (validated input):
```
G_WHIP_INPUTBOX_REGEX='^[0-9]+$' G_WHIP_INPUTBOX_REGEX_TEXT='a number' G_WHIP_DEFAULT_ITEM=10
G_WHIP_INPUTBOX 'Set retry count:' || return
RETRIES=$G_WHIP_RETURNED_VALUE
```

- `G_WHIP_YESNO` (confirmation):
- `G_WHIP_YESNO()` Yes/No prompt (confirmation):
```
if G_WHIP_YESNO 'Delete backup?'; then
G_EXEC rm -rf "$TARGET"
fi
```

- `G_WHIP_VIEWFILE` (show a logfile):
- `G_WHIP_VIEWFILE()` displays a file that can be scrolled:
```
log=1 G_WHIP_VIEWFILE "$FP_LOG" || return
```

- `Save()` persistence pattern (follow dietpi-banner conventions):
- `G_TRUNCATE_MID()` shorten long strings by squishing the middle characters:
```
G_TRUNCATE_MID "Long text to be shortened by removing the middle" 26
# -> "Long text to... the middle"

# And `G_TRUNCATE_MID "alphabetical" N` returns the below, as N decreases
# alp...al
# al...al
# alphab
# alpha
# alph
# alp
```

- `Save()` example persistence pattern (beware of escape sequences):
```
Save(){
# `echo` text to be evaluated when re-loading
# Call with `Save > "preference/filepath"`
# `echo` text to be eval-ed when re-loading
# Call with `Save > "preference/file/path"`
echo "aDESCRIPTION[10]='${aDESCRIPTION[10]}'"
for i in "${!aENABLED[@]}"; do echo "aENABLED[$i]=${aENABLED[$i]}"; done
for i in {0..6}; do val="${aCOLOUR[$i]}"; esc=$(printf '%s' "$val" | sed $'s/\x1b/\\e/g'); esc=${esc//\'/\\\'}; echo "aCOLOUR[$i]='$esc'"; done
}
```

### Banner extension pattern (example)
### DietPi-Banner extension pattern

When adding banner items (e.g. `dietpi-banner`), follow this minimal pattern:
When adding banner items, follow this minimal pattern:

- Describe: add the label to `aDESCRIPTION[index]` and a default to
`aENABLED[index]` during initialization.
`aENABLED[index]` during initialization if relevant (the standard default is disabled=0).
If the item needs to show in the main menu checklist, add `index` to MENU_ITEMS.

- Output: implement `Print_<ShortName>()` or add a guarded line in `Print_Banner_raw()`:
- Output: implement `Get_<Shortname>()` and add a guarded line in `Print_Banner_raw()`:
```
(( ${aENABLED[index]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[index]} $GREEN_SEPARATOR $(Print_<ShortName>)"
(( ${aENABLED[index]} )) && Print_Item_State "${aDESCRIPTION[index]}" "$(Get_Shortname 2>&1)"
```

- Persist: ensure `Save()` writes `aENABLED[index]=...` and any custom
`aDESCRIPTION[...]` lines so the state survives restarts.
- Persist: ensure `Save()` writes `aENABLED[index]=...` so the state survives restarts.

### Nested / multi-page menu pattern

Expand Down
Loading