adb-enablemodem 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. adb_exec() {
  4. adb -s "$serial" shell "( $1 ) >/dev/null 2>&1"'; printf "\nEXIT_CODE: %i\n" $?' | head -c 64 | grep -qx 'EXIT_CODE: 0\r\?'
  5. }
  6. enablemodem_do() {
  7. logger -t adb-enablemodem 'INFO: waiting for device'
  8. adb wait-for-device
  9. serial="$(adb get-serialno)"
  10. vendor_id="$(adb -s "$serial" shell 'uci get product.usb.vid' | head -c 16 | tr -d '\r\n')"
  11. product_id="$(adb -s "$serial" shell 'uci get product.usb.pid' | head -c 16 | tr -d '\r\n')"
  12. case "$vendor_id:$product_id" in
  13. "0x2357:0x000D") # TP-LINK LTE MODULE
  14. case "$1" in
  15. start)
  16. if adb_exec '
  17. chmod +x /WEBSERVER/www/cgi-bin/*
  18. fds="$(ls /proc/$$/fd | grep -v "^[012]$")"
  19. for fd in $fds; do
  20. eval "exec $fd>&-"
  21. done
  22. start-stop-daemon -x httpd -S -- -h /WEBSERVER/www/
  23. '; then
  24. logger -t adb-enablemodem 'INFO: httpd on modem started'
  25. else
  26. logger -t adb-enablemodem 'ERROR: failed to start httpd on modem'
  27. fi
  28. option_newid='/sys/bus/usb-serial/drivers/option1/new_id'
  29. if [ -e "$option_newid" ]; then
  30. printf '%s %s' "$vendor_id" "$product_id" > "$option_newid"
  31. fi
  32. ;;
  33. stop)
  34. if adb_exec 'start-stop-daemon -x httpd -K'; then
  35. logger -t adb-enablemodem 'INFO: httpd on modem stopped'
  36. else
  37. logger -t adb-enablemodem 'ERROR: failed to stop httpd on modem'
  38. fi
  39. ;;
  40. esac
  41. ;;
  42. *)
  43. logger -t adb-enablemodem "ERROR: unknown device $vendor_id:$product_id"
  44. ;;
  45. esac
  46. }
  47. start() {
  48. ( enablemodem_do start ) &
  49. }
  50. stop() {
  51. ( enablemodem_do stop ) &
  52. }
  53. restart() {
  54. ( enablemodem_do stop; enablemodem_do start ) &
  55. }