watch_up.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. event="$1"
  3. directory="$2"
  4. file="$3"
  5. case "$event" in
  6. n) if [[ "$file" == "upgraderun.sh" ]]; then
  7. pkill -f "sh /tmp/Upgrade/upgraderun.sh"
  8. mv /tmp/Upgrade/upgraderun.sh /tmp/Upgrade/upgraderun.old
  9. echo "squashed upgraderun.sh"
  10. echo "start countdown"
  11. secs=30
  12. endTime=$(( $(date +%s) + secs ))
  13. while [ $(date +%s) -lt $endTime ]; do
  14. if pgrep -f 'upgraderun.sh' > /dev/null ; then
  15. pkill -f "sh /tmp/Upgrade/upgraderun.sh"
  16. pkillexitstatus=$?
  17. if [ $pkillexitstatus -eq 0 ]; then
  18. echo "matched upgraderun.sh, killed."
  19. status=false
  20. break 1
  21. fi
  22. fi
  23. done
  24. if [[ -e /tmp/Upgrade/app ]]; then
  25. echo "found app image, flashing"
  26. flashcp -v /tmp/Upgrade/app /dev/mtd3
  27. /opt/wz_mini/bin/busybox sync
  28. else
  29. echo "no kernel image present"
  30. fi
  31. if [[ -e /tmp/Upgrade/kernel ]]; then
  32. echo "found kernel image, flashing"
  33. flashcp -v /tmp/Upgrade/kernel /dev/mtd1
  34. /opt/wz_mini/bin/busybox sync
  35. else
  36. echo "no app image present"
  37. fi
  38. if [[ -e /tmp/Upgrade/rootfs ]]; then
  39. echo "found rootfs image, flashing"
  40. flashcp -v /tmp/Upgrade/rootfs /dev/mtd2
  41. /opt/wz_mini/bin/busybox sync
  42. else
  43. echo "no root image present"
  44. fi
  45. /opt/wz_mini/bin/busybox sync
  46. /opt/wz_mini/bin/busybox sync
  47. sleep 5
  48. /opt/wz_mini/bin/busybox reboot
  49. fi;;
  50. *) echo "This script must be run from inotifyd";;
  51. esac