watch_up.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. exec 1>> /opt/wz_mini/log/watch_up.log 2>&1
  3. set -x
  4. event="$1"
  5. directory="$2"
  6. file="$3"
  7. case "$event" in
  8. n) date; if [[ "$file" == "img" ]]; then
  9. set -x
  10. #hook the v2
  11. if cat /params/config/.product_config | grep WYZEC1-JZ; then
  12. while [ ! -f /tmp/Upgrade/upgraderun.sh ]
  13. do
  14. # sed -i '/pgrep/,+4d' /tmp/Upgrade/upgraderun.sh
  15. sleep 0.1
  16. done
  17. else
  18. #t31
  19. while [ ! -f /tmp/Upgrade/upgraderun.sh ]
  20. do
  21. pkill -f "sh /tmp/Upgrade/upgraderun.sh"
  22. mv /tmp/Upgrade/upgraderun.sh /tmp/Upgrade/upgraderun.old
  23. echo "squashed upgraderun.sh"
  24. sleep 0.1
  25. done
  26. echo "start countdown"
  27. secs=30
  28. endTime=$(( $(date +%s) + secs ))
  29. while [ $(date +%s) -lt $endTime ]; do
  30. if pgrep -f 'upgraderun.sh' > /dev/null ; then
  31. pkill -f "sh /tmp/Upgrade/upgraderun.sh"
  32. pkillexitstatus=$?
  33. if [ $pkillexitstatus -eq 0 ]; then
  34. echo "matched upgraderun.sh, killed."
  35. status=false
  36. break 1
  37. fi
  38. fi
  39. done
  40. fi
  41. if cat /params/config/.product_config | grep WYZEC1-JZ; then
  42. echo "v2 found"
  43. upgrade_path=$(find /tmp/Upgrade | grep upgradecp.sh)
  44. sed -i '/wc -c $KERNEL/,+14d' $upgrade_path
  45. #mv /tmp/Upgrade/upgraderun.sh /tmp/Upgrade/run_upg.sh
  46. #sh /tmp/Upgrade/run_upg.sh
  47. #/tmp/Upgrade/system_upgrade.sh
  48. else
  49. if [[ -e /tmp/Upgrade/app ]]; then
  50. echo "found app image, flashing"
  51. flashcp -v /tmp/Upgrade/app /dev/mtd3
  52. /opt/wz_mini/bin/busybox sync
  53. else
  54. echo "no kernel image present"
  55. fi
  56. if [[ -e /tmp/Upgrade/kernel ]]; then
  57. echo "found kernel image, flashing"
  58. flashcp -v /tmp/Upgrade/kernel /dev/mtd1
  59. /opt/wz_mini/bin/busybox sync
  60. else
  61. echo "no app image present"
  62. fi
  63. if [[ -e /tmp/Upgrade/rootfs ]]; then
  64. echo "found rootfs image, flashing"
  65. flashcp -v /tmp/Upgrade/rootfs /dev/mtd2
  66. /opt/wz_mini/bin/busybox sync
  67. else
  68. echo "no root image present"
  69. fi
  70. /opt/wz_mini/bin/busybox sync
  71. /opt/wz_mini/bin/busybox sync
  72. sleep 5
  73. echo reboot
  74. /opt/wz_mini/bin/busybox reboot
  75. fi
  76. fi;;
  77. *) echo "This script must be run from inotifyd";;
  78. esac