oboo.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/bin/sh
  2. ## Oboo script for various functionality
  3. ### global variables
  4. # options
  5. bVerbose=0
  6. bJson=0
  7. bTest=0
  8. bBase64=0
  9. bError=0
  10. #commands
  11. bCmd=0
  12. scriptCommand=""
  13. scriptOption0=""
  14. scriptOption1=""
  15. scriptOption2=""
  16. _Print () {
  17. echo "$1"
  18. }
  19. #############################
  20. ##### Print Usage ###########
  21. configUsage () {
  22. _Print "Oboo Configuration File:"
  23. _Print " oboo [OPTIONS] config generate"
  24. _Print " Create a generic configuration file"
  25. _Print ""
  26. }
  27. cardsUsage () {
  28. _Print "Oboo Cards:"
  29. _Print " oboo [OPTIONS] cards restart"
  30. _Print " Restart the Oboo Cards and Card Manager"
  31. _Print ""
  32. }
  33. uhttpdUsage () {
  34. _Print "uHTTPd:"
  35. _Print " oboo [OPTIONS] uhttpd cors [enable/disable]"
  36. _Print " Configure CORS on uHTTPd and restart the service"
  37. _Print ""
  38. }
  39. usage () {
  40. _Print "Functionality:"
  41. _Print " Configure Oboo products"
  42. _Print ""
  43. _Print "General Usage:"
  44. _Print " oboo [OPTIONS] <COMMAND> <PARAMETER>"
  45. _Print ""
  46. configUsage
  47. cardsUsage
  48. uhttpdUsage
  49. _Print ""
  50. _Print "Command Line Options:"
  51. _Print " -v Increase output verbosity"
  52. #_Print " -j Set all output to JSON"
  53. _Print ""
  54. }
  55. ########################################
  56. ### Configuration Functions
  57. ########################################
  58. # create a generic config file
  59. configFileGenerate () {
  60. local config='{
  61. "config": {
  62. "hourMode": 12,
  63. "dayNightLed": true,
  64. "location": "Toronto, On",
  65. "brightnessTime": 1,
  66. "brightnessInfo": 7,
  67. "tz": "GMT",
  68. "timezone": "GMT0",
  69. "autoTimeZone": false
  70. },
  71. "cards": {
  72. "0": {
  73. "name": "weather",
  74. "id": 0,
  75. "tempUnit": "fahrenheit",
  76. "card": "Weather",
  77. "location": "Toronto, On",
  78. "distanceUnit": "imperial"
  79. }
  80. }
  81. }'
  82. # echo "$config"
  83. echo "$config" > /etc/config.json
  84. }
  85. ########################################
  86. ### Card Functions
  87. ########################################
  88. # restart the card manager and the cards
  89. cardRestart () {
  90. /etc/init.d/card-manager restart
  91. /etc/init.d/oboo-cards restart
  92. }
  93. ########################################
  94. ### uhttpd Functions
  95. ########################################
  96. # enable/disable uHTTPd CORS
  97. uhttpdSetCors () {
  98. uci set uhttpd.main.ubus_cors="$1"
  99. uci commit uhttpd
  100. }
  101. # restart the uhttpd service
  102. uhttpdRestart () {
  103. /etc/init.d/uhttpd restart
  104. }
  105. # enable cors and restart the service
  106. uhttpdEnableCors () {
  107. uhttpdSetCors "1"
  108. uhttpdRestart
  109. }
  110. # disable cors and restart the service
  111. uhttpdDisableCors () {
  112. uhttpdSetCors "0"
  113. uhttpdRestart
  114. }
  115. ########################################
  116. ### Parse Arguments
  117. ########################################
  118. # parse arguments
  119. while [ "$1" != "" ]
  120. do
  121. case "$1" in
  122. # options
  123. -v|--v|-verbose|verbose)
  124. bVerbose=1
  125. shift
  126. ;;
  127. # commands
  128. config)
  129. bCmd=1
  130. scriptCommand="config"
  131. shift
  132. scriptOption0="$1"
  133. shift
  134. ;;
  135. cards)
  136. bCmd=1
  137. scriptCommand="cards"
  138. shift
  139. scriptOption0="$1"
  140. shift
  141. ;;
  142. uhttpd)
  143. bCmd=1
  144. scriptCommand="uhttpd"
  145. shift
  146. scriptOption0="$1"
  147. shift
  148. scriptOption1="$1"
  149. shift
  150. ;;
  151. *)
  152. echo "ERROR: Invalid Argument: $1"
  153. usage
  154. exit
  155. ;;
  156. esac
  157. done
  158. ########################################
  159. ########################################
  160. ### Main Program
  161. ########################################
  162. ## commands
  163. if [ $bCmd == 1 ]; then
  164. if [ "$scriptCommand" == "config" ]; then
  165. if [ "$scriptOption0" == "generate" ]; then
  166. configFileGenerate
  167. fi
  168. elif [ "$scriptCommand" == "cards" ]; then
  169. if [ "$scriptOption0" == "restart" ]; then
  170. cardRestart
  171. fi
  172. elif [ "$scriptCommand" == "uhttpd" ]; then
  173. if [ "$scriptOption0" == "cors" ]; then
  174. if [ "$scriptOption1" == "enable" ]; then
  175. uhttpdEnableCors
  176. elif [ "$scriptOption1" == "disable" ]; then
  177. uhttpdDisableCors
  178. fi
  179. fi
  180. fi
  181. _Print "> Done"
  182. else
  183. usage
  184. fi