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