wz_user.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. bonding_setup() {
  99. echo "bonding kernel module setup"
  100. if [[ "$BONDING_ENABLED" == "true" ]]; then
  101. if [[ "$BONDING_LINK_MONITORING_FREQ_MS" == "" ]]; then
  102. BONDING_LINK_MONITORING_FREQ_MS="100"
  103. fi
  104. if [[ "$BONDING_DOWN_DELAY_MS" == "" ]]; then
  105. BONDING_DOWN_DELAY_MS="5000"
  106. fi
  107. if [[ "$BONDING_UP_DELAY_MS" == "" ]]; then
  108. BONDING_UP_DELAY_MS="5000"
  109. fi
  110. if [[ "$BONDING_PRIMARY_INTERFACE" == "" ]]; then
  111. BONDING_PRIMARY_INTERFACE="$1"
  112. fi
  113. if [[ "$BONDING_SECONDARY_INTERFACE" == "" ]]; then
  114. BONDING_SECONDARY_INTERFACE="$2"
  115. fi
  116. if [[ "$BONDING_FAIL_OVER_MAC" == "" ]]; then
  117. BONDING_FAIL_OVER_MAC="0"
  118. fi
  119. # Insert the bonding driver into the kernel
  120. 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" fail_over_mac="$BONDING_FAIL_OVER_MAC"
  121. fi
  122. }
  123. eth_wlan_up() {
  124. ##Run DHCP client, and bind mount our fake wpa_cli.sh to fool iCamera
  125. ifconfig wlan0 up
  126. pkill udhcpc
  127. udhcpc -i wlan0 -x hostname:$CUSTOM_HOSTNAME -p /var/run/udhcpc.pid -b
  128. # If running with Interface Bonding enabled, kill any existing
  129. # wpa_supplicant that might be running and spawn our own instead
  130. if [[ "$BONDING_ENABLED" == "true" ]] && ([[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]); then
  131. /opt/wz_mini/bin/busybox killall wpa_supplicant
  132. wpa_supplicant -D nl80211 -i wlanold -c /tmp/wpa_supplicant.conf -B -s
  133. fi
  134. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  135. mount -o bind /opt/wz_mini/bin/wpa_cli.sh /system/bin/wpa_cli
  136. else
  137. mount -o bind /opt/wz_mini/bin/wpa_cli.sh /bin/wpa_cli
  138. fi
  139. break
  140. }
  141. wpa_check() {
  142. #Check if wpa_supplicant has been created by iCamera
  143. if [ -e /tmp/wpa_supplicant.conf ]; then
  144. echo "wpa_supplicant.conf ready"
  145. wlanold_check $1
  146. else
  147. echo "wpa_supplicant.conf not ready, wait some time for creation."
  148. COUNT=0
  149. ATTEMPTS=15
  150. until [[ -e /tmp/wpa_supplicant.conf ]] || [[ $COUNT -eq $ATTEMPTS ]]; do
  151. echo -e "$(( COUNT++ ))... \c"
  152. sleep 5
  153. done
  154. [[ $COUNT -eq $ATTEMPTS ]] && echo "time exceeded waiting for iCamera, continue potentially broken condition without network." && wlanold_check $1
  155. fi
  156. }
  157. wlanold_check() {
  158. #Have we renamed interfaces yet?
  159. if [ -d /sys/class/net/wlanold ]; then
  160. echo "wlanold exist"
  161. eth_wlan_up
  162. else
  163. echo "wlanold doesn't exist"
  164. if [[ "$BONDING_ENABLED" == "true" ]] && ([[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]); then
  165. rename_interface_and_setup_bonding bond0 "$BONDING_PRIMARY_INTERFACE" "$BONDING_SECONDARY_INTERFACE"
  166. else
  167. rename_interface $1
  168. fi
  169. fi
  170. }
  171. netloop() {
  172. ##While loop for check
  173. while true
  174. do
  175. wpa_check $1
  176. echo "wlan0 not ready yet..."
  177. sleep 5
  178. done
  179. }
  180. swap_enable() {
  181. if [ -e /opt/wz_mini/swap ]; then
  182. echo "Swap file exists"
  183. if cat /proc/swaps | grep "mini" ; then
  184. echo "Swap is already enabled"
  185. else
  186. echo "Enable swap"
  187. swapon /opt/wz_mini/swap
  188. fi
  189. else
  190. echo "Swap file missing!"
  191. fi
  192. }
  193. dmesg_log() {
  194. DMESG_LOG=/opt/wz_mini/log/dmesg
  195. if [[ -e $DMESG_LOG.log || -L $DMESG_LOG.log ]] ; then
  196. i=0
  197. while [[ -e $DMESG_LOG.log.$i || -L $DMESG_LOG.log.$i ]] ; do
  198. let i++
  199. done
  200. mv $DMESG_LOG.log $DMESG_LOG.log.$i
  201. DMESG_LOG=$DMESG_LOG
  202. fi
  203. touch -- "$DMESG_LOG".log
  204. dmesg > $DMESG_LOG.log 2>&1
  205. }
  206. trim_logs() {
  207. echo "Deleting logs older than 5 boots..."
  208. find /opt/wz_mini/log -name '*log*' | while read file; do
  209. [ "${file#/opt/wz_mini/log/*log.}" -gt 5 ] && rm -v "$file"
  210. done
  211. }
  212. first_run_check
  213. wait_wlan
  214. #Set module dir depending on platform
  215. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  216. KMOD_PATH="/opt/wz_mini/lib/modules/3.10.14"
  217. else
  218. KMOD_PATH="/opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__"
  219. fi
  220. swap_enable
  221. if [[ "$ENABLE_IPV6" == "true" ]]; then
  222. echo "ipv6 enabled"
  223. else
  224. echo "ipv6 disabled"
  225. sysctl -w net.ipv6.conf.all.disable_ipv6=1
  226. fi
  227. if [[ "$ENABLE_NFSv4" == "true" ]]; then
  228. insmod $KMOD_PATH/kernel/lib/oid_registry.ko
  229. insmod $KMOD_PATH/kernel/net/dns_resolver/dns_resolver.ko
  230. insmod $KMOD_PATH/kernel/fs/nfs/nfsv4.ko
  231. insmod $KMOD_PATH/kernel/net/sunrpc/auth_gss/auth_rpcgss.ko
  232. echo nfsv4 enabled
  233. else
  234. echo nfsv4 disabled
  235. fi
  236. if [[ "$ENABLE_IPTABLES" == "true" ]]; then
  237. insmod $KMOD_PATH/kernel/net/netfilter/x_tables.ko
  238. insmod $KMOD_PATH/kernel/net/ipv4/netfilter/ip_tables.ko
  239. insmod $KMOD_PATH/kernel/net/ipv4/netfilter/ipt_REJECT.ko
  240. insmod $KMOD_PATH/kernel/net/ipv4/netfilter/iptable_filter.ko
  241. insmod $KMOD_PATH/kernel/net/ipv4/netfilter/iptable_mangle.ko
  242. echo "iptables ipv4 enabled"
  243. if [[ "$ENABLE_IPV6" == "true" ]]; then
  244. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6_tables.ko
  245. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6t_REJECT.ko
  246. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6table_filter.ko
  247. insmod $KMOD_PATH/kernel/net/ipv6/netfilter/ip6table_mangle.ko
  248. echo "iptables ipv6 enabled"
  249. fi
  250. else
  251. echo "iptables disabled"
  252. fi
  253. if [[ "$ENABLE_USB_ETH" == "true" ]]; then
  254. insmod $KMOD_PATH/kernel/drivers/net/usb/usbnet.ko
  255. # Auto-Detect an Ethernet Driver and load it
  256. if [[ "$ENABLE_USB_ETH_MODULE_AUTODETECT" == "true" ]]; then
  257. for DEVICE in `lsusb | awk '{print $6}'| tr '[:upper:]' '[:lower:]'`; do
  258. case $DEVICE in
  259. '077b:2226' | '0846:1040' | '2001:1a00' | '0b95:1720' | '07b8:420a' |\
  260. '08dd:90ff' | '0557:2009' | '0411:003d' | '0411:006e' | '6189:182d' |\
  261. '0df6:0056' | '07aa:0017' | '1189:0893' | '1631:6200' | '04f1:3008' |\
  262. '17ef:7203' | '0b95:772b' | '0b95:7720' | '0b95:1780' | '0789:0160' |\
  263. '13b1:0018' | '1557:7720' | '07d1:3c05' | '2001:3c05' | '2001:1a02' |\
  264. '1737:0039' | '04bb:0930' | '050d:5055' | '05ac:1402' | '0b95:772a' |\
  265. '14ea:ab11' | '0db0:a877' | '0b95:7e2b' | '0b95:172a' | '066b:20f9')
  266. echo "Loading ASIX Ethernet driver..."
  267. modprobe asix
  268. ;;
  269. '0b95:1790' | '0b95:178a' | '0df6:0072')
  270. echo "Loading AX88179 Gigabit Ethernet driver..."
  271. modprobe ax88179_178a
  272. ;;
  273. '1004:61aa' | '046d:c11f' | '1410:b001' | '1410:9010' | '413c:8195' |\
  274. '413c:8196' | '413c:819b' | '16d5:650a' | '12d1:14ac')
  275. echo "Loading USB CDC Ethernet driver..."
  276. modprobe cdc_ether
  277. ;;
  278. '0bda:8152')
  279. echo "Loading Realtek RTL8152 driver..."
  280. modprobe r8152
  281. ;;
  282. esac
  283. done
  284. fi
  285. # Manually load any other Ethernet Drivers if asked for
  286. if [[ "$ENABLE_USB_ETH_MODULE_MANUAL" != "" ]]; then
  287. for i in $(echo "$ENABLE_USB_ETH_MODULE_MANUAL" | tr "," "\n")
  288. do
  289. insmod $KMOD_PATH/kernel/drivers/net/usb/$i.ko
  290. done
  291. fi
  292. bonding_setup eth0 wlan0
  293. swap_enable
  294. netloop eth0
  295. else
  296. echo "USB Ethernet disabled"
  297. fi
  298. if [[ "$ENABLE_USB_DIRECT" == "true" ]]; then
  299. HOST_MACADDR=$(echo "$CUSTOM_HOSTNAME"|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
  300. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  301. echo connect > /sys/devices/platform/jz-dwc2/dwc2/udc/dwc2/soft_connect
  302. sleep 1
  303. devmem 0x10000040 32 0x0b800096
  304. sleep 1
  305. devmem 0x13500000 32 0x001100cc
  306. else
  307. #Set dwc2 ID_PIN driver memory
  308. devmem 0x13500000 32 0x001100cc
  309. devmem 0x10000040 32 0x0b000096
  310. #wipe the bits to set the ID_PIN, only for the V3.
  311. devmem 0x10000040 32 0x0b000FFF
  312. fi
  313. insmod $KMOD_PATH/kernel/drivers/usb/gadget/libcomposite.ko
  314. if [ -f /opt/wz_mini/tmp/.T31 ]; then
  315. insmod /opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__/kernel/drivers/usb/gadget/u_ether.ko
  316. insmod /opt/wz_mini/lib/modules/3.10.14__isvp_swan_1.0__/kernel/drivers/usb/gadget/usb_f_ncm.ko
  317. fi
  318. insmod $KMOD_PATH/kernel/drivers/usb/gadget/g_ncm.ko iManufacturer=wz_mini_ncm host_addr="$HOST_MACADDR" dev_addr="$USB_DIRECT_MAC_ADDR"
  319. sleep 1
  320. bonding_setup usb0 wlan0
  321. swap_enable
  322. #loop begin
  323. while true
  324. do
  325. wpa_check usb0
  326. echo "wlan0 not ready yet..."
  327. sleep 1
  328. done
  329. else
  330. echo "USB Direct disabled"
  331. fi
  332. if [[ "$ENABLE_USB_RNDIS" == "true" ]]; then
  333. if [[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]; then
  334. echo "RNDIS is not compatible with ENABLE_USB_ETH or ENABLE_USB_DIRECT. Please enable only ENABLE_USB_RNDIS"
  335. else
  336. insmod $KMOD_PATH/kernel/drivers/net/usb/usbnet.ko
  337. insmod $KMOD_PATH/kernel/drivers/net/usb/cdc_ether.ko
  338. insmod $KMOD_PATH/kernel/drivers/net/usb/rndis_host.ko
  339. sleep 1
  340. swap_enable
  341. #loop begin
  342. while true
  343. do
  344. wpa_check usb0
  345. echo "wlan0 not ready yet..."
  346. sleep 1
  347. done
  348. fi
  349. else
  350. echo "usb rndis disabled"
  351. fi
  352. if [[ "$ENABLE_WIREGUARD" == "true" ]]; then
  353. insmod $KMOD_PATH/kernel/net/ipv4/tunnel4.ko
  354. insmod $KMOD_PATH/kernel/net/ipv4/ip_tunnel.ko
  355. insmod $KMOD_PATH/kernel/net/wireguard/wireguard.ko
  356. if [[ "$WIREGUARD_IPV4" != "" ]]; then
  357. if [ -d /opt/wz_mini/etc/wireguard ]; then
  358. echo "wireguard dir exists"
  359. else
  360. mkdir -p /opt/wz_mini/etc/wireguard
  361. fi
  362. if [ ! -f /opt/wz_mini/etc/wireguard/privatekey ]; then
  363. (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)
  364. fi
  365. /opt/wz_mini/bin/busybox ip link add dev wg0 type wireguard
  366. /opt/wz_mini/bin/busybox ip address add dev wg0 "$WIREGUARD_IPV4"
  367. /opt/wz_mini/bin/wg set wg0 private-key /opt/wz_mini/etc/wireguard/privatekey
  368. /opt/wz_mini/bin/busybox ip link set wg0 up
  369. fi
  370. if [[ "$WIREGUARD_PEER_PUBLIC_KEY" != "" ]] && [[ "$WIREGUARD_PEER_ALLOWED_IPS" != "" ]] && [[ "$WIREGUARD_PEER_ENDPOINT" != "" ]] && [[ "$WIREGUARD_PEER_KEEP_ALIVE" != "" ]]; then
  371. /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"
  372. /opt/wz_mini/bin/busybox ip route add "$WIREGUARD_PEER_ALLOWED_IPS" dev wg0
  373. fi
  374. else
  375. echo "wireguard disabled"
  376. fi
  377. if [[ "$ENABLE_CIFS" == "true" ]]; then
  378. insmod $KMOD_PATH/kernel/fs/cifs/cifs.ko
  379. else
  380. echo "cifs disabled"
  381. fi
  382. if [[ "$ENABLE_USB_STORAGE" == "true" ]]; then
  383. insmod $KMOD_PATH/kernel/drivers/scsi/scsi_mod.ko
  384. insmod $KMOD_PATH/kernel/drivers/scsi/sd_mod.ko
  385. insmod $KMOD_PATH/kernel/drivers/usb/storage/usb-storage.ko
  386. else
  387. echo "usb_storage disabled"
  388. fi
  389. if [[ "$ENABLE_EXT4" == "true" ]]; then
  390. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  391. insmod $KMOD_PATH/kernel/lib/crc16.ko
  392. fi
  393. insmod $KMOD_PATH/kernel/fs/jbd2/jbd2.ko
  394. insmod $KMOD_PATH/kernel/fs/mbcache.ko
  395. insmod $KMOD_PATH/kernel/fs/ext4/ext4.ko
  396. else
  397. echo "ext4 disabled"
  398. fi
  399. if [[ "$DISABLE_FW_UPGRADE" == "true" ]]; then
  400. mkdir /tmp/Upgrade
  401. mount -t tmpfs -o size=1,nr_inodes=1 none /tmp/Upgrade
  402. #Setting this host causes iCamera to segfault, lets ignore it for now
  403. #echo -e "127.0.0.1 localhost \n127.0.0.1 wyze-upgrade-service.wyzecam.com" > /opt/wz_mini/tmp/.storage/hosts
  404. #mount --bind /opt/wz_mini/tmp/.storage/hosts /etc/hosts
  405. /opt/wz_mini/bin/busybox inotifyd /opt/wz_mini/usr/bin/watch_up.sh /tmp:n > /dev/null 2>&1 &
  406. else
  407. mkdir /tmp/Upgrade
  408. /opt/wz_mini/bin/busybox inotifyd /opt/wz_mini/usr/bin/watch_up.sh /tmp:n > /dev/null 2>&1 &
  409. fi
  410. if [[ "$REMOTE_SPOTLIGHT" == "true" ]]; then
  411. /opt/wz_mini/bin/socat pty,link=/dev/ttyUSB0,raw tcp:"$REMOTE_SPOTLIGHT_HOST":9000 &
  412. echo "remote accessory enabled"
  413. else
  414. echo "remote accessory disabled"
  415. fi
  416. if [[ "$ENABLE_MP4_WRITE" == "true" ]]; then
  417. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  418. echo "mp4_write is not supported on T20"
  419. else
  420. /opt/wz_mini/bin/cmd mp4write on
  421. echo "mp4_write enabled"
  422. fi
  423. else
  424. echo "mp4 write disabled"
  425. fi
  426. if [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then
  427. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  428. HI_VIDEO_DEV="/dev/video6"
  429. else
  430. HI_VIDEO_DEV="/dev/video1"
  431. fi
  432. swap_enable
  433. if [[ "$RTSP_PASSWORD" = "" ]]; then
  434. RTSP_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
  435. fi
  436. /opt/wz_mini/bin/cmd video 0 on
  437. if [[ "$RTSP_HI_RES_ENABLE_AUDIO" == "true" ]]; then
  438. /opt/wz_mini/bin/cmd audio 0 on
  439. AUDIO_CH="-C 1"
  440. AUDIO_FMT="-a S16_LE"
  441. DEVICE1="$HI_VIDEO_DEV,hw:0,0"
  442. else
  443. DEVICE1="$HI_VIDEO_DEV"
  444. echo "rtsp audio disabled"
  445. fi
  446. else
  447. echo "rtsp disabled"
  448. fi
  449. if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]]; then
  450. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  451. LOW_VIDEO_DEV="/dev/video7"
  452. else
  453. LOW_VIDEO_DEV="/dev/video2"
  454. fi
  455. swap_enable
  456. /opt/wz_mini/bin/cmd video 1 on
  457. if [[ "$RTSP_PASSWORD" = "" ]]; then
  458. RTSP_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
  459. fi
  460. if [[ "$RTSP_LOW_RES_ENABLE_AUDIO" == "true" ]]; then
  461. /opt/wz_mini/bin/cmd audio 1 on
  462. AUDIO_CH="-C 1"
  463. AUDIO_FMT="-a S16_LE"
  464. DEVICE2="$LOW_VIDEO_DEV,hw:2,0"
  465. else
  466. DEVICE2="$LOW_VIDEO_DEV"
  467. echo "rtsp audio disabled"
  468. fi
  469. else
  470. echo "rtsp disabled"
  471. fi
  472. if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]] || [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then
  473. echo "delay RTSP for iCamera"
  474. #This delay is required. Sometimes, if you start the rtsp server too soon, live view will break on the app.
  475. sleep 5
  476. 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 &
  477. sleep 1
  478. echo "Set imp variables via helper"
  479. /opt/wz_mini/usr/bin/imp_helper.sh > /dev/null 2>&1 &
  480. fi
  481. 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
  482. if [[ "$RTMP_STREAM_DISABLE_AUDIO" == "true" ]]; then
  483. RTMP_AUDIO="no_audio"
  484. fi
  485. echo "delay RTMP server"
  486. #Follow the delay from the RTSP server
  487. sleep 5
  488. /opt/wz_mini/bin/rtmp-stream.sh "$RMTP_STREAM_SERVICE" "$RTMP_AUDIO" &
  489. fi
  490. if [[ "$NIGHT_DROP_DISABLE" == "true" ]]; then
  491. touch /opt/wz_mini/tmp/.nd
  492. fi
  493. hostname_set
  494. touch /opt/wz_mini/tmp/.wz_user_firstrun
  495. pkill -f dumpload #Kill dumpload so it won't waste cpu or ram gathering cores and uploading them when something crashes
  496. sysctl -w kernel.core_pattern='|/bin/false'
  497. dmesg_log
  498. trim_logs
  499. sync;echo 3 > /proc/sys/vm/drop_caches
  500. if [ -f "$CUSTOM_SCRIPT_PATH" ]; then
  501. echo "starting custom script"
  502. $CUSTOM_SCRIPT_PATH &
  503. else
  504. echo "no custom script configured in wz_mini.conf"
  505. fi
  506. echo "searching for custom scripts in /opt/wz_mini/etc/rc.local.d"
  507. if [ -d "${1:-/opt/wz_mini/etc/rc.local.d}" ] ; then
  508. for filename in $(find /opt/wz_mini/etc/rc.local.d/ -name "*.sh" | /opt/wz_mini/bin/busybox sort) ; do
  509. if [ -f "${filename}" ] && [ -x "${filename}" ]; then
  510. echo "running ${filename}"
  511. "${filename}" &
  512. fi
  513. done
  514. fi
  515. echo "finished executing custom scripts from /opt/wz_mini/etc/rc.local.d"
  516. echo "wz_user.sh done" > /dev/kmsg