watch_up.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/sh
  2. DEBUG=false
  3. export WZMINI_CFG=/opt/wz_mini/wz_mini.conf
  4. [ -f $WZMINI_CFG ] && source $WZMINI_CFG
  5. if [ "$DEBUG" == "true" ]; then
  6. if [ -L /dev/fd ]; then
  7. echo fd exists
  8. else
  9. echo fd does not exist, link
  10. ln -s /proc/self/fd /dev/fd
  11. fi
  12. LOG_FILE=/opt/wz_mini/log/watch_up.log
  13. exec > >(busybox tee -a ${LOG_FILE}) 2>&1
  14. fi
  15. set -x
  16. event="$1"
  17. directory="$2"
  18. file="$3"
  19. case "$event" in
  20. n) date; if [[ "$file" == "img" ]]; then
  21. set -x
  22. if [[ "$DISABLE_FW_UPGRADE" == "true" ]]; then
  23. #Reboot as soon as we see "img", this means an update is incoiming
  24. reboot
  25. fi
  26. #hook the v2
  27. if cat /params/config/.product_config | grep WYZEC1-JZ; then
  28. while [ ! -f /tmp/Upgrade/upgraderun.sh ]
  29. do
  30. # sed -i '/pgrep/,+4d' /tmp/Upgrade/upgraderun.sh
  31. sleep 0.1
  32. done
  33. else
  34. #t31
  35. while [ ! -f /tmp/Upgrade/upgraderun.sh ]
  36. do
  37. pkill -f "sh /tmp/Upgrade/upgraderun.sh"
  38. mv /tmp/Upgrade/upgraderun.sh /tmp/Upgrade/upgraderun.old
  39. echo "squashed upgraderun.sh"
  40. sleep 0.1
  41. done
  42. echo "start countdown"
  43. secs=30
  44. endTime=$(( $(date +%s) + secs ))
  45. while [ $(date +%s) -lt $endTime ]; do
  46. if pgrep -f 'upgraderun.sh' > /dev/null ; then
  47. pkill -f "sh /tmp/Upgrade/upgraderun.sh"
  48. pkillexitstatus=$?
  49. if [ $pkillexitstatus -eq 0 ]; then
  50. echo "matched upgraderun.sh, killed."
  51. status=false
  52. break 1
  53. fi
  54. fi
  55. done
  56. fi
  57. if cat /params/config/.product_config | grep WYZEC1-JZ; then
  58. echo "v2 found"
  59. upgrade_path=$(find /tmp/Upgrade | grep upgradecp.sh)
  60. sed -i '/wc -c $KERNEL/,+14d' $upgrade_path
  61. #mv /tmp/Upgrade/upgraderun.sh /tmp/Upgrade/run_upg.sh
  62. #sh /tmp/Upgrade/run_upg.sh
  63. #/tmp/Upgrade/system_upgrade.sh
  64. else
  65. if [[ -e /tmp/Upgrade/app ]]; then
  66. echo "found app image, flashing"
  67. flashcp -v /tmp/Upgrade/app /dev/mtd3
  68. /opt/wz_mini/bin/busybox sync
  69. else
  70. echo "no kernel image present"
  71. fi
  72. if [[ -e /tmp/Upgrade/kernel ]]; then
  73. echo "found kernel image, flashing"
  74. flashcp -v /tmp/Upgrade/kernel /dev/mtd1
  75. /opt/wz_mini/bin/busybox sync
  76. else
  77. echo "no app image present"
  78. fi
  79. if [[ -e /tmp/Upgrade/rootfs ]]; then
  80. echo "found rootfs image, flashing"
  81. flashcp -v /tmp/Upgrade/rootfs /dev/mtd2
  82. /opt/wz_mini/bin/busybox sync
  83. else
  84. echo "no root image present"
  85. fi
  86. /opt/wz_mini/bin/busybox sync
  87. /opt/wz_mini/bin/busybox sync
  88. sleep 5
  89. echo reboot
  90. /opt/wz_mini/bin/busybox reboot
  91. fi
  92. fi;;
  93. *) echo "This script must be run from inotifyd";;
  94. esac