_chk_dependency.sh 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Kselftest framework requirement - SKIP code is 4.
  4. ksft_skip=4
  5. DBGFS=$(grep debugfs /proc/mounts --max-count 1 | awk '{print $2}')
  6. if [ "$DBGFS" = "" ]
  7. then
  8. echo "debugfs not mounted"
  9. exit $ksft_skip
  10. fi
  11. DBGFS+="/damon"
  12. if [ $EUID -ne 0 ];
  13. then
  14. echo "Run as root"
  15. exit $ksft_skip
  16. fi
  17. if [ ! -d "$DBGFS" ]
  18. then
  19. echo "$DBGFS not found"
  20. exit $ksft_skip
  21. fi
  22. if [ -f "$DBGFS/monitor_on_DEPRECATED" ]
  23. then
  24. monitor_on_file="monitor_on_DEPRECATED"
  25. else
  26. monitor_on_file="monitor_on"
  27. fi
  28. for f in attrs target_ids "$monitor_on_file"
  29. do
  30. if [ ! -f "$DBGFS/$f" ]
  31. then
  32. echo "$f not found"
  33. exit 1
  34. fi
  35. done
  36. permission_error="Operation not permitted"
  37. for f in attrs target_ids "$monitor_on_file"
  38. do
  39. status=$( cat "$DBGFS/$f" 2>&1 )
  40. if [ "${status#*$permission_error}" != "$status" ]; then
  41. echo "Permission for reading $DBGFS/$f denied; maybe secureboot enabled?"
  42. exit $ksft_skip
  43. fi
  44. done