Skip to content

Commit 9c07d63

Browse files
authored
Update scaffold templates, metadata, and staging scripts with naming and debug changes (#25)
1 parent 8ca12e7 commit 9c07d63

12 files changed

+428
-345
lines changed

src/initialize/debug.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,36 @@ debug() {
3535

3636

3737
_about_debug() {
38-
cat <<-EOF
38+
cat <<EOF
3939
4040
Usage: debug <option> || <"message string">
41-
Options:
42-
help Show this help message
43-
"message string" Show debug message (DEBUG non-zero)
44-
reset (Re)set starting point
45-
total Show total time and reset
41+
Options:
42+
help Show this help message
43+
"message string" Show debug message (DEBUG non-zero)
44+
reset (Re)set starting point
45+
total Show total time and reset
4646
4747
4848
When providing a "message string", elapsed time since last debug call is shown if DEBUG is set.
49-
EOF
49+
EOF
5050
}
51+
52+
53+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
54+
DEBUG=${DEBUG:-true}
55+
56+
debug "debug initialized"
57+
58+
# --- Capture and assert help output ---
59+
help_output="$(debug help)" # Capture
60+
echo "$help_output" | grep -q "Usage: debug" || { # Assert
61+
echo "Help output does not contain expected usage string"
62+
exit 1
63+
}
64+
# --- end assertion ---
65+
66+
debug "$help_output"
67+
debug "test complete"
68+
debug total
69+
70+
fi

tests/test_debug.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

tools/00_setup_module.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
_about_setup_module() {
5+
cat << EOF
6+
7+
usage: $0 <module_name>
8+
9+
Creates Armbian Config V3 module scaffolding in ./staging/
10+
11+
<module_name> Name of the new module (required).
12+
13+
Outputs:"
14+
- <module_name>.conf Module metadata template
15+
- <module_name>.sh Module Bash template
16+
- docs_<module_name>.md Documentation stub
17+
18+
Example:"
19+
$0 mymodule"
20+
EOF
21+
}
22+
23+
setup_module() {
24+
25+
STAGING_DIR="./staging"
26+
27+
28+
if [[ $# -lt 1 ]]; then
29+
echo "Usage: $0 <module_name>"
30+
exit 1
31+
fi
32+
33+
MODULE="$1"
34+
35+
# Ensure ./staging exists
36+
if [[ ! -d "$STAGING_DIR" ]]; then
37+
mkdir -p "$STAGING_DIR"
38+
fi
39+
40+
# Output .conf metadata template inside ./staging
41+
cat > "${STAGING_DIR}/${MODULE}.conf" <<EOF
42+
# ${MODULE} - Armbian Config V3 metadata
43+
44+
[${MODULE}]
45+
feature=${MODULE}
46+
description=
47+
extend_desc=false
48+
documents=false
49+
options=
50+
parent=
51+
group=
52+
contributor=\${contributor:-}
53+
maintainer=false
54+
arch=arm64 armhf x86-64
55+
require_os=Armbian Debian Ubuntu
56+
require_kernel=5.15+
57+
port=false
58+
helpers=${helpers:-}
59+
60+
EOF
61+
62+
# Output .sh module template inside ./staging
63+
cat > "${STAGING_DIR}/${MODULE}.sh" <<EOF
64+
#!/bin/bash
65+
set -euo pipefail
66+
67+
# ${MODULE} - Armbian Config V3 module
68+
69+
${MODULE}() {
70+
# TODO: implement module logic
71+
echo "${MODULE} - Armbian Config V3 test"
72+
echo "Scaffold test"
73+
}
74+
75+
_about_${MODULE}() {
76+
# TODO: implement standard help message
77+
echo "use: ${MODULE} - ..."
78+
echo "help - this message"
79+
}
80+
81+
# ${MODULE} - Armbian Config V3 Test
82+
83+
if [[ "\${BASH_SOURCE[0]}" == "\${0}" ]]; then
84+
echo "${MODULE} - Armbian Config V3 test"
85+
echo "# TODO: implement module logic"
86+
exit 1
87+
fi
88+
89+
EOF
90+
91+
# Output .sh module template inside ./staging
92+
cat > "${STAGING_DIR}/${MODULE}.md" <<EOF
93+
# ${MODULE} - Armbian Config V3 extra documents
94+
95+
## TODO: EXTRA Documents about the feature.
96+
97+
EOF
98+
99+
echo -e "Staging: Complete\nScaffold for ${MODULE} can be found at ${STAGING_DIR}/."
100+
}
101+
102+
103+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
104+
foo="${1:-help}"
105+
if [[ $foo = "help" ]]; then
106+
_about_setup_module && exit 1
107+
else
108+
setup_module "$foo"
109+
fi
110+
unset foo
111+
fi

tools/02_validate_module.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
_about_validate_module() {
5+
cat <<EOF
6+
7+
usage: $0 <modulename> or help
8+
9+
Check results:
10+
OK - File exists and passes checks
11+
MISSING - File is missing
12+
WARN - File exists but is incomplete
13+
14+
Checks performed:
15+
- docs_<modulename>.md (must have more than a top-level header)
16+
- <modulename>.sh (must contain Help info in _about_<modulename>() function)
17+
- <modulename>.conf (must have non-comment content)
18+
19+
EOF
20+
}
21+
22+
_check_md() {
23+
file="$1"
24+
if [ ! -f "$file" ]; then
25+
echo "MISSING: $file"
26+
return 1
27+
fi
28+
if ! grep -q "^# " "$file"; then
29+
echo "WARN: $file missing top-level header"
30+
return 1
31+
fi
32+
# Check for more content than the header (ignore lines with only # ...)
33+
if [ "$(grep -c "^# " "$file")" -eq "$(wc -l < "$file")" ]; then
34+
echo "WARN: $file has only a top-level header"
35+
return 1
36+
fi
37+
echo "OK: $file"
38+
}
39+
40+
_check_sh() {
41+
file="$1"
42+
modname="$(basename "$file" .sh)"
43+
if [ ! -f "$file" ]; then
44+
echo "MISSING: $file"
45+
return 1
46+
fi
47+
if ! grep -q "^_about_${modname}()" "$file"; then
48+
echo "WARN: $file missing _about_${modname}()"
49+
return 1
50+
fi
51+
echo "OK: $file"
52+
}
53+
54+
# At top of your script
55+
REQUIRED_CONF_FIELDS=(feature helpers description)
56+
57+
_check_conf() {
58+
file="$1"
59+
local missing=0
60+
if [ ! -f "$file" ]; then
61+
echo "MISSING: $file"
62+
return 1
63+
fi
64+
65+
for field in "${REQUIRED_CONF_FIELDS[@]}"; do
66+
if ! grep -qE "^$field=" "$file"; then
67+
echo "WARN: $file missing required field: $field"
68+
missing=1
69+
fi
70+
done
71+
72+
if [ "$missing" -eq 0 ]; then
73+
echo "OK: $file"
74+
return 0
75+
else
76+
return 1
77+
fi
78+
}
79+
80+
validate_module() {
81+
local cmd="${1:-help}"
82+
local status=0
83+
case "$cmd" in
84+
help|--help|-h)
85+
_about_validate_module
86+
exit 0
87+
;;
88+
*)
89+
_check_md "./staging/docs_$cmd.md" || status=1
90+
_check_sh "./staging/$cmd.sh" || status=1
91+
_check_conf "./staging/$cmd.conf" || status=1
92+
if [[ "$status" -ne 0 ]]; then
93+
echo "One or more validation checks failed for module: $cmd" >&2
94+
exit 1
95+
fi
96+
;;
97+
esac
98+
}
99+
100+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
101+
validate_module "$@"
102+
fi

tools/04_promote_module.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
5+
promote_module() {
6+
7+
DOC_ROOT="${DOC_ROOT:-./docs}"
8+
9+
declare -A array_entries
10+
declare -A group_counts # For unique id per group
11+
12+
# Move *.sh (not docs_*.sh) with a matching .conf file to src/$parent/
13+
for sh_file in ./staging/*.sh; do
14+
[ -f "$sh_file" ] || continue
15+
base_name=$(basename "$sh_file" .sh)
16+
conf_file="./staging/${base_name}.conf"
17+
if [ -f "$conf_file" ]; then
18+
parent=$(grep '^parent=' "$conf_file" | head -n1 | cut -d= -f2- | xargs)
19+
if [ -n "$parent" ]; then
20+
dest_dir="./src/$parent"
21+
mkdir -p "$dest_dir"
22+
echo "Moving $sh_file and $conf_file to $dest_dir/"
23+
mv "$sh_file" "$dest_dir/"
24+
mv "$conf_file" "$dest_dir/"
25+
else
26+
echo "No parent= in $conf_file, skipping $sh_file"
27+
fi
28+
fi
29+
done
30+
# Move *.md scripts from staging to docs/
31+
for docs_file in ./staging/*.md; do
32+
if [ -n "$parent" ]; then
33+
mkdir -p "$DOC_ROOT"
34+
[ -f "$docs_file" ] || continue
35+
echo "Moving $docs_file to $DOC_ROOT/"
36+
mv "$docs_file" "$DOC_ROOT/"
37+
fi
38+
done
39+
40+
}
41+
42+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
43+
promote_module
44+
fi

0 commit comments

Comments
 (0)