From f09bb35ecf47cb01b36f86c7be6d18b0e7fc4f45 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 7 Sep 2016 22:21:42 +0100 Subject: [PATCH] Fix avahi service description path --- src/freedombone-utils-avahi | 158 ++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/freedombone-utils-avahi b/src/freedombone-utils-avahi index e707562c..3618431c 100755 --- a/src/freedombone-utils-avahi +++ b/src/freedombone-utils-avahi @@ -29,101 +29,101 @@ # along with this program. If not, see . function create_avahi_service { - service_name=$1 - service_type=$2 - service_protocol=$3 - service_port=$4 - service_description="$5" + service_name=$1 + service_type=$2 + service_protocol=$3 + service_port=$4 + service_description="$5" - if [ ! -d /etc/avahi ]; then - echo $'create_avahi_service: avahi was not installed' - exit 52925 - fi + if [ ! -d /etc/avahi ]; then + echo $'create_avahi_service: avahi was not installed' + exit 52925 + fi - echo '' > /etc/avahi/services/${service_name}.service - echo '' >> /etc/avahi/services/${service_name}.service - echo '' >> /etc/avahi/services/${service_name}.service - echo " %h ${service_type}" >> /etc/avahi/services/${service_name}.service - echo ' ' >> /etc/avahi/services/${service_name}.service - echo " _${service_type}._${service_protocol}" >> /etc/avahi/services/${service_name}.service - echo " ${service_port}" >> /etc/avahi/services/${service_name}.service - if [ "$service_description" ]; then - echo " $service_description" >> /tmp/zeronet-blog.service - fi - echo ' ' >> /etc/avahi/services/${service_name}.service - echo '' >> /etc/avahi/services/${service_name}.service + echo '' > /etc/avahi/services/${service_name}.service + echo '' >> /etc/avahi/services/${service_name}.service + echo '' >> /etc/avahi/services/${service_name}.service + echo " %h ${service_type}" >> /etc/avahi/services/${service_name}.service + echo ' ' >> /etc/avahi/services/${service_name}.service + echo " _${service_type}._${service_protocol}" >> /etc/avahi/services/${service_name}.service + echo " ${service_port}" >> /etc/avahi/services/${service_name}.service + if [ "$service_description" ]; then + echo " $service_description" >> /etc/avahi/services/${service_name}.service + fi + echo ' ' >> /etc/avahi/services/${service_name}.service + echo '' >> /etc/avahi/services/${service_name}.service } function mesh_avahi { - chroot "$rootdir" apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd + chroot "$rootdir" apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd - decarray=( 1 2 3 4 5 6 7 8 9 0 ) - 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]} - sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf + decarray=( 1 2 3 4 5 6 7 8 9 0 ) + 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]} + sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf - if [ ! -d $rootdir/etc/avahi/services ]; then - mkdir -p $rootdir/etc/avahi/services - fi + if [ ! -d $rootdir/etc/avahi/services ]; then + mkdir -p $rootdir/etc/avahi/services + fi - # remove an avahi service which isn't used - if [ -f $rootdir/etc/avahi/services/udisks.service ]; then - rm $rootdir/etc/avahi/services/udisks.service - fi + # remove an avahi service which isn't used + if [ -f $rootdir/etc/avahi/services/udisks.service ]; then + rm $rootdir/etc/avahi/services/udisks.service + fi - # Add an ssh service - echo '' > $rootdir/etc/avahi/services/ssh.service - echo '' >> $rootdir/etc/avahi/services/ssh.service - echo '' >> $rootdir/etc/avahi/services/ssh.service - echo ' %h SSH' >> $rootdir/etc/avahi/services/ssh.service - echo ' ' >> $rootdir/etc/avahi/services/ssh.service - echo ' _ssh._tcp' >> $rootdir/etc/avahi/services/ssh.service - echo " $SSH_PORT" >> $rootdir/etc/avahi/services/ssh.service - echo ' ' >> $rootdir/etc/avahi/services/ssh.service - echo '' >> $rootdir/etc/avahi/services/ssh.service + # Add an ssh service + echo '' > $rootdir/etc/avahi/services/ssh.service + echo '' >> $rootdir/etc/avahi/services/ssh.service + echo '' >> $rootdir/etc/avahi/services/ssh.service + echo ' %h SSH' >> $rootdir/etc/avahi/services/ssh.service + echo ' ' >> $rootdir/etc/avahi/services/ssh.service + echo ' _ssh._tcp' >> $rootdir/etc/avahi/services/ssh.service + echo " $SSH_PORT" >> $rootdir/etc/avahi/services/ssh.service + echo ' ' >> $rootdir/etc/avahi/services/ssh.service + echo '' >> $rootdir/etc/avahi/services/ssh.service - # keep the daemon running - WATCHDOG_SCRIPT_NAME="keepon" - echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo ' systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo ' echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo ' echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME - chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + # keep the daemon running + WATCHDOG_SCRIPT_NAME="keepon" + echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo ' systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo ' echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo ' echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME + chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME } function install_avahi { - if [ $INSTALLING_MESH ]; then - mesh_avahi - return - fi - if grep -Fxq "install_avahi" $COMPLETION_FILE; then - return - fi - # only enable avahi if we're doing mesh networking - if [[ $ENABLE_BABEL != "yes" && $ENABLE_BATMAN != "yes" && $ENABLE_CJDNS != "yes" ]]; then - return - fi + if [ $INSTALLING_MESH ]; then + mesh_avahi + return + fi + if grep -Fxq "install_avahi" $COMPLETION_FILE; then + return + fi + # only enable avahi if we're doing mesh networking + if [[ $ENABLE_BABEL != "yes" && $ENABLE_BATMAN != "yes" && $ENABLE_CJDNS != "yes" ]]; then + return + fi - ${PROJECT_NAME}-mesh-install -f avahi - if [ ! "$?" = "0" ]; then - echo $'Failed to install avahi' - exit 68442 - fi + ${PROJECT_NAME}-mesh-install -f avahi + if [ ! "$?" = "0" ]; then + echo $'Failed to install avahi' + exit 68442 + fi - if [ $DEFAULT_DOMAIN_NAME ]; then - sed -i "s|#host-name=.*|host-name=$DEFAULT_DOMAIN_NAME|g" /etc/avahi/avahi-daemon.conf - sed -i "s|host-name=.*|host-name=$DEFAULT_DOMAIN_NAME|g" /etc/avahi/avahi-daemon.conf - else - decarray=( 1 2 3 4 5 6 7 8 9 0 ) - 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]} - sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf - sed -i "s|host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf - fi + if [ $DEFAULT_DOMAIN_NAME ]; then + sed -i "s|#host-name=.*|host-name=$DEFAULT_DOMAIN_NAME|g" /etc/avahi/avahi-daemon.conf + sed -i "s|host-name=.*|host-name=$DEFAULT_DOMAIN_NAME|g" /etc/avahi/avahi-daemon.conf + else + decarray=( 1 2 3 4 5 6 7 8 9 0 ) + 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]} + sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf + sed -i "s|host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf + fi - echo 'install_avahi' >> $COMPLETION_FILE + echo 'install_avahi' >> $COMPLETION_FILE } # NOTE: deliberately there is no "exit 0"