Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
34 changes: 27 additions & 7 deletions src/initialize/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,36 @@ debug() {


_about_debug() {
cat <<-EOF
cat <<EOF

Usage: debug <option> || <"message string">
Options:
help Show this help message
"message string" Show debug message (DEBUG non-zero)
reset (Re)set starting point
total Show total time and reset
Options:
help Show this help message
"message string" Show debug message (DEBUG non-zero)
reset (Re)set starting point
total Show total time and reset


When providing a "message string", elapsed time since last debug call is shown if DEBUG is set.
EOF
EOF
}


if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
DEBUG=${DEBUG:-true}

debug "debug initialized"

# --- Capture and assert help output ---
help_output="$(debug help)" # Capture
echo "$help_output" | grep -q "Usage: debug" || { # Assert
echo "Help output does not contain expected usage string"
exit 1
}
# --- end assertion ---

debug "$help_output"
debug "test complete"
debug total

fi
38 changes: 0 additions & 38 deletions tests/test_debug.sh

This file was deleted.

107 changes: 107 additions & 0 deletions tools/00_setup_module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash
set -euo pipefail

_about_setup_module() {
cat << EOF

usage: $0 <module_name>"

Creates Armbian Config V3 module scaffolding in ./staging/"

<module_name> Name of the new module (required)."

Outputs:"
- <module_name>.conf Module metadata template"
- <module_name>.sh Module Bash template"
- docs_<module_name>.md Documentation stub"

Example:"
$0 mymodule"
EOF
}

setup_module() {

STAGING_DIR="./staging"


if [[ $# -lt 1 ]]; then
echo "Usage: $0 <module_name>"
exit 1
fi

MODULE="$1"

# Ensure ./staging exists
if [[ ! -d "$STAGING_DIR" ]]; then
mkdir -p "$STAGING_DIR"
fi

# Output .conf metadata template inside ./staging
cat > "${STAGING_DIR}/${MODULE}.conf" <<EOF
# ${MODULE} - Armbian Config V3 metadata

[${MODULE}]
feature=${MODULE}
description=\${description:-}
extend_desc=\${extend_desc:-false}
documents=\${documents:-false}
options=\${options:-}
parent=\${parent:-system}
group=\${group:-managers}
contributor=\${contributor:-}
maintainer=\${maintainer:-false}
arch=\${arch:-"arm64 armhf x86-64"}
require_os=\${require_os:-"Armbian Debian Ubuntu"}
require_kernel=\${require_kernel:-5.15+}
port=\${port:-false}
helpers=_about_${MODULE}

EOF

# Output .sh module template inside ./staging
cat > "${STAGING_DIR}/${MODULE}.sh" <<EOF
#!/bin/bash
set -euo pipefail

# ${MODULE} - Armbian Config V3 module

${MODULE}() {
# TODO: implement module logic
echo "${MODULE} - Armbian Config V3 test"
echo "Scaffold test"
}

_about_${MODULE}() {
# TODO: implement standard help message
echo "use: ${MODULE} - ..."
echo "help - this message"
}

# ${MODULE} - Armbian Config V3 Test

if [[ "\${BASH_SOURCE[0]}" == "\${0}" ]]; then
echo "${MODULE} - Armbian Config V3 test"
echo "# TODO: implement module logic"
exit 1
fi

EOF

# Output .sh module template inside ./staging
cat > "${STAGING_DIR}/docs_${MODULE}.md" <<EOF
# ${MODULE} - Armbian Config V3 extra documents

## TODO: EXTRA Documents about the feature.

EOF

echo -e "Staging: Complete\nScaffold for ${MODULE} can be found at ${STAGING_DIR}/."
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
foo="${1:-help}"
[[ $foo = "help" ]] && _about_setup_module && exit 1
setup_module "$foo"
unset foo
fi
96 changes: 96 additions & 0 deletions tools/01_validate_module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash
set -euo pipefail

_about_validate_module() {
cat <<EOF

usage: $0 <modulename> or help

Check results:
OK - File exists and passes checks
MISSING - File is missing
WARN - File exists but is incomplete

Checks performed:
- docs_<modulename>.md (must have more than a top-level header)
- <modulename>.sh (must contain Help info in _about_<modulename>() function)
- <modulename>.conf (must have non-comment content)

EOF
}

_check_md() {
file="$1"
if [ ! -f "$file" ]; then
echo "MISSING: $file"
return 1
fi
if ! grep -q "^# " "$file"; then
echo "WARN: $file missing top-level header"
return 1
fi
# Check for more content than the header (ignore lines with only # ...)
if [ "$(grep -c "^# " "$file")" -eq "$(wc -l < "$file")" ]; then
echo "WARN: $file has only a top-level header"
return 1
fi
echo "OK: $file"
}

_check_sh() {
file="$1"
modname="$(basename "$file" .sh)"
if [ ! -f "$file" ]; then
echo "MISSING: $file"
return 1
fi
if ! grep -q "^_about_${modname}()" "$file"; then
echo "WARN: $file missing _about_${modname}()"
return 1
fi
echo "OK: $file"
}

# At top of your script
REQUIRED_CONF_FIELDS=(feature helpers description)

_check_conf() {
file="$1"
local missing=0
if [ ! -f "$file" ]; then
echo "MISSING: $file"
return 1
fi

for field in "${REQUIRED_CONF_FIELDS[@]}"; do
if ! grep -qE "^$field=" "$file"; then
echo "WARN: $file missing required field: $field"
missing=1
fi
done

if [ "$missing" -eq 0 ]; then
echo "OK: $file"
return 0
else
return 1
fi
}

validate_module() {
local cmd="${1:-help}"
case "$cmd" in
help|--help|-h)
_about_validate_module
;;
*)
_check_md "./staging/docs_$cmd.md"
_check_sh "./staging/$cmd.sh"
_check_conf "./staging/$cmd.conf"
;;
esac
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
validate_module "$@"
fi
45 changes: 45 additions & 0 deletions tools/03_promote_module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -euo pipefail


promote_module() {

DOC_ROOT="${DOC_ROOT:-./docs}"

mkdir -p "$DOC_ROOT"
declare -A array_entries
declare -A group_counts # For unique id per group


# Move docs_*.sh scripts from staging to docs/
for docs_file in ./staging/docs_*.md; do
[ -f "$docs_file" ] || continue
echo "Moving $docs_file to ./docs/"
mv "$docs_file" ./docs/
done

# Move *.sh (not docs_*.sh) with a matching .conf file to src/$parent/
for sh_file in ./staging/*.sh; do
[[ "$sh_file" == *docs_*.sh ]] && continue
[ -f "$sh_file" ] || continue
base_name=$(basename "$sh_file" .sh)
conf_file="./staging/${base_name}.conf"
if [ -f "$conf_file" ]; then
parent=$(awk -F= '/^parent=/{print $2}' "$conf_file" | head -n1)
if [ -n "$parent" ]; then
dest_dir="./src/$parent"
mkdir -p "$dest_dir"
echo "Moving $sh_file and $conf_file to $dest_dir/"
mv "$sh_file" "$dest_dir/"
mv "$conf_file" "$dest_dir/"
else
echo "No parent= in $conf_file, skipping $sh_file"
fi
fi
done

}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
promote_module
fi
Loading
Loading