wz_init.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/bin/sh
  2. ###
  3. ###DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING
  4. ###
  5. ###This file is run by switch_root, from the initramfs in the kernel.
  6. LOG_NAME=/opt/wz_mini/log/wz_init
  7. if [[ -e $LOG_NAME.log || -L $LOG_NAME.log ]] ; then
  8. i=0
  9. while [[ -e $LOG_NAME.log.$i || -L $LOG_NAME.log.$i ]] ; do
  10. let i++
  11. done
  12. mv $LOG_NAME.log $LOG_NAME.log.$i
  13. LOG_NAME=$LOG_NAME
  14. fi
  15. touch -- "$LOG_NAME".log
  16. exec 1> $LOG_NAME.log 2>&1
  17. export WZMINI_CFG=/opt/wz_mini/wz_mini.conf
  18. [ -f $WZMINI_CFG ] && source $WZMINI_CFG
  19. echo "welcome to wz_init.sh"
  20. echo "PID $$"
  21. echo '
  22. __ ________ __ __ _____ _ _ _____
  23. \ \ / |___ / | \/ |_ _| \ | |_ _|
  24. \ \ /\ / / / / | \ / | | | | \| | | |
  25. \ \/ \/ / / / | |\/| | | | | . ` | | |
  26. \ /\ / / /__ | | | |_| |_| |\ |_| |_
  27. \/ \/ /_____| |_| |_|_____|_| \_|_____|
  28. ______
  29. |______|
  30. '
  31. set -x
  32. #replace stock busybox
  33. mount --bind /opt/wz_mini/bin/busybox /bin/busybox
  34. echo "replace stock fstab"
  35. mount --bind /opt/wz_mini/etc/fstab /etc/fstab
  36. echo "mount workplace dir"
  37. mount -t tmpfs /opt/wz_mini/tmp
  38. echo "install busybox applets"
  39. mkdir /opt/wz_mini/tmp/.bin
  40. /opt/wz_mini/bin/busybox --install -s /opt/wz_mini/tmp/.bin
  41. ##DETECT CAMERA MODEL & PLATFORM TYPE
  42. #V2=WYZEC1-JZ
  43. #PANv1=WYZECP1_JEF
  44. #PANv2=HL_PAN2
  45. #V3=WYZE_CAKP2JFUS
  46. #DB3=WYZEDB3
  47. #mtdblock9 only exists on the T20 platform, indicating V2 or PANv1
  48. if [ -b /dev/mtdblock9 ]; then
  49. mkdir /opt/wz_mini/tmp/params
  50. mount -t jffs2 /dev/mtdblock9 /opt/wz_mini/tmp/params
  51. touch /opt/wz_mini/tmp/.$(cat /opt/wz_mini/tmp/params/config/.product_config | grep PRODUCT_MODEL | sed -e 's#.*=\(\)#\1#')
  52. touch /opt/wz_mini/tmp/.T20
  53. umount /opt/wz_mini/tmp/params
  54. rm -rf /opt/wz_mini/tmp/params
  55. elif [ -b /dev/mtdblock6 ]; then
  56. mkdir /opt/wz_mini/tmp/configs
  57. mount -t jffs2 /dev/mtdblock6 /opt/wz_mini/tmp/configs
  58. touch /opt/wz_mini/tmp/.$(cat /opt/wz_mini/tmp/configs/.product_config | grep PRODUCT_MODEL | sed -e 's#.*=\(\)#\1#')
  59. touch /opt/wz_mini/tmp/.T31
  60. umount /opt/wz_mini/tmp/configs
  61. rm -rf /opt/wz_mini/tmp/configs
  62. fi
  63. #Set the correct GPIO for the audio driver (T31 only)
  64. if [ -f /opt/wz_mini/tmp/.HL_PAN2 ]; then
  65. GPIO=7
  66. elif [ -f /opt/wz_mini/tmp/.WYZE_CAKP2JFUS ]; then
  67. GPIO=63
  68. fi
  69. if [ -e /opt/wz_mini/etc/.first_boot ]; then
  70. echo "first boot already completed"
  71. else
  72. echo "first boot, initializing"
  73. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  74. #May need different gpio for PANv1
  75. #We don't rmmod this module, as it is marked [permanent] by the kernel on T20
  76. insmod /opt/wz_mini/lib/modules/3.10.14/extra/audio.ko sign_mode=0
  77. LD_LIBRARY_PATH='/opt/wz_mini/lib' /opt/wz_mini/bin/audioplay_t20 /opt/wz_mini/usr/share/audio/init_v2.wav $AUDIO_PROMPT_VOLUME
  78. else
  79. insmod /opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__/extra/audio.ko spk_gpio=$GPIO alc_mode=0 mic_gain=0
  80. /opt/wz_mini/bin/audioplay_t31 /opt/wz_mini/usr/share/audio/init.wav $AUDIO_PROMPT_VOLUME
  81. rmmod audio
  82. fi
  83. fi
  84. touch /opt/wz_mini/etc/.first_boot
  85. mount --bind /opt/wz_mini/etc/inittab /etc/inittab
  86. echo "bind /etc/profile for local/ssh shells"
  87. mount --bind /opt/wz_mini/etc/profile /etc/profile
  88. echo "mounting tmpfs"
  89. mount -t tmpfs /tmp
  90. echo "mount system to replace factorycheck with dummy, to prevent bind unmount"
  91. if [ -f /opt/wz_mini/tmp/.T31 ]; then
  92. mount /dev/mtdblock3 /system
  93. mount --bind /opt/wz_mini/bin/factorycheck /system/bin/factorycheck
  94. fi
  95. touch /tmp/usrflag
  96. echo "create workspace directory"
  97. mkdir /opt/wz_mini/tmp/.storage
  98. echo "copy stock rcS"
  99. cp /etc/init.d/rcS /opt/wz_mini/tmp/.storage/rcS
  100. echo "add wz_post inject to stock rcS"
  101. sed -i '/^".*/aset -x' /opt/wz_mini/tmp/.storage/rcS
  102. sed -i '/^# Mount configs.*/i/opt/wz_mini/etc/init.d/wz_post.sh\n' /opt/wz_mini/tmp/.storage/rcS
  103. sed -i '/sbin:/s/$/:\/opt\/wz_mini\/bin/' /opt/wz_mini/tmp/.storage/rcS
  104. sed -i '/system\/\lib/s/$/:\/opt\/wz_mini\/lib/' /opt/wz_mini/tmp/.storage/rcS
  105. #Custom PATH hooks
  106. #sed -i '/^# Run init script.*/i#Hook Library PATH here\nexport LD_LIBRARY_PATH=/tmp/test/lib:$LD_LIBRARY_PATH\n' /opt/wz_mini/tmp/.storage/rcS
  107. #sed -i '/^# Run init script.*/i#Hook system PATH here\nexport PATH=/tmp/test/bin:$PATH\n' /opt/wz_mini/tmp/.storage/rcS
  108. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  109. mount -t jffs2 /dev/mtdblock4 /system
  110. fi
  111. echo "Copy factory app_init.sh"
  112. cp /system/init/app_init.sh /opt/wz_mini/tmp/.storage/app_init.sh
  113. echo "Replace factory app_init.sh path"
  114. sed -i '/\/system\/init\/app_init.sh/,+4d' /opt/wz_mini/tmp/.storage/rcS
  115. sed -i '/Run init script.*/a /opt/wz_mini/tmp/.storage/app_init.sh\n' /opt/wz_mini/tmp/.storage/rcS
  116. sed -i '/\/system\/init\/app_init.sh/,+2d' /opt/wz_mini/tmp/.storage/rcS
  117. echo "replace stock password"
  118. cp /opt/wz_mini/etc/shadow /opt/wz_mini/tmp/.storage/shadow
  119. if [[ "$DEBUG_PASSWORD" == "true" ]]; then
  120. sed -i 's/:[^:]*/:/' /opt/wz_mini/tmp/.storage/shadow
  121. fi
  122. mount --bind /opt/wz_mini/tmp/.storage/shadow /etc/shadow
  123. chmod 400 /etc/shadow
  124. if [[ -e /opt/wz_mini/swap.gz ]]; then
  125. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  126. LD_LIBRARY_PATH='/opt/wz_mini/lib' /opt/wz_mini/bin/audioplay_t20 /opt/wz_mini/usr/share/audio/swap_v2.wav $AUDIO_PROMPT_VOLUME
  127. else
  128. insmod /opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__/extra/audio.ko spk_gpio=$GPIO alc_mode=0 mic_gain=0
  129. /opt/wz_mini/bin/audioplay_t31 /opt/wz_mini/usr/share/audio/swap.wav $AUDIO_PROMPT_VOLUME
  130. rmmod audio
  131. fi
  132. echo "swap archive present, extracting"
  133. gzip -d /opt/wz_mini/swap.gz
  134. mkswap /opt/wz_mini/swap
  135. sync;echo 3 > /proc/sys/vm/drop_caches
  136. else
  137. echo "swap archive missing, not extracting"
  138. fi
  139. if [ -d /opt/wz_mini/usr/share/terminfo ]; then
  140. echo "terminfo already present"
  141. else
  142. echo "terminfo not present, extract"
  143. tar xf /opt/wz_mini/usr/share/terminfo.tar -C /opt/wz_mini/usr/share/
  144. fi
  145. echo "Run dropbear ssh server"
  146. /opt/wz_mini/bin/dropbear -R -s -g
  147. if [[ "$DEBUG_ENABLED" == "true" ]]; then
  148. sed -i '/app_init.sh/,+4d' /opt/wz_mini/tmp/.storage/rcS
  149. sed -i '/^# Run init/i/bin/sh /etc/profile' /opt/wz_mini/tmp/.storage/rcS
  150. touch /tmp/dbgflag
  151. elif [[ "$WEB_CAM_ENABLE" == "true" ]]; then
  152. sed -i '/app_init.sh/,+4d' /opt/wz_mini/tmp/.storage/rcS
  153. sed -i '/^# Run init/i/opt/wz_mini/etc/init.d/wz_cam.sh &' /opt/wz_mini/tmp/.storage/rcS
  154. touch /tmp/dbgflag
  155. elif [[ -d /opt/Upgrade ]]; then
  156. sed -i '/app_init.sh/,+4d' /opt/wz_mini/tmp/.storage/rcS
  157. sed -i '/^# Run init/i/bin/sh /etc/profile' /opt/wz_mini/tmp/.storage/rcS
  158. sed -i '/^# Mount configs.*/i/opt/wz_mini/bin/upgrade-run.sh &\n' /opt/wz_mini/tmp/.storage/rcS
  159. touch /tmp/dbgflag
  160. fi
  161. /linuxrc