5 if [ "%{name}" != "%\{name\}" ]; then
6 # Red Hat ("%{...}" is interpolated at package build time)
9 prefix="${RPM_INSTALL_PREFIX}"
12 script="$(basename "${0}")"
13 pkg="${script%.postinst}"
18 case "${pkgtype}-${1}" in
19 deb-configure | rpm-1)
20 dest_dir="/lib/systemd/system"
21 if ! [ -d "${dest_dir}" ]; then
25 # Find the unit file we need to install.
26 unit_file="${pkg}.service"
28 "${prefix}/share/doc/${pkg}" \
30 if [ -e "${dir}/${unit_file}" ]; then
35 if [ -z "${src_dir}" ]; then
36 echo >&2 "WARNING: postinst script did not find ${unit_file} anywhere."
40 # Install/update the unit file if necessary.
41 if [ "${src_dir}" != "${dest_dir}" ]; then
42 cp "${src_dir}/${unit_file}" "${dest_dir}/" || exit 0
45 # Enable service, and make sure systemd re-reads the unit
46 # file, in case we changed it.
47 if [ -e /run/systemd/system ]; then
48 systemctl daemon-reload || true
49 eval "$(systemctl -p UnitFileState show "${pkg}")"
50 case "${UnitFileState}" in
52 # Failing to enable or start the service is not a
53 # package error, so don't let errors here
55 systemctl enable "${pkg}" || true
56 systemctl start "${pkg}" || true
59 systemctl reload-or-try-restart "${pkg}" || true