wz_user.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. #!/bin/sh
  2. LOG_NAME=/opt/wz_mini/log/wz_user
  3. if [[ -e $LOG_NAME.log || -L $LOG_NAME.log ]] ; then
  4. i=0
  5. while [[ -e $LOG_NAME.log.$i || -L $LOG_NAME.log.$i ]] ; do
  6. let i++
  7. done
  8. mv $LOG_NAME.log $LOG_NAME.log.$i
  9. LOG_NAME=$LOG_NAME
  10. fi
  11. touch -- "$LOG_NAME".log
  12. exec 1> $LOG_NAME.log 2>&1
  13. set -x
  14. echo "welcome to wz_user.sh"
  15. echo "PID $$"
  16. if [[ -e /tmp/dbgflag ]];then
  17. echo "debug mode, disabled"
  18. exit 0
  19. fi
  20. export WZMINI_CFG=/opt/wz_mini/wz_mini.conf
  21. [ -f $WZMINI_CFG ] && source $WZMINI_CFG
  22. hostname_set() {
  23. echo "set hostname"
  24. hostname $CUSTOM_HOSTNAME
  25. }
  26. first_run_check() {
  27. if [ -e /opt/wz_mini/tmp/.wz_user_firstrun ]; then
  28. echo "wz_user.sh already run once, exit."
  29. exit 0
  30. fi
  31. }
  32. store_mac() {
  33. echo "store original mac"
  34. cat /sys/class/net/wlan0/address | tr '[:lower:]' '[:upper:]' > /opt/wz_mini/tmp/wlan0_mac
  35. }
  36. wait_wlan() {
  37. ##Check if the driver has been loaded for the onboard wlan0, store the MAC.
  38. while true
  39. do
  40. if ifconfig wlan0 | grep "inet addr"; then
  41. store_mac
  42. break
  43. elif ifconfig wlan0 | grep "inet addr" && [[ "$ENABLE_USB_ETH" == "true" || "$ENABLE_USB_DIRECT" == "true" ]]; then
  44. store_mac
  45. break
  46. fi
  47. echo " wlan0 not ready yet..."
  48. sleep 5
  49. done
  50. }
  51. rename_interface() {
  52. ##Fool iCamera by renaming the hardline interface to wlan0
  53. echo "renaming interfaces"
  54. ifconfig $1 down
  55. ifconfig wlan0 down
  56. /opt/wz_mini/bin/busybox ip link set wlan0 name wlanold
  57. /opt/wz_mini/bin/busybox ip addr flush dev wlanold
  58. /opt/wz_mini/bin/busybox ip link set $1 name wlan0
  59. eth_wlan_up
  60. }
  61. rename_interface_and_setup_bonding() {
  62. ##Fool iCamera by renaming the hardline interface to wlan0
  63. ## $1 Bonding Interface, $2 Primary Interface, $3 Secondary Interface
  64. bonding_interface=$1
  65. primary_interface=$2
  66. secondary_interface=$3
  67. echo "renaming interfaces"
  68. # Bring all interfaces down
  69. ifconfig $bonding_interface down
  70. ifconfig $primary_interface down
  71. ifconfig $secondary_interface down
  72. # Have to bring bonding interface up to be able to bond our slaves.
  73. /opt/wz_mini/bin/busybox ip link set $bonding_interface up
  74. # Rename the real wlan0 interface if needed/used
  75. if [[ "$primary_interface" == "wlan0" ]]; then
  76. /opt/wz_mini/bin/busybox ip link set $primary_interface name wlanold
  77. /opt/wz_mini/bin/busybox ip addr flush dev wlanold
  78. primary_interface="wlanold"
  79. # Because we just changed the name of the primary interface, we need to
  80. # tell the bonding driver about the name change as well.
  81. echo "$primary_interface" > /sys/devices/virtual/net/$bonding_interface/bonding/primary
  82. fi
  83. if [[ "$secondary_interface" == "wlan0" ]]; then
  84. /opt/wz_mini/bin/busybox ip link set $secondary_interface name wlanold
  85. /opt/wz_mini/bin/busybox ip addr flush dev wlanold
  86. secondary_interface="wlanold"
  87. fi
  88. # Enslave the Ethernet and Original Wifi interfaces
  89. # under the bonding interface.
  90. /opt/wz_mini/tmp/.bin/ifenslave $bonding_interface $primary_interface $secondary_interface
  91. # Have to bring bonding interface down to be rename the interface
  92. /opt/wz_mini/bin/busybox ip link set $bonding_interface down
  93. # Name the bonding interface to be the "new" wlan0 interface
  94. /opt/wz_mini/bin/busybox ip link set $bonding_interface name wlan0
  95. # Bring the newly renamed wlan0 (actually the bond interface) back up
  96. eth_wlan_up
  97. }
  98. eth_wlan_up() {
  99. ##Run DHCP client, and bind mount our fake wpa_cli.sh to fool iCamera
  100. ifconfig wlan0 up
  101. pkill udhcpc
  102. udhcpc -i wlan0 -x hostname:$CUSTOM_HOSTNAME -p /var/run/udhcpc.pid -b
  103. # If running with Interface Bonding enabled, kill any existing
  104. # wpa_supplicant that might be running and spawn our own instead
  105. if [[ "$BONDING_ENABLED" == "true" ]] && ([[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]); then
  106. /opt/wz_mini/bin/busybox killall wpa_supplicant
  107. wpa_supplicant -D nl80211 -i wlanold -c /tmp/wpa_supplicant.conf -B -s
  108. fi
  109. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  110. mount -o bind /opt/wz_mini/bin/wpa_cli.sh /system/bin/wpa_cli
  111. else
  112. mount -o bind /opt/wz_mini/bin/wpa_cli.sh /bin/wpa_cli
  113. fi
  114. break
  115. }
  116. wpa_check() {
  117. #Check if wpa_supplicant has been created by iCamera
  118. if [ -e /tmp/wpa_supplicant.conf ]; then
  119. echo "wpa_supplicant.conf ready"
  120. wlanold_check $1
  121. else
  122. echo "wpa_supplicant.conf not ready, wait some time for creation."
  123. COUNT=0
  124. ATTEMPTS=15
  125. until [[ -e /tmp/wpa_supplicant.conf ]] || [[ $COUNT -eq $ATTEMPTS ]]; do
  126. echo -e "$(( COUNT++ ))... \c"
  127. sleep 5
  128. done
  129. [[ $COUNT -eq $ATTEMPTS ]] && echo "time exceeded waiting for iCamera, continue potentially broken condition without network." && wlanold_check $1
  130. fi
  131. }
  132. wlanold_check() {
  133. #Have we renamed interfaces yet?
  134. if [ -d /sys/class/net/wlanold ]; then
  135. echo "wlanold exist"
  136. eth_wlan_up
  137. else
  138. echo "wlanold doesn't exist"
  139. if [[ "$BONDING_ENABLED" == "true" ]] && ([[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]); then
  140. rename_interface_and_setup_bonding bond0 "$BONDING_PRIMARY_INTERFACE" "$BONDING_SECONDARY_INTERFACE"
  141. else
  142. rename_interface $1
  143. fi
  144. fi
  145. }
  146. netloop() {
  147. ##While loop for check
  148. while true
  149. do
  150. wpa_check $1
  151. echo "wlan0 not ready yet..."
  152. sleep 5
  153. done
  154. }
  155. swap_enable() {
  156. if [ -e /opt/wz_mini/swap ]; then
  157. echo "Swap file exists"
  158. if cat /proc/swaps | grep "mini" ; then
  159. echo "Swap is already enabled"
  160. else
  161. echo "Enable swap"
  162. swapon /opt/wz_mini/swap
  163. fi
  164. else
  165. echo "Swap file missing!"
  166. fi
  167. }
  168. dmesg_log() {
  169. DMESG_LOG=/opt/wz_mini/log/dmesg
  170. if [[ -e $DMESG_LOG.log || -L $DMESG_LOG.log ]] ; then
  171. i=0
  172. while [[ -e $DMESG_LOG.log.$i || -L $DMESG_LOG.log.$i ]] ; do
  173. let i++
  174. done
  175. mv $DMESG_LOG.log $DMESG_LOG.log.$i
  176. DMESG_LOG=$DMESG_LOG
  177. fi
  178. touch -- "$DMESG_LOG".log
  179. dmesg > $DMESG_LOG.log 2>&1
  180. }
  181. trim_logs() {
  182. echo "Deleting logs older than 5 boots..."
  183. find /opt/wz_mini/log -name '*log*' | while read file; do
  184. [ "${file#/opt/wz_mini/log/*log.}" -gt 5 ] && rm -v "$file"
  185. done
  186. }
  187. first_run_check
  188. wait_wlan
  189. #Set module dir depending on platform
  190. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  191. KMOD_PATH="/opt/wz_mini/lib/modules/3.10.14"
  192. else
  193. KMOD_PATH="/opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__"
  194. fi
  195. swap_enable
  196. if [[ "$ENABLE_IPV6" == "true" ]]; then
  197. echo "ipv6 enabled"
  198. else
  199. echo "ipv6 disabled"
  200. sysctl -w net.ipv6.conf.all.disable_ipv6=1
  201. fi
  202. if [[ "$ENABLE_NFSv4" == "true" ]]; then
  203. insmod $KMOD_PATH/kernel/lib/oid_registry.ko
  204. insmod $KMOD_PATH/kernel/net/dns_resolver/dns_resolver.ko
  205. insmod $KMOD_PATH/kernel/fs/nfs/nfsv4.ko
  206. insmod $KMOD_PATH/kernel/net/sunrpc/auth_gss/auth_rpcgss.ko
  207. echo nfsv4 enabled
  208. else
  209. echo nfsv4 disabled
  210. fi
  211. if [[ "$ENABLE_IPTABLES" == "true" ]]; then
  212. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  213. echo "T20 has iptables built in"
  214. else
  215. insmod /lib/modules/3.10.14__isvp_swan_1.0__/kernel/net/netfilter/x_tables.ko
  216. insmod /lib/modules/3.10.14__isvp_swan_1.0__/kernel/net/ipv4/netfilter/ip_tables.ko
  217. insmod /lib/modules/3.10.14__isvp_swan_1.0__/kernel/net/ipv4/netfilter/ipt_REJECT.ko
  218. insmod /lib/modules/3.10.14__isvp_swan_1.0__/kernel/net/ipv4/netfilter/iptable_filter.ko
  219. insmod /lib/modules/3.10.14__isvp_swan_1.0__/kernel/net/ipv4/netfilter/iptable_mangle.ko
  220. echo "iptables ipv4 enabled"
  221. fi
  222. if [[ "$ENABLE_IPV6" == "true" ]]; then
  223. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6_tables.ko
  224. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6t_REJECT.ko
  225. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6table_filter.ko
  226. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6table_mangle.ko
  227. echo "iptables ipv6 enabled"
  228. fi
  229. else
  230. echo "iptables disabled"
  231. fi
  232. if [[ "$ENABLE_USB_ETH" == "true" ]]; then
  233. insmod $KMOD_PATH/kernel/drivers/net/usb/usbnet.ko
  234. for i in $(echo "$ENABLE_USB_ETH_MODULES" | tr "," "\n")
  235. do
  236. insmod $KMOD_PATH/kernel/drivers/net/usb/$i.ko
  237. done
  238. if [[ "$BONDING_ENABLED" == "true" ]]; then
  239. if [[ "$BONDING_LINK_MONITORING_FREQ_MS" == "" ]]; then
  240. "$BONDING_LINK_MONITORING_FREQ_MS" = "100"
  241. fi
  242. if [[ "$BONDING_DOWN_DELAY_MS" == "" ]]; then
  243. "$BONDING_DOWN_DELAY_MS" = "5000"
  244. fi
  245. if [[ "$BONDING_UP_DELAY_MS" == "" ]]; then
  246. "$BONDING_UP_DELAY_MS" = "5000"
  247. fi
  248. if [[ "$BONDING_PRIMARY_INTERFACE" == "" ]]; then
  249. "$BONDING_PRIMARY_INTERFACE" = "eth0"
  250. fi
  251. if [[ "$BONDING_SECONDARY_INTERFACE" == "" ]]; then
  252. "$BONDING_SECONDARY_INTERFACE" = "wlan0"
  253. fi
  254. # Insert the bonding driver into the kernel
  255. insmod $KMOD_PATH/kernel/drivers/net/bonding/bonding.ko mode=active-backup miimon="$BONDING_LINK_MONITORING_FREQ_MS" downdelay="$BONDING_DOWN_DELAY_MS" updelay="$BONDING_UP_DELAY_MS" primary="$BONDING_PRIMARY_INTERFACE"
  256. fi
  257. swap_enable
  258. netloop eth0
  259. else
  260. echo "usb ethernet disabled"
  261. fi
  262. if [[ "$ENABLE_USB_DIRECT" == "true" ]]; then
  263. HOST_MACADDR=$(echo "$CUSTOM_HOSTNAME"|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
  264. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  265. echo connect > /sys/devices/platform/jz-dwc2/dwc2/udc/dwc2/soft_connect
  266. sleep 1
  267. devmem 0x10000040 32 0x0b800096
  268. sleep 1
  269. devmem 0x13500000 32 0x001100cc
  270. else
  271. #Set dwc2 ID_PIN driver memory
  272. devmem 0x13500000 32 0x001100cc
  273. devmem 0x10000040 32 0x0b000096
  274. #wipe the bits to set the ID_PIN, only for the V3.
  275. devmem 0x10000040 32 0x0b000FFF
  276. fi
  277. insmod $KMOD_PATH/kernel/drivers/usb/gadget/libcomposite.ko
  278. if [ -f /opt/wz_mini/tmp/.T31 ]; then
  279. insmod /opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__/kernel/drivers/usb/gadget/u_ether.ko
  280. insmod /opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__/kernel/drivers/usb/gadget/usb_f_ncm.ko
  281. fi
  282. insmod $KMOD_PATH/kernel/drivers/usb/gadget/g_ncm.ko iManufacturer=wz_mini_ncm host_addr="$HOST_MACADDR" dev_addr="$USB_DIRECT_MAC_ADDR"
  283. sleep 1
  284. if [[ "$BONDING_ENABLED" == "true" ]]; then
  285. if [[ "$BONDING_LINK_MONITORING_FREQ_MS" == "" ]]; then
  286. "$BONDING_LINK_MONITORING_FREQ_MS" = "100"
  287. fi
  288. if [[ "$BONDING_DOWN_DELAY_MS" == "" ]]; then
  289. "$BONDING_DOWN_DELAY_MS" = "5000"
  290. fi
  291. if [[ "$BONDING_UP_DELAY_MS" == "" ]]; then
  292. "$BONDING_UP_DELAY_MS" = "5000"
  293. fi
  294. if [[ "$BONDING_PRIMARY_INTERFACE" == "" ]]; then
  295. "$BONDING_PRIMARY_INTERFACE" = "usb0"
  296. fi
  297. if [[ "$BONDING_SECONDARY_INTERFACE" == "" ]]; then
  298. "$BONDING_SECONDARY_INTERFACE" = "wlan0"
  299. fi
  300. # Insert the bonding driver into the kernel
  301. insmod $KMOD_PATH/kernel/drivers/net/bonding/bonding.ko mode=active-backup miimon="$BONDING_LINK_MONITORING_FREQ_MS" downdelay="$BONDING_DOWN_DELAY_MS" updelay="$BONDING_UP_DELAY_MS" primary="$BONDING_PRIMARY_INTERFACE"
  302. fi
  303. swap_enable
  304. #loop begin
  305. while true
  306. do
  307. wpa_check usb0
  308. echo "wlan0 not ready yet..."
  309. sleep 1
  310. done
  311. else
  312. echo "usb direct disabled"
  313. fi
  314. if [[ "$ENABLE_USB_RNDIS" == "true" ]]; then
  315. insmod $KMOD_PATH/kernel/drivers/net/usb/usbnet.ko
  316. insmod $KMOD_PATH/kernel/drivers/net/usb/cdc_ether.ko
  317. insmod $KMOD_PATH/kernel/drivers/net/usb/rndis_host.ko
  318. sleep 1
  319. swap_enable
  320. #loop begin
  321. while true
  322. do
  323. wpa_check usb0
  324. echo "wlan0 not ready yet..."
  325. sleep 1
  326. done
  327. else
  328. echo "usb direct disabled"
  329. fi
  330. if [[ "$ENABLE_WIREGUARD" == "true" ]]; then
  331. insmod $KMOD_PATH/kernel/net/ipv4/tunnel4.ko
  332. insmod $KMOD_PATH/kernel/net/ipv4/ip_tunnel.ko
  333. insmod $KMOD_PATH/kernel/net/wireguard/wireguard.ko
  334. if [[ "$WIREGUARD_IPV4" != "" ]]; then
  335. if [ -d /opt/wz_mini/etc/wireguard ]; then
  336. echo "wireguard dir exists"
  337. else
  338. mkdir -p /opt/wz_mini/etc/wireguard
  339. fi
  340. if [ ! -f /opt/wz_mini/etc/wireguard/privatekey ]; then
  341. (umask 277 && /opt/wz_mini/bin/wg genkey | /opt/wz_mini/bin/busybox tee /opt/wz_mini/etc/wireguard/privatekey | /opt/wz_mini/bin/wg pubkey > /opt/wz_mini/etc/wireguard/publickey)
  342. fi
  343. /opt/wz_mini/bin/busybox ip link add dev wg0 type wireguard
  344. /opt/wz_mini/bin/busybox ip address add dev wg0 "$WIREGUARD_IPV4"
  345. /opt/wz_mini/bin/wg set wg0 private-key /opt/wz_mini/etc/wireguard/privatekey
  346. /opt/wz_mini/bin/busybox ip link set wg0 up
  347. fi
  348. if [[ "$WIREGUARD_PEER_PUBLIC_KEY" != "" ]] && [[ "$WIREGUARD_PEER_ALLOWED_IPS" != "" ]] && [[ "$WIREGUARD_PEER_ENDPOINT" != "" ]] && [[ "$WIREGUARD_PEER_KEEP_ALIVE" != "" ]]; then
  349. /opt/wz_mini/bin/wg set wg0 peer "$WIREGUARD_PEER_PUBLIC_KEY" allowed-ips "$WIREGUARD_PEER_ALLOWED_IPS" endpoint "$WIREGUARD_PEER_ENDPOINT" persistent-keepalive "$WIREGUARD_PEER_KEEP_ALIVE"
  350. /opt/wz_mini/bin/busybox ip route add "$WIREGUARD_PEER_ALLOWED_IPS" dev wg0
  351. fi
  352. else
  353. echo "wireguard disabled"
  354. fi
  355. if [[ "$ENABLE_CIFS" == "true" ]]; then
  356. insmod $KMOD_PATH/kernel/fs/cifs/cifs.ko
  357. else
  358. echo "cifs disabled"
  359. fi
  360. if [[ "$ENABLE_USB_STORAGE" == "true" ]]; then
  361. insmod $KMOD_PATH/kernel/drivers/scsi/scsi_mod.ko
  362. insmod $KMOD_PATH/kernel/drivers/scsi/sd_mod.ko
  363. insmod $KMOD_PATH/kernel/drivers/usb/storage/usb-storage.ko
  364. else
  365. echo "usb_storage disabled"
  366. fi
  367. if [[ "$ENABLE_EXT4" == "true" ]]; then
  368. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  369. insmod $KMOD_PATH/kernel/lib/crc16.ko
  370. fi
  371. insmod $KMOD_PATH/kernel/fs/jbd2/jbd2.ko
  372. insmod $KMOD_PATH/kernel/fs/mbcache.ko
  373. insmod $KMOD_PATH/kernel/fs/ext4/ext4.ko
  374. else
  375. echo "ext4 disabled"
  376. fi
  377. if [[ "$DISABLE_FW_UPGRADE" == "true" ]]; then
  378. mkdir /tmp/Upgrade
  379. mount -t tmpfs -o size=1,nr_inodes=1 none /tmp/Upgrade
  380. echo -e "127.0.0.1 localhost \n127.0.0.1 wyze-upgrade-service.wyzecam.com" > /opt/wz_mini/tmp/.storage/hosts
  381. mount --bind /opt/wz_mini/tmp/.storage/hosts /etc/hosts
  382. else
  383. mkdir /tmp/Upgrade
  384. /opt/wz_mini/bin/busybox inotifyd /opt/wz_mini/usr/bin/watch_up.sh /tmp:n &
  385. fi
  386. if [[ "$REMOTE_SPOTLIGHT" == "true" ]]; then
  387. /opt/wz_mini/bin/socat pty,link=/dev/ttyUSB0,raw tcp:"$REMOTE_SPOTLIGHT_HOST":9000 &
  388. echo "remote accessory enabled"
  389. else
  390. echo "remote accessory disabled"
  391. fi
  392. if [[ "$ENABLE_MP4_WRITE" == "true" ]]; then
  393. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  394. echo "mp4_write is not supported on T20"
  395. else
  396. /opt/wz_mini/bin/cmd mp4write on
  397. echo "mp4_write enabled"
  398. fi
  399. else
  400. echo "mp4 write disabled"
  401. fi
  402. if [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then
  403. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  404. HI_VIDEO_DEV="/dev/video6"
  405. else
  406. HI_VIDEO_DEV="/dev/video1"
  407. fi
  408. swap_enable
  409. if [[ "$RTSP_PASSWORD" = "" ]]; then
  410. RTSP_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
  411. fi
  412. /opt/wz_mini/bin/cmd video on
  413. if [[ "$RTSP_HI_RES_ENABLE_AUDIO" == "true" ]]; then
  414. /opt/wz_mini/bin/cmd audio on
  415. AUDIO_CH="-C 1"
  416. AUDIO_FMT="-a S16_LE"
  417. DEVICE1="$HI_VIDEO_DEV,hw:Loopback,0"
  418. else
  419. DEVICE1="$HI_VIDEO_DEV"
  420. echo "rtsp audio disabled"
  421. fi
  422. if [[ "$RTSP_HI_RES_ENC_PARAMETER" != "" ]]; then
  423. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  424. if [[ $RTSP_HI_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]]; then
  425. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:0:4:$RTSP_HI_RES_ENC_PARAMETER" > /dev/null 2>&1 &
  426. sleep 5
  427. else
  428. echo "Invalid encoder value"
  429. fi
  430. else
  431. if [[ $RTSP_HI_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]]; then
  432. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:44:4:$RTSP_HI_RES_ENC_PARAMETER" > /dev/null 2>&1 &
  433. sleep 5
  434. else
  435. echo "Invalid encoder value"
  436. fi
  437. fi
  438. fi
  439. if [[ "$RTSP_HI_RES_MAX_BITRATE" != "" ]]; then
  440. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  441. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:28:4:$RTSP_HI_RES_MAX_BITRATE" > /dev/null 2>&1 &
  442. sleep 5
  443. else
  444. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:52:4:$RTSP_HI_RES_MAX_BITRATE" > /dev/null 2>&1 &
  445. sleep 5
  446. fi
  447. fi
  448. if [[ "$RTSP_HI_RES_TARGET_BITRATE" != "" ]]; then
  449. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  450. echo "not supported on T20"
  451. else
  452. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:48:4:$RTSP_HI_RES_TARGET_BITRATE" > /dev/null 2>&1 &
  453. sleep 5
  454. fi
  455. fi
  456. if [[ "$RTSP_HI_RES_FPS" != "" ]]; then
  457. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  458. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:8:4:$RTSP_HI_RES_FPS" > /dev/null 2>&1 &
  459. sleep 5
  460. else
  461. watch -n30 -t "/system/bin/impdbg --enc_rc_s 0:80:4:$RTSP_HI_RES_FPS" > /dev/null 2>&1 &
  462. sleep 5
  463. fi
  464. fi
  465. else
  466. echo "rtsp disabled"
  467. fi
  468. if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]]; then
  469. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  470. LOW_VIDEO_DEV="/dev/video7"
  471. else
  472. LOW_VIDEO_DEV="/dev/video2"
  473. fi
  474. swap_enable
  475. /opt/wz_mini/bin/cmd video on1
  476. if [[ "$RTSP_PASSWORD" = "" ]]; then
  477. RTSP_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
  478. fi
  479. if [[ "$RTSP_LOW_RES_ENABLE_AUDIO" == "true" ]]; then
  480. /opt/wz_mini/bin/cmd audio on1
  481. AUDIO_CH="-C 1"
  482. AUDIO_FMT="-a S16_LE"
  483. DEVICE2="$LOW_VIDEO_DEV,hw:Loopback,1"
  484. else
  485. DEVICE2="$LOW_VIDEO_DEV"
  486. echo "rtsp audio disabled"
  487. fi
  488. if [[ "$RTSP_LOW_RES_ENC_PARAMETER" != "" ]]; then
  489. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  490. if [[ $RTSP_LOW_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]]; then
  491. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:0:4:$RTSP_LOW_RES_ENC_PARAMETER" > /dev/null 2>&1 &
  492. sleep 5
  493. else
  494. echo "Invalid encoder value"
  495. fi
  496. else
  497. if [[ $RTSP_LOW_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]]; then
  498. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:44:4:$RTSP_LOW_RES_ENC_PARAMETER" > /dev/null 2>&1 &
  499. else
  500. echo "Invalid encoder value"
  501. fi
  502. fi
  503. fi
  504. if [[ "$RTSP_LOW_RES_MAX_BITRATE" != "" ]]; then
  505. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  506. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:28:4:$RTSP_LOW_RES_MAX_BITRATE" > /dev/null 2>&1 &
  507. sleep 5
  508. else
  509. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:52:4:$RTSP_LOW_RES_MAX_BITRATE" > /dev/null 2>&1 &
  510. fi
  511. fi
  512. if [[ "$RTSP_LOW_RES_TARGET_BITRATE" != "" ]]; then
  513. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  514. echo "not supported on T20"
  515. else
  516. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:48:4:$RTSP_LOW_RES_TARGET_BITRATE" > /dev/null 2>&1 &
  517. fi
  518. fi
  519. if [[ "$RTSP_LOW_RES_FPS" != "" ]]; then
  520. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  521. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:8:4:$RTSP_LOW_RES_FPS" > /dev/null 2>&1 &
  522. sleep 5
  523. else
  524. watch -n30 -t "/system/bin/impdbg --enc_rc_s 1:80:4:$RTSP_LOW_RES_FPS" > /dev/null 2>&1 &
  525. fi
  526. fi
  527. else
  528. echo "rtsp disabled"
  529. fi
  530. if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]] || [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then
  531. echo "delay RTSP for iCamera"
  532. #This delay is required. Sometimes, if you start the rtsp server too soon, live view will break on the app.
  533. sleep 5
  534. LD_LIBRARY_PATH=/opt/wz_mini/lib /opt/wz_mini/bin/v4l2rtspserver $AUDIO_CH $AUDIO_FMT -F0 -U "$RTSP_LOGIN":"$RTSP_PASSWORD" -P "$RTSP_PORT" $DEVICE1 $DEVICE2 &
  535. fi
  536. if ([[ "$RTSP_LOW_RES_ENABLED" == "true" ]] || [[ "$RTSP_HI_RES_ENABLED" == "true" ]]) && [[ "$RTMP_STREAM_ENABLED" == "true" ]] && ([[ "$RTSP_LOW_RES_ENABLE_AUDIO" == "true" ]] || [[ "$RTSP_HI_RES_ENABLE_AUDIO" == "true" ]]); then
  537. if [[ "$RTMP_STREAM_DISABLE_AUDIO" == "true" ]]; then
  538. RTMP_AUDIO="no_audio"
  539. fi
  540. echo "delay RTMP server"
  541. #Follow the delay from the RTSP server
  542. sleep 5
  543. /opt/wz_mini/bin/rtmp-stream.sh "$RMTP_STREAM_SERVICE" "$RTMP_AUDIO"
  544. fi
  545. if [[ "$NIGHT_DROP_DISABLE" == "true" ]]; then
  546. touch /opt/wz_mini/tmp/.nd
  547. fi
  548. if [[ "$ENABLE_ATBM603X_DRIVER" == "true" ]]; then
  549. #Reduce dmesg log spam by driver
  550. echo "LOG_ERR=OFF LOG_WARN=ON LOG_LMAC=ON LOG_SCAN=OFF" > /sys/module/atbm603x_wifi_sdio/atbmfs/atbm_printk_mask
  551. fi
  552. hostname_set
  553. touch /opt/wz_mini/tmp/.wz_user_firstrun
  554. pkill -f dumpload #Kill dumpload so it won't waste cpu or ram gathering cores and uploading them when something crashes
  555. sysctl -w kernel.core_pattern='|/bin/false'
  556. dmesg_log
  557. trim_logs
  558. sync;echo 3 > /proc/sys/vm/drop_caches
  559. if [ -f "$CUSTOM_SCRIPT_PATH" ]; then
  560. echo "starting custom script"
  561. $CUSTOM_SCRIPT_PATH &
  562. else
  563. echo "custom script not found"
  564. fi
  565. echo "wz_user.sh done" > /dev/kmsg