watch_up.sh 2.0 KB

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