wz_user.sh 18 KB

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