pup_event_backend_modprobe_protect 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/ash
  2. #101121 --modcheck=<module> call is in rerwin's firmware scripts.
  3. #121003 rerwin: rewritten to wait for loading delays & accept --modcheck wildcard (e.g., hsf*).
  4. PARAM1="$1"
  5. write_delay_log() {
  6. echo "$(date +%H:%M:%S.%N | cut -c 1-12) ${$} $MODULE - $1" >> /tmp/pup_event_backend/delay.log
  7. }
  8. case $PARAM1 in
  9. --modcheck*)
  10. MODULE="$(echo "$PARAM1" | cut -f 2 -d '=')"
  11. if [ "$(echo $MODULE | grep '\*')" ];then
  12. MODBASE="$(echo $MODULE | grep -o '^[^\*]*')"
  13. MODULE="$(cat /tmp/pup_event_backend/protect1-* | grep -w -o -s "${MODBASE}[^ ]*" | tail -n 1)"
  14. [ "${MODULE}" ] || exit 1
  15. fi
  16. lsmod | grep -q -s "^${MODULE} " && exit 0
  17. [ "$(grep -s " ${MODULE} " /tmp/pup_event_backend/protect1-*)" = "" ] \
  18. && [ "$(grep '^ADDLIST=' /etc/rc.d/MODULESCONFIG | grep " ${MODULE} ")" = "" ] \
  19. && exit 1
  20. write_delay_log "Began wait for loading"
  21. FIRMWARE="$(grep -w "${MODULE}.ko" /etc/modules/firmware.dep.$(uname -r)| grep '^[^:]*')"
  22. BRKCNT=0; STATUS=1; MODPATH=""
  23. while [ $BRKCNT -lt 10 ];do
  24. if [ "$FIRMWARE" ] && [ -f /pinstall.${FIRMWARE}.sh ];then
  25. sleep 1
  26. else #any pinstall completed
  27. if [ "$MODPATH" = "" ];then
  28. MODPATH="$(find /lib/modules/$(uname -r)/ -maxdepth 6 -type f -name ${MODULE}.ko)"
  29. if [ "$MODPATH" = "" ];then
  30. write_delay_log "Not installed"
  31. STATUS=2; break
  32. fi
  33. else #module installed
  34. sleep 1
  35. if lsmod | grep -q -s "^${MODULE} ";then
  36. write_delay_log "Ended wait for loading"
  37. STATUS=0; break
  38. fi
  39. fi
  40. fi
  41. BRKCNT=$(($BRKCNT + 1))
  42. done
  43. [ $STATUS -eq 1 ] && write_delay_log "Wait for loading exceeded timeout limit"
  44. exit $STATUS
  45. ;;
  46. esac
  47. exit 0
  48. ###END###