freedombone-utils-avahi 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Avahi functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. function create_avahi_service {
  31. service_name=$1
  32. service_type=$2
  33. service_protocol=$3
  34. service_port=$4
  35. service_description="$5"
  36. if [ ! -d /etc/avahi ]; then
  37. echo $'create_avahi_service: avahi was not installed'
  38. exit 52925
  39. fi
  40. echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /etc/avahi/services/${service_name}.service
  41. echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /etc/avahi/services/${service_name}.service
  42. echo '<service-group>' >> /etc/avahi/services/${service_name}.service
  43. echo " <name replace-wildcards=\"yes\">%h ${service_type}</name>" >> /etc/avahi/services/${service_name}.service
  44. echo ' <service>' >> /etc/avahi/services/${service_name}.service
  45. echo " <type>_${service_type}._${service_protocol}</type>" >> /etc/avahi/services/${service_name}.service
  46. echo " <port>${service_port}</port>" >> /etc/avahi/services/${service_name}.service
  47. if [ "$service_description" ]; then
  48. echo " <txt-record>$description</txt-record>" >> /tmp/zeronet-blog.service
  49. fi
  50. echo ' </service>' >> /etc/avahi/services/${service_name}.service
  51. echo '</service-group>' >> /etc/avahi/services/${service_name}.service
  52. }
  53. function configure_avahi {
  54. if grep -Fxq "configure_avahi" $COMPLETION_FILE; then
  55. return
  56. fi
  57. # only enable avahi if we're doing mesh networking
  58. if [[ $ENABLE_BABEL != "yes" && $ENABLE_BATMAN != "yes" && $ENABLE_CJDNS != "yes" ]]; then
  59. return
  60. fi
  61. ${PROJECT_NAME}-mesh-install -f avahi
  62. if [ ! "$?" = "0" ]; then
  63. echo $'Failed to install avahi'
  64. exit 68442
  65. fi
  66. if [ $DEFAULT_DOMAIN_NAME ]; then
  67. sed -i "s|#host-name=.*|host-name=$DEFAULT_DOMAIN_NAME|g" /etc/avahi/avahi-daemon.conf
  68. sed -i "s|host-name=.*|host-name=$DEFAULT_DOMAIN_NAME|g" /etc/avahi/avahi-daemon.conf
  69. else
  70. decarray=( 1 2 3 4 5 6 7 8 9 0 )
  71. PEER_ID=${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}
  72. sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf
  73. sed -i "s|host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf
  74. fi
  75. echo 'configure_avahi' >> $COMPLETION_FILE
  76. }
  77. # NOTE: deliberately there is no "exit 0"