This commit is contained in:
2026-03-15 04:54:51 +01:00
parent 0fb8fe5a66
commit 7ac487f640
81 changed files with 3867 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
POSTINSTALL_MDNS_AVAHI_ENABLE="yes"
POSTINSTALL_MDNS_AVAHI_PUBLISH_WORKSTATION="yes"
POSTINSTALL_MDNS_AVAHI_CONFIG_FILE="/etc/avahi/avahi-daemon.conf"
POSTINSTALL_MDNS_AVAHI_SETTINGS_FILE="config/mdns-avahi.yaml"

View File

@@ -0,0 +1,4 @@
MODULE_ID="network/mdns-avahi"
MODULE_NAME="Publication mDNS Avahi"
MODULE_CATEGORY="network"
MODULE_DESCRIPTION="Installe et configure Avahi pour publier la machine sur le reseau local"

View File

@@ -0,0 +1,104 @@
#!/usr/bin/env bash
MODULE_MDNS_AVAHI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODULE_MDNS_AVAHI_PROJECT_ROOT="$(cd "$MODULE_MDNS_AVAHI_DIR/../../.." && pwd)"
# shellcheck source=lib/package.sh
source "$MODULE_MDNS_AVAHI_PROJECT_ROOT/lib/package.sh"
# shellcheck source=modules/network/mdns-avahi/config.sh
source "$MODULE_MDNS_AVAHI_DIR/config.sh"
# shellcheck source=modules/network/mdns-avahi/metadata.conf
source "$MODULE_MDNS_AVAHI_DIR/metadata.conf"
module_mdns_avahi_metadata() {
printf '%s|%s|%s\n' "$MODULE_ID" "$MODULE_NAME" "$MODULE_DESCRIPTION"
}
module_mdns_avahi_config_path() {
printf '%s/%s\n' "$MODULE_MDNS_AVAHI_PROJECT_ROOT" "$POSTINSTALL_MDNS_AVAHI_SETTINGS_FILE"
}
module_mdns_avahi_settings() {
local config_path=""
local enable_value="$POSTINSTALL_MDNS_AVAHI_ENABLE"
local publish_workstation="$POSTINSTALL_MDNS_AVAHI_PUBLISH_WORKSTATION"
config_path="$(module_mdns_avahi_config_path)"
if [[ -f "$config_path" ]]; then
while IFS='=' read -r key value; do
case "$key" in
enable) enable_value="$value" ;;
publish_workstation) publish_workstation="$value" ;;
esac
done < <(
awk '
/^[[:space:]]*enable:/ { print "enable=" $2 }
/^[[:space:]]*publish_workstation:/ { print "publish_workstation=" $2 }
' "$config_path"
)
fi
printf '%s|%s\n' "$enable_value" "$publish_workstation"
}
module_mdns_avahi_require_package() {
if package_is_installed "avahi-daemon"; then
ui_info "Paquet avahi-daemon deja installe"
return 0
fi
ui_warn "Paquet avahi-daemon absent, installation en cours"
package_refresh_indexes
package_install avahi-daemon avahi-utils libnss-mdns
log_info "Paquets Avahi installes"
ui_success "Paquets Avahi installes"
}
module_mdns_avahi_write_config() {
local enable_value="${1:-$POSTINSTALL_MDNS_AVAHI_ENABLE}"
local publish_workstation="${2:-$POSTINSTALL_MDNS_AVAHI_PUBLISH_WORKSTATION}"
local disable_value="yes"
if [[ "$enable_value" == "yes" ]]; then
disable_value="no"
fi
cp "$POSTINSTALL_MDNS_AVAHI_CONFIG_FILE" "${POSTINSTALL_MDNS_AVAHI_CONFIG_FILE}.bak.postinstall" 2>/dev/null || true
sed -i \
-e "s/^#*disable-publishing=.*/disable-publishing=$disable_value/" \
-e "s/^#*publish-workstation=.*/publish-workstation=$publish_workstation/" \
"$POSTINSTALL_MDNS_AVAHI_CONFIG_FILE"
}
module_mdns_avahi_check() {
package_is_installed "avahi-daemon" || return 1
systemctl is-active --quiet avahi-daemon || return 1
grep -Eq '^disable-publishing=no$' "$POSTINSTALL_MDNS_AVAHI_CONFIG_FILE" || return 1
}
module_mdns_avahi_install() {
local settings=""
local enable_value=""
local publish_workstation=""
settings="$(module_mdns_avahi_settings)"
IFS='|' read -r enable_value publish_workstation <<< "$settings"
module_mdns_avahi_require_package || return 1
module_mdns_avahi_write_config "$enable_value" "$publish_workstation"
systemctl enable --now avahi-daemon
systemctl restart avahi-daemon
log_info "Avahi configure, publication=$enable_value workstation=$publish_workstation"
ui_success "Avahi configure"
}
module_mdns_avahi_test() {
package_is_installed "avahi-daemon" || return 1
test -f "$POSTINSTALL_MDNS_AVAHI_CONFIG_FILE" || return 1
test -f "$(module_mdns_avahi_config_path)" || return 1
systemctl is-active --quiet avahi-daemon || return 1
grep -Eq '^disable-publishing=(no|yes)$' "$POSTINSTALL_MDNS_AVAHI_CONFIG_FILE" || return 1
}

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
MODULE_MDNS_AVAHI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$MODULE_MDNS_AVAHI_DIR/../../.." && pwd)"
# shellcheck source=lib/ui.sh
source "$PROJECT_ROOT/lib/ui.sh"
# shellcheck source=lib/log.sh
source "$PROJECT_ROOT/lib/log.sh"
# shellcheck source=lib/package.sh
source "$PROJECT_ROOT/lib/package.sh"
# shellcheck source=core/runtime.sh
source "$PROJECT_ROOT/core/runtime.sh"
# shellcheck source=modules/network/mdns-avahi/module.sh
source "$MODULE_MDNS_AVAHI_DIR/module.sh"
runtime_init "$PROJECT_ROOT"
log_init
if ! package_is_installed avahi-daemon; then
printf 'mdns-avahi test SKIPPED: avahi-daemon not installed\n'
exit 0
fi
if ! test -f "$PROJECT_ROOT/config/mdns-avahi.yaml"; then
printf 'mdns-avahi test FAILED: missing repository config\n' >&2
exit 1
fi
if ! systemctl status avahi-daemon >/dev/null 2>&1; then
printf 'mdns-avahi test SKIPPED: systemd status unavailable in this environment\n'
exit 0
fi
if module_mdns_avahi_test; then
printf 'mdns-avahi test OK\n'
else
printf 'mdns-avahi test FAILED\n' >&2
exit 1
fi