fork download
  1. #!/bin/sh
  2.  
  3. fota() {
  4. usage () {
  5. echo "error: $1"
  6. echo "Usage: $0 COMMAND CUREF VERSION [TO_VERSION FWID] [ENV]"
  7. echo " - TO_VERSION and FWID are required when COMMAND is 'download'."
  8. echo " - ENV can be a URL or one of: prod, test, dev"
  9. exit 1
  10. }
  11.  
  12. id=0123456780123456
  13. [ $# -ge 1 ] || usage "Missing parameter: COMMAND"
  14. cmd=$1
  15. shift
  16. [ $# -ge 1 ] || usage "Missing parameter: CUREF"
  17. cu=$1
  18. shift
  19. [ $# -ge 1 ] || usage "Missing parameter: VERSION"
  20. fv=$1
  21. shift
  22. env=prod
  23.  
  24. get_env () {
  25. if [ -n "$1" ]; then
  26. env=$1
  27. fi
  28. case "$env" in
  29. prod)
  30. env="http://m...content-available-to-author-only...h.com"
  31. ;;
  32. test)
  33. env="http://m...content-available-to-author-only...h.com"
  34. ;;
  35. dev)
  36. env="http://m...content-available-to-author-only...h.com"
  37. ;;
  38. http://*|https://*)
  39. ;;
  40. *)
  41. echo "Invalid environment $env"
  42. exit 1
  43. ;;
  44. esac
  45. }
  46.  
  47. f_check () {
  48. local data tv fwid
  49. data=$(curl -s "$env/check.php?id=$id&cltp=1&fv=$fv&mode=2&type=FIRMWARE&curef=$cu")
  50. tv=$(echo "$data" | grep -o '<TV>[^<]*</TV>' | sed 's/<[^>]*>//g')
  51. fwid=$(echo "$data" | grep -o '<FW_ID>[^<]*</FW_ID>' | sed 's/<[^>]*>//g')
  52. echo "$cu: $fv: ${tv:+"$tv ($fwid)"}"
  53. }
  54. f_download () {
  55. local data slv url
  56. data=$(echo "id=$id&cltp=1&fv=$fv&tv=$tv&mode=2&type=FIRMWARE&curef=$cu&salt=1&vk=1&fw_id=$fwid" | curl -d@- -X POST -s "$env/download_request.php")
  57. url=$(echo "$data" | grep -o '<DOWNLOAD_URL>[^<]*</DOWNLOAD_URL>' | sed 's/<[^>]*>//g')
  58. slv=$(echo "$data" | grep -o '<SLAVE>[^<]*</SLAVE>' | sed 's/<[^>]*>//g')
  59. echo "http://$slv$url"
  60. }
  61.  
  62. case "$cmd" in
  63. check)
  64. get_env "$1"
  65. f_check
  66. ;;
  67. download)
  68. tv=$1
  69. [ $# -ge 1 ] || usage "Missing parameter: TO_VERSION"
  70. shift
  71. [ $# -ge 1 ] || usage "Missing parameter: FWID"
  72. fwid=$1
  73. shift
  74. get_env "$1"
  75. f_download
  76. ;;
  77. *)
  78. echo "Unknown command: $1"
  79. exit 1
  80. ;;
  81. esac
  82. }
  83.  
  84. -x
  85.  
  86. fota check BTS-23BTS70VN00 2.5.2
  87.  
Success #stdin #stdout #stderr 0.02s 12752KB
stdin
Standard input is empty
stdout
BTS-23BTS70VN00: 2.5.2: 
stderr
./prog.sh: line 84: -x: command not found