-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
snap: hooks: add initial hook implementation
Signed-off-by: Ondrej Kubik <ondrej.kubik@canonical.com>
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -r 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |