cd /var/www || exit 1

echo "cuenta,app,custom,php_loc"

# Recorre posibles cuentas (directorios nivel 1), excluyendo framework reservado
for c in */ ; do
  c=${c%/}

  # excluir framework reservado
  case "$c" in
    eodin|eodin*|site) continue ;;
  esac

  [ -d "$c" ] || continue

  # apps = directorios dentro de la cuenta excluyendo account
  for app in "$c"/* ; do
    [ -d "$app" ] || continue
    [ "$(basename "$app")" = "account" ] && continue

    # custom si hay al menos 1 subdirectorio inmediato
    if find "$app" -mindepth 1 -maxdepth 1 -type d | read; then
      custom="custom"
    else
      custom="no_custom"
    fi

    # líneas PHP: suma wc -l de *.php (recursivo)
    php_loc=$(
      find "$app" -type f -name "*.php" -print0 \
      | xargs -0 -r wc -l \
      | awk 'END{print ($1 ? $1 : 0)}'
    )

    echo "$c,$(basename "$app"),$custom,$php_loc"
  done
done

