#!/bin/sh set -e # summary of how this script can be called: # # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package create_config_from_template() { local config="$1" local template="$2" local lastver="$3" if [ "$4" != "--" ]; then echo "create_config_from_template called with the wrong number of arguments" >&2 return 1 fi for _ in $(seq 1 4); do shift done if [ -n "$2" ] && dpkg --compare-versions -- "$2" gt "$lastver"; then # The package is already configured, and the version that's been # configured is new enough to contain the config file if [ -e "$config.dpkg-backup" ]; then # The package had been configured in the past and has # subsequently been removed without purging, so a backup of # the config file is still present on the disk. Restore it mv -f "$config.dpkg-backup" "$config" return 0 else # We're doing a regular upgrade. Don't change anything return 0 fi else # We're either installing from scratch, or upgrading from a version # that didn't have the config file yet. Make a copy of the template # in the appropriate location and with the expected permissions install -o root -g root -m 0600 "$template" "$config" return 0 fi } finish_conffile_transfer() { local conffile="$1" local lastver="$2" local pkgfrom="$3" local pkgto="$4" if [ "$5" != "--" ]; then echo "finish_conffile_transfer called with the wrong number of arguments" >&2 return 1 fi for _ in $(seq 1 5); do shift done # If we're upgrading rather than installing from scratch, we can assume # the transfer must have happened at some point in the past and stop here if [ -n "$2" ]; then return 0 fi if [ -e "$conffile.dpkg-transfer" ]; then # Complete the process started in $pkgfrom's preinst by restoring the # version of the conffile containing local modifications echo "Finishing transfer of config file $conffile (from $pkgfrom to $pkgto) ..." mv -f "$conffile.dpkg-transfer" "$conffile" return 0 fi if [ -e "$conffile.dpkg-disappear" ]; then # The conffile had been deleted by the admin, so let's return to # that state rm -f "$conffile" "$conffile.dpkg-disappear" return 0 fi } systemd_daemon_reload() { if [ -z "${DPKG_ROOT:-}" ] && [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true fi } systemd_unit_restart_if_active() { if [ -z "${DPKG_ROOT:-}" ] && [ -d /run/systemd/system ]; then for unit in "$@"; do if systemctl is-active -q "$unit"; then deb-systemd-invoke restart "$unit" >/dev/null || true fi done fi } case "$1" in configure) create_config_from_template \ "/etc/libvirt/qemu/networks/default.xml" \ "/usr/share/libvirt/networks/default.xml" \ "6.9.0-2~" \ -- \ "$@" finish_conffile_transfer \ "/etc/libvirt/qemu/networks/default.xml" \ "6.9.0-2~" \ "libvirt-daemon-system" \ "libvirt-daemon-config-network" \ -- \ "$@" # Since we might have changed the on-disk configuration for some # services, restart them so that they can pick up the new settings systemd_daemon_reload systemd_unit_restart_if_active libvirtd.service ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0