Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snap package enablement #204

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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/*
36 changes: 36 additions & 0 deletions glue/usr/bin/avahi-help
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

# parse config file for supported settings keys
# shellcheck disable=SC1091 # SC1091 is irrelevant, ${SNAP} is defined withing snap context
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
39 changes: 39 additions & 0 deletions glue/usr/bin/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

# 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' ' ')"
# shellcheck disable=SC2034 # SC2034 is irrelevant, UNDEFINED_K is used by calling script
# shellcheck disable=SC2206 # SC2206 is irrelevant, we want the words to split
UNDEFINED_K=(${LUNDEFINED_K})
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
# shellcheck disable=SC2034 # SC2034 is irrelevant, UNDEFINED_V is used by calling script
# shellcheck disable=SC2206 # SC2206 is irrelevant, we want the words to split
UNDEFINED_V=(${LUNDEFINED_V})
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

# 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' ' ')"
# shellcheck disable=SC2034 # SC2034 is irrelevant, DEFINED_K is used by calling script
# shellcheck disable=SC2206 # SC2206 is irrelevant, we want the words to split
DEFINED_K=(${LDEFINED_K})
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
# shellcheck disable=SC2034 # SC2034 is irrelevant, DEFINED_V is used by calling script
# shellcheck disable=SC2206 # SC2206 is irrelevant, we want the words to split
DEFINED_V=(${LDEFINED_V})
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Binary file added snap/gui/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

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 -r line
do
# shellcheck disable=SC2086 # SC2086 does not apply, we are passing multiple arguments
process_line ${line}
Fixed Show fixed Hide fixed
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
29 changes: 29 additions & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

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"
[ ! -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"

logger "avahi.hook.${hook_name}: hook finished successfully" || true
29 changes: 29 additions & 0 deletions snap/hooks/post-refresh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

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"
[ ! -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"

logger "avahi.hook.${hook_name}: hook finished successfully" || true
Loading