diff --git a/Makefile.am b/Makefile.am index 2da0f9d..9ea4094 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,3 +21,8 @@ bin_PROGRAMS = time_daemon time_daemon_SOURCES = time_daemon.c time_service_v01.c time_daemon_LDADD = $(requiredlibs) time_daemon_LDFLAGS = -lpthread @GLIB_LIBS@ + +# Systemd service file installation +if HAVE_SYSTEMD +systemdsystemunit_DATA = time-daemon.service +endif diff --git a/build_script.sh b/build_script.sh index 23fc85f..7a92f12 100755 --- a/build_script.sh +++ b/build_script.sh @@ -50,7 +50,12 @@ echo "Running configure.." echo "Running make.." make || { echo "make failed"; exit 1; } -make install || { echo "make install failed"; exit 1; } +# Use sudo only if not running as root +if [ "$(id -u)" -eq 0 ]; then + make install || { echo "make install failed"; exit 1; } +else + sudo make install || { echo "make install failed"; exit 1; } +fi FILES_TO_CLEAN=( aclocal.m4 configure ar-lib config.h config.h.in config.log config.status libtool diff --git a/configure.ac b/configure.ac index 1833f14..3f4806d 100644 --- a/configure.ac +++ b/configure.ac @@ -3,8 +3,8 @@ # Requires autoconf tool later than 2.61 AC_PREREQ(2.61) -# Initialize the qmi-framework package version 1.0.0 -AC_INIT([time-services],1.0.0) +# Initialize the qmi-framework package version 0.1.1 +AC_INIT([time-services],0.1.1) # Does not strictly follow GNU Coding standards AM_INIT_AUTOMAKE([foreign]) # Disables auto rebuilding of configure, Makefile.ins @@ -41,6 +41,26 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, AC_MSG_ERROR(GLib >= 2.16 i GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" AC_SUBST(GLIB_LIBS) +# Check for systemd +AC_ARG_WITH([systemdsystemunitdir], + [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])], + [], + [with_systemdsystemunitdir=auto]) + +AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [ + def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) + + AS_IF([test "x$def_systemdsystemunitdir" = "x"], + [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"], + [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]) + with_systemdsystemunitdir=no], + [with_systemdsystemunitdir="$def_systemdsystemunitdir"])]) + +AS_IF([test "x$with_systemdsystemunitdir" != "xno"], + [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]) + +AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"]) + AC_CONFIG_FILES([ \ Makefile \ ]) diff --git a/time-daemon.service b/time-daemon.service new file mode 100644 index 0000000..a21cbe2 --- /dev/null +++ b/time-daemon.service @@ -0,0 +1,15 @@ +[Unit] +Description=Time Services Daemon + +[Service] +Type=simple +ExecStart=/usr/bin/time_daemon +Restart=on-failure +StateDirectory=time + +# Device access for RTC (read-only) +DeviceAllow=/dev/rtc0 r +DevicePolicy=closed + +[Install] +WantedBy=multi-user.target