S20initsetup 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:
  4. # Short-Description: Setup bindOk=1 once WiFi settings are detected when in self-hosted mode
  5. # Description: Update .user_config so bindOk=1 when QR code containing WiFi settings are scanned. Allows for WiFi to work on next reboot without needing Wyze App/Cloud initial setup.
  6. ### END INIT INFO
  7. . /opt/wz_mini/wz_mini.conf
  8. case "$1" in
  9. start)
  10. echo "#####$(basename "$0")#####"
  11. # If not enabled or on T20 which is unsupported by this script
  12. if [[ "$ENABLE_SELFHOSTED_MODE" != "true" ]] || [ ! -f /opt/wz_mini/tmp/.T31 ]; then
  13. exit 0
  14. fi
  15. # Note: At the time of this boot stage, /configs isn't mounted. If it's not mounted, we have to mount it to check the wifi status
  16. if mount | grep -q /configs ; then
  17. # Is it already set?
  18. if grep -q bindOk=1 /configs/.user_config ; then
  19. echo "Initial setup is done. Nothing to do."
  20. exit 0
  21. fi
  22. else
  23. mount -t jffs2 /dev/mtdblock6 /configs
  24. # Is it already set?
  25. if grep -q bindOk=1 /configs/.user_config ; then
  26. echo "Initial setup is done. Nothing to do."
  27. exit 0
  28. fi
  29. umount /configs
  30. fi
  31. echo "Initial setup not completed yet."
  32. # Wait until these wifi settings are set in /configs later on.
  33. # Note that /configs will be mounted eventually by the second stage boot.
  34. while true ; do
  35. if [ -f /configs/.wifipasswd ] && [ -s /configs/.wifipasswd ] && [ -f /configs/.wifissid ] && [ -s /configs/.wifissid ] ; then
  36. echo "Detected WiFi configs. "
  37. if wpa_cli -p /var/run/wpa_supplicant -i wlan0 STATUS | grep -q wpa_state=COMPLETED ; then
  38. echo "WiFi connection seems Good. Updating bindOk=1."
  39. sed -i 's/bindOk=0/bindOk=1/g' /configs/.user_config
  40. /opt/wz_mini/bin/cmd aplay /usr/share/notify/CN/connect_wifi_ok.wav 60
  41. grep bindOk /configs/.user_config
  42. exit 0
  43. fi
  44. fi
  45. echo "Waiting for WiFi settings from QR code..."
  46. sleep 5
  47. done &
  48. ;;
  49. *)
  50. echo "Usage: $0 {start}"
  51. exit 1
  52. ;;
  53. esac