Skip to content

Commit

Permalink
Merge e8cbadc into 9f184a6
Browse files Browse the repository at this point in the history
  • Loading branch information
kubiko committed May 7, 2024
2 parents 9f184a6 + e8cbadc commit 9b7fa85
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ missing
py-compile
stamp-h1
test-driver
=======
parts
stage
prime
*.snap
snap/.snapcraft
!snap/hooks/*
18 changes: 18 additions & 0 deletions glue/usr/bin/avahi-help
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# parse config file for supported settings keys
source "$SNAP/usr/bin/config" &>/dev/null
echo -e "avahi snap help"
echo -e "avahi supports settings keys:"
echo -e "values can be changed by calling\n$ snap set avahi avahi-daemon-conf.<key name>='<key value>'"
echo -e "\te.g. $ snap set avahi avahi-daemon-conf.host-name=<host name>"

echo -e "Curretly defined keys:"
for index in ${!DEFINED_K[*]}; do
echo -e "\t${DEFINED_K[${index}]}=${DEFINED_V[${index}]}"
done

echo -e "Keys with no set value:"
for index in ${!UNDEFINED_K[*]}; do
echo -e "\t${UNDEFINED_K[${index}]}, proposed value '${UNDEFINED_V[${index}]}'"
done
14 changes: 14 additions & 0 deletions glue/usr/bin/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# parse avahi config and store keys/values to the separate arrays
# all commented out keys
LUNDEFINED_K="$(grep -E '^#.*=' $SNAP_COMMON/etc/avahi/avahi-daemon.conf | awk -F'[=]' '{print $1}' | tr '\n' ' ' | tr -d '#')"
LUNDEFINED_V="$(grep -E '^#.*=' $SNAP_COMMON/etc/avahi/avahi-daemon.conf | awk -F'[=]' '{print $2}' | tr '\n' ' ')"
UNDEFINED_K="($LUNDEFINED_K)"
UNDEFINED_V="($LUNDEFINED_V)"

# all set keys
LDEFINED_K="$(grep '^[a-zA-Z].*=' $SNAP_COMMON/etc/avahi/avahi-daemon.conf | awk -F'[=]' '{print $1}' | tr '\n' ' ')"
LDEFINED_V="$(grep '^[a-zA-Z].*=' $SNAP_COMMON/etc/avahi/avahi-daemon.conf | awk -F'[=]' '{print $2}' | tr '\n' ' ')"
DEFINED_K="($LDEFINED_K)"
DEFINED_V="($LDEFINED_V)"
Binary file added snap/gui/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

hook_name="$(basename "'"'"${0}"'")'
logger "avahi.hook.${hook_name}: entering the hook" || true
config_file="avahi-daemon.conf"
# work on temp file, before commiting changes back, to reduce number of writes
cp "${SNAP_COMMON}/etc/avahi/${config_file}" "/tmp/"
process_line() {
# each line starts with key name and ends with the value
local key="${1}"
local value="${2}"
sed -i 's/.*'"${key}"'.*/'"${key}"'='"${value}"'/g' /tmp/${config_file}
}
# read key value pairs from snap config line by line
while read line
do
process_line "$line"
done < <( snapctl get -d avahi-daemon-conf | jq -r '.[] | to_entries[] | "\(.key) \(.value)"')
# we are done, write back config file, only if it has changed
if ! cmp "/tmp/${config_file}" "${SNAP_COMMON}/etc/avahi/${config_file}"; then
logger "avahi.${hook_name}: ${config_file} changed, updating it...." || true
mv "/tmp/${config_file}" "${SNAP_COMMON}/etc/avahi/"
snapctl restart "${SNAP_INSTANCE_NAME}.daemon"
fi
# no need to restart avahi-daemon, it tracks the changes in the config file
logger "avahi.hook.${hook_name}: hook finished successfully" || true
12 changes: 12 additions & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

hook_name="$(basename "'"'"${0}"'")'
logger "avahi.hook.${hook_name}: entering the hook" || true
mkdir -p "${SNAP_COMMON}/etc" "${SNAP_COMMON}/usr/share"
[ ! -d "${SNAP_COMMON}/etc/avahi/services" ] && cp -r "${SNAP}/etc/avahi/*" "${SNAP_COMMON}/etc/avahi"
[ ! -d "${SNAP_COMMON}/usr/share/dbus-1" ] && cp -r "${SNAP}/usr/share/dbus-1" "${SNAP_COMMON}/usr/share"
[ ! -e "${SNAP_COMMON}/usr/share/avahi/avahi-service.dtd" ] && cp -r "${SNAP}/usr/share/avahi/*" "${SNAP_COMMON}/usr/share/avahi"
logger "avahi.hook.${hook_name}: hook finished successfully" || true
12 changes: 12 additions & 0 deletions snap/hooks/post-refresh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

hook_name="$(basename "'"'"${0}"'")'
logger "avahi.hook.${hook_name}: entering the hook" || true
mkdir -p "${SNAP_COMMON}/etc" "${SNAP_COMMON}/usr/share"
[ ! -d "${SNAP_COMMON}/etc/avahi/services" ] && cp -r "${SNAP}/etc/avahi/*" "${SNAP_COMMON}/etc/avahi"
[ ! -d "${SNAP_COMMON}/usr/share/dbus-1" ] && cp -r "${SNAP}/usr/share/dbus-1" "${SNAP_COMMON}/usr/share"
[ ! -e "${SNAP_COMMON}/usr/share/avahi/avahi-service.dtd" ] && cp -r "${SNAP}/usr/share/avahi/*" "${SNAP_COMMON}/usr/share/avahi"
logger "avahi.hook.${hook_name}: hook finished successfully" || true
176 changes: 176 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
name: avahi
summary: avahi-daemon
description: |
avahi service daemon
Avahi is a free, LGPL implementation of DNS Service Discovery (DNS-SD RFC 6763) over Multicast DNS (mDNS RFC 6762),
commonly known as and compatible with Apple Bonjour primarily targetting Linux.
Copyright 2004-2015 by the Avahi developers.
base: core20
confinement: strict
grade: stable
adopt-info: avahi

environment:
PATH: $SNAP/usr/bin:$PATH
LD_LIBRARY_PATH: $SNAP/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}:$SNAP/usr/lib

architectures:
- build-on: armhf
- build-on: arm64
- build-on: amd64
- build-on: riscv64

# expose services folder for other snaps
slots:
services-content:
interface: content
content: avahi-services
write:
- $SNAP_COMMON/etc/avahi/services

apps:
daemon:
command: usr/sbin/avahi-daemon -f $SNAP_COMMON/etc/avahi/avahi-daemon.conf --no-drop-root --debug
daemon: simple
adapter: none
plugs:
- network
- network-bind
- network-control
slots:
- avahi-observe
- avahi-control

browse:
command: usr/bin/avahi-browse
adapter: none
plugs:
- network

publish:
command: usr/bin/avahi-publish
adapter: none
plugs:
- network

resolve:
command: usr/bin/avahi-resolve
adapter: none
plugs:
- network

set-host-name:
command: usr/bin/avahi-set-host-name
adapter: none
plugs:
- network

help:
command: usr/bin/avahi-help
adapter: none

parts:
avahi:
plugin: autotools
source: .
source-type: git
autotools-configure-parameters:
- --prefix=/usr
- --disable-qt3
- --disable-qt4
- --disable-qt5
- --disable-gtk
- --disable-gtk3
- --disable-gdbm
- --disable-python
- --disable-pygtk
- --disable-python-dbus
- --disable-mono
- --disable-monodoc
- --disable-manpages
- --disable-xmltoman
- --with-avahi-user=root
- --with-avahi-group=root
- --with-distro=debian
- --disable-gobject
- --sysconfdir=/var/snap/${SNAPCRAFT_PROJECT_NAME}/common/etc
- --datadir=/var/snap/${SNAPCRAFT_PROJECT_NAME}/common/usr/share
- --localstatedir=/var
stage-packages:
- libdaemon0
- libevent-2.1-7
override-pull: |
snapcraftctl pull
track="latest"
# depending on a channel in the snap store, build last release tag or master
# last stable tag
stable_tag=$(git tag --list | sed 's/v//g' | sort --version-sort | grep -v "rc" | tail -1)
latest_tag=$(git tag --list | sed 's/v//g' | sort --version-sort | tail -1)
if [ "${stable_tag}" != "${latest_tag}" ]; then
# last release candidate tag
release_candidate_tag=$(git tag --list | sed 's/v//g' | sort --version-sort | grep "rc" | tail -1)
fi
last_commited_version=$(git describe --abbrev=0 --tags)
candidata_version="$(snap info avahi | awk '$1 == "${track}/candidate:" { print $2 }')"
beta_version="$(snap info avahi | awk '$1 == "${track}/beta:" { print $2 }')"
# If there is release_candidate_tag, check if this version is also in the candate channel,
# if there is different version or channel is closed, build release candidate version
if [ -n "${release_candidate_tag}" ] && [ "${release_candidate_tag}" != "${candidata_version}" ] ; then
version="${release_candidate_tag}"
# if beta channel is closed or version is less than stable tag version, build last stable version
elif [ "^" = "${beta_version}" ] && $(dpkg --compare-versions "${beta_version}" "lt" "${stable_tag}" ); then
version="${latest_tag}"
fi
# if we have no version defined, we are building tip from master
if [ -n "${version}" ]; then
git checkout v${version}
else
version="$(git describe --tags | cut -c 2-)"
fi
snapcraftctl set-version "${version}"
override-build: |
snapcraftctl build
# add tag with txt record os=snappy
sed -i \
'/<\/service>/ i\ <txt-record>os=snappy</txt-record>' \
$SNAPCRAFT_PART_INSTALL/var/snap/${SNAPCRAFT_PROJECT_NAME}/common/etc/avahi/services/ssh.service
organize:
var/snap/${SNAPCRAFT_PROJECT_NAME}/common/etc: etc
var/snap/${SNAPCRAFT_PROJECT_NAME}/common/usr/share/dbus-1: usr/share/dbus-1
var/snap/${SNAPCRAFT_PROJECT_NAME}/common/usr/share/avahi: usr/share/avahi
stage:
- -lib
- -run
- -usr/include
- -usr/lib/*.a
- -usr/lib/avahi
- -var

# snap helper scripts
glue:
source: glue
plugin: dump
stage-packages:
- jq
- libjq1
- libnss-mdns
organize:
'lib/${CRAFT_ARCH_TRIPLET}*': usr/lib/${CRAFT_ARCH_TRIPLET}/
stage:
- usr
- -usr/share/doc
- -usr/share/man

build-packages:
- gettext
- intltool
- libdaemon-dev
- libdbus-1-dev
- libevent-dev
- libexpat1-dev
- libglib2.0-dev
- libsystemd-dev
- xmltoman

0 comments on commit 9b7fa85

Please sign in to comment.