diff --git a/CMakeLists.txt b/CMakeLists.txt index df765e1..c01c808 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,8 +89,10 @@ endif() if (UNIX AND NOT APPLE) option(WITH_SYSTEMD "Build with systemd Support" OFF) if (WITH_SYSTEMD) - configure_file(src/systemd/dtranslatebot.service.in "${dtranslatebot_BINARY_DIR}/systemd/dtranslatebot.service" @ONLY) - install(FILES "${dtranslatebot_BINARY_DIR}/systemd/dtranslatebot.service" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/systemd/system") + configure_file(src/systemd/dtranslatebot.service.in "${dtranslatebot_BINARY_DIR}/systemd/service/dtranslatebot.service" @ONLY) + configure_file(src/systemd/dtranslatebot.sysusersd.in "${dtranslatebot_BINARY_DIR}/systemd/sysusers.d/dtranslatebot.conf" @ONLY) + install(FILES "${dtranslatebot_BINARY_DIR}/systemd/service/dtranslatebot.service" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/systemd/system") + install(FILES "${dtranslatebot_BINARY_DIR}/systemd/sysusers.d/dtranslatebot.conf" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/sysusers.d") endif() endif() diff --git a/rpmspec/dtranslatebot.spec b/rpmspec/dtranslatebot.spec new file mode 100644 index 0000000..415611e --- /dev/null +++ b/rpmspec/dtranslatebot.spec @@ -0,0 +1,70 @@ +%global _lto_cflags %{?_lto_cflags} -ffat-lto-objects +%global dtb_cmake_args -DCMAKE_BUILD_TYPE=Release -DWITH_DPP_STATIC_BUNDLE=TRUE -DWITH_SYSTEMD=TRUE + +Name: dtranslatebot +Version: 0.2.0 +Release: 1%{?dist} +Summary: Discord Translation Bot +License: BSD-2-Clause +URL: https://github.com/Syping/%{name} +Source0: %{name}_%{version}.tar.gz +Source1: %{name}.sysusersd + +BuildRequires: cmake >= 3.16 +%if 0%{?rhel} && 0%{?rhel} < 9 +BuildRequires: gcc-toolset-9-annobin +BuildRequires: gcc-toolset-9-gcc-c++ +%else +BuildRequires: annobin +BuildRequires: gcc-c++ +%endif +%if 0%{?rhel} +BuildRequires: epel-rpm-macros-systemd +%endif +BuildRequires: systemd-rpm-macros +%{?systemd_requires} +%{?sysusers_requires_compat} + +%description +dtranslatebot is a Discord Bot which translate incoming Discord messages to Discord webhooks. + +%prep +%setup -q + +%build +%if 0%{?rhel} && 0%{?rhel} < 9 +source /opt/rh/gcc-toolset-9/enable +%endif +%cmake %{?dtb_cmake_args} +%if 0%{?cmake_build:1} +%cmake_build +%else +%make_build +%endif + +%install +%if 0%{?cmake_install:1} +%cmake_install +%else +%make_install +%endif +mkdir -p %{buildroot}%{_localstatedir}/lib/%{name} +install -p -D -m 0644 %{SOURCE1} %{buildroot}%{_sysusersdir}/%{name}.conf + +%pre +%sysusers_create_compat %{SOURCE1} + +%post +%systemd_post %{name}.service + +%preun +%systemd_preun %{name}.service + +%postun +%systemd_postun_with_restart %{name}.service + +%files +%{_bindir}/%{name} +%{_unitdir}/%{name}.service +%{_sysusersdir}/%{name}.conf +%dir %attr(0750,%{name},%{name}) %{_localstatedir}/lib/%{name} diff --git a/rpmspec/dtranslatebot.sysusersd b/rpmspec/dtranslatebot.sysusersd new file mode 100644 index 0000000..f181398 --- /dev/null +++ b/rpmspec/dtranslatebot.sysusersd @@ -0,0 +1,2 @@ +#Type Name ID GECOS Home directory Shell +u dtranslatebot - "Discord Translation Bot" /var/lib/translatebot - diff --git a/src/systemd/dtranslatebot.sysusersd.in b/src/systemd/dtranslatebot.sysusersd.in new file mode 100644 index 0000000..144004d --- /dev/null +++ b/src/systemd/dtranslatebot.sysusersd.in @@ -0,0 +1 @@ +u dtranslatebot - "Discord Translation Bot" "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/dtranslatebot" -