2
0

check-controllers.sh 1.3 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. [ -d build ] || {
  3. echo "Execute as ./build/check-controllers.sh" >&2
  4. exit 1
  5. }
  6. find . -type f -name '*.lua' -path '*/controller/*' | while read controller; do
  7. controller="${controller#./}"
  8. base="${controller%%/controller/*}"
  9. sed -rne 's#^.*\b(cbi|form)\([[:space:]]*("([^"]*)"|\047([^\047]*)\047)[[:space:]]*[,)].*$#\1 \3\4#gp' "$controller" | while read type map; do
  10. model="$base/model/cbi/$map.lua"
  11. package="${controller##*/controller/}"; package="${package%.lua}"; package="luci.controller.${package//\//.}"
  12. if ! grep -sqE '\bmodule[[:space:]]*\(?[[:space:]]*("|\047|\[=*\[)'"$package" "$controller"; then
  13. echo "'$controller' does not contain the expected\n\t'module(\"$package\", ...)' line.\n"
  14. fi
  15. grep -sqE '\b(Form|SimpleForm)[[:space:]]*\(' "$model" && ! grep -sqE '\bMap[[:space:]]*\(' "$model" && is_form=1 || is_form=0
  16. if [ ! -f "$model" ]; then
  17. echo -e "'$controller' references $type('$map')\n\tbut expected file '$model' does not exist.\n"
  18. elif [ $type = "cbi" -a $is_form = 1 ]; then
  19. echo -e "'$controller' references $type('$map')\n\tbut '$model' looks like a Form or SimpleForm.\n"
  20. elif [ $type = "form" -a $is_form = 0 ]; then
  21. echo -e "'$controller' references $type('$map')\n\tbut '$model' does not look like a Form or SimpleForm.\n"
  22. fi
  23. done
  24. done