Skip to content

Commit

Permalink
configure.ac: generate scripts/systemd/nut-common.in based on current…
Browse files Browse the repository at this point in the history
… config
  • Loading branch information
jimklimov committed May 28, 2021
1 parent e06bc6f commit 6595807
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
4 changes: 4 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ then
fi
fi

if [ ! -e scripts/systemd/nut-common.tmpfiles.in ]; then
echo '# autoconf requires this file exists before generating configure script' > scripts/systemd/nut-common.tmpfiles.in
fi

# now we can safely call autoreconf
echo "Calling autoreconf..."
autoreconf -iv && {
Expand Down
45 changes: 41 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,27 @@ if test -n "${systemdsystemunitdir}"; then
esac
fi

dnl Note: if (systemd-)tmpfiles tech is present, it can be useful even for
dnl daemons starting not as systemd units
AC_MSG_CHECKING([whether to install systemd tmpfiles files (${systemdtmpfilesdir})])
AC_ARG_WITH([systemdtmpfilesdir],
AS_HELP_STRING([--with-systemdtmpfilesdir=DIR], [Directory for systemd tmpfiles scripts (auto)]),
[systemdtmpfilesdir=${withval}])
if test -n "${systemdsystemunitdir}"; then
case "${systemdtmpfilesdir}" in
[systemdshutdowndir=${withval}])
case "${systemdtmpfilesdir}" in
yes|auto|"")
systemdtmpfilesdir=`$PKG_CONFIG --variable=tmpfilesdir systemd`
esac
;;
no)
systemdtmpfilesdir=""
;;
*)
systemdtmpfilesdir="${withval}"
;;
esac
if test -n "${systemdtmpfilesdir}"; then
AC_MSG_RESULT(using ${systemdtmpfilesdir})
else
AC_MSG_RESULT(no)
fi

dnl
Expand Down Expand Up @@ -2026,6 +2039,30 @@ AC_MSG_RESULT(["${nut_enable_Werror}"])
dnl Finally restore warnings settings that the caller might have provided in CFLAGS etc
NUT_POP_WARNINGS

dnl Due to possibly repetitive content, generate unique settings:
AS_IF([test -n "$systemdtmpfilesdir"],
[cat > scripts/systemd/nut-common.tmpfiles.in << EOF
# State file (e.g. upsd to driver) and pidfile location for NUT:
d @STATEPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - -
X @STATEPATH@/nut
EOF
AS_IF([test "$STATEPATH" != "$PIDPATH"],
[cat >> scripts/systemd/nut-common.tmpfiles.in << EOF
d @PIDPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - -
X @PIDPATH@/nut
EOF])
AS_IF([test -n "$ALTPIDPATH" && test "$STATEPATH" != "$ALTPIDPATH" && test "$PIDPATH" != "$ALTPIDPATH"],
[cat >> scripts/systemd/nut-common.tmpfiles.in << EOF
d @ALTPIDPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - -
X @ALTPIDPATH@/nut
EOF])
AS_IF([test -n "$ALTSTATEPATH" && test "$STATEPATH" != "$ALTSTATEPATH" && test "$ALTSTATEPATH" != "$ALTPIDPATH" && test "$PIDPATH" != "$ALTSTATEPATH"],
[cat >> scripts/systemd/nut-common.tmpfiles.in << EOF
d @ALTSTATEPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - -
X @ALTSTATEPATH@/nut
EOF])
])

AC_OUTPUT([
clients/Makefile
common/Makefile
Expand Down
2 changes: 2 additions & 0 deletions scripts/systemd/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Note: nut-common.tmpfiles.in is also generated, by configure script
/nut-common.tmpfiles.in
/nut-common.tmpfiles
/nut-driver.service
/[email protected]
Expand Down
7 changes: 0 additions & 7 deletions scripts/systemd/nut-common.tmpfiles.in

This file was deleted.

0 comments on commit 6595807

Please sign in to comment.