You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.9 KiB

  1. #!/bin/sh
  2. # Converts a uci config file into an appropriate mosquitto.conf snippet
  3. # expected to be used in an init file to generate a config file to run from
  4. # Karl Palsson <karlp@remake.is> 2012.
  5. # Considered to be released into the public domain
  6. TCONF=/tmp/mosquitto.generated.$$.conf
  7. while getopts "f:" o; do
  8. case $o in
  9. f)
  10. TCONF=$OPTARG
  11. ;;
  12. esac
  13. done
  14. if [ -e $TCONF ]; then
  15. echo "Odd, same temporary generated config file already existed: $TCONF"
  16. exit 1
  17. fi
  18. echo "Generating mosquitto config file in $TCONF"
  19. NOW=$(date)
  20. echo "# mosquitto.conf file generated from UCI config." >>$TCONF
  21. echo "# Config snippet generated by $0 on $NOW" >>$TCONF
  22. echo "#" >> $TCONF
  23. QQ=$(uci -q get mosquitto.mosquitto.log_dest)
  24. if [ $? = 0 ]; then
  25. for dest in $QQ; do
  26. echo "log_dest $dest" >> $TCONF
  27. done
  28. fi
  29. QQ=$(uci -q get mosquitto.mosquitto.no_remote_access)
  30. if [ $? = 0 ]; then
  31. if [ "$QQ" -eq 1 ]; then
  32. echo "bind_address 127.0.0.1" >> $TCONF
  33. fi
  34. fi
  35. HATE_SECTION_COUNT=$(grep config /etc/config/mosquitto | grep bridge | wc -l)
  36. if [ $HATE_SECTION_COUNT -gt 0 ]; then
  37. for i in $(seq $HATE_SECTION_COUNT -1 1); do
  38. NN=$(uci -q get mosquitto.@bridge[-$i].connection)
  39. echo "" >> $TCONF
  40. echo "# Bridge connection from UCI section" >> $TCONF
  41. echo "connection $NN" >> $TCONF
  42. ADDR=$(uci -q get mosquitto.@bridge[-$i].address)
  43. echo "address $ADDR" >> $TCONF
  44. TOPICS=$(uci -q -d';' get mosquitto.@bridge[-$i].topic)
  45. # UGLY! just want to split on the ; :(
  46. echo $TOPICS | sed "s/^/topic /" | sed "s/;/\ntopic /g" >> $TCONF
  47. CS=$(uci -q get mosquitto.@bridge[-$i].cleansession)
  48. if [ $? -eq 0 ]; then
  49. if [ "$CS" -eq 1 ]; then
  50. echo "cleansession true" >> $TCONF
  51. fi
  52. else
  53. echo "cleansession false" >> $TCONF
  54. fi
  55. TRYPRIV=$(uci -q get mosquitto.@bridge[-$i].tryprivate)
  56. if [ $? -eq 0 ]; then
  57. if [ "$TRYPRIV" -eq 1 ]; then
  58. echo "try_private true" >> $TCONF
  59. else
  60. echo "try_private false" >> $TCONF
  61. fi
  62. else
  63. # Override default to avoid crashes with 0.15 brokers :(
  64. echo "try_private false" >> $TCONF
  65. fi
  66. CLIENTID=$(uci -q get mosquitto.@bridge[-$i].clientid)
  67. if [ $? -eq 0 ]; then
  68. echo "clientid $CLIENTID" >> $TCONF
  69. fi
  70. BRIDGEID=$(uci -q get mosquitto.@bridge[-$i].identity)
  71. if [ $? -eq 0 ]; then
  72. echo "bridge_identity $BRIDGEID" >> $TCONF
  73. fi
  74. BRIDGEPSK=$(uci -q get mosquitto.@bridge[-$i].psk)
  75. if [ $? -eq 0 ]; then
  76. echo "bridge_psk $BRIDGEPSK" >> $TCONF
  77. fi
  78. BRIDGETLSVERSION=$(uci -q get mosquitto.@bridge[-$i].tls_version)
  79. if [ $? -eq 0 ]; then
  80. echo "bridge_tls_version $BRIDGETLSVERSION" >> $TCONF
  81. fi
  82. done
  83. fi