diff --git a/.build/RPM/rpxy.spec b/.build/RPM/rpxy.spec index 5f664c9..16e3ec1 100644 --- a/.build/RPM/rpxy.spec +++ b/.build/RPM/rpxy.spec @@ -13,74 +13,66 @@ Requires: systemd %description This rpm installs rpxy into /usr/bin and sets up a systemd service. +# Prep section: Unpack the source %prep %autosetup +# Install section: Copy files to their destinations %install rm -rf %{buildroot} -# Copy binary -mkdir -p %{buildroot}%{_bindir} -cp rpxy %{buildroot}%{_bindir}/ -# Create systemd service -mkdir -p %{buildroot}%{_sysconfdir}/systemd/system -cp rpxy.service %{buildroot}%{_sysconfdir}/systemd/system/ -# Create config directory -mkdir -p %{buildroot}%{_sysconfdir}/rpxy/acme_registry -cp config.toml %{buildroot}%{_sysconfdir}/rpxy/ -# Copy documentation -mkdir -p %{buildroot}%{_docdir}/rpxy -cp LICENSE %{buildroot}%{_docdir}/rpxy/ -cp README.md %{buildroot}%{_docdir}/rpxy/ +# Create necessary directories +mkdir -p %{buildroot}%{_bindir} +mkdir -p %{buildroot}%{_sysconfdir}/systemd/system +mkdir -p %{buildroot}%{_sysconfdir}/rpxy/acme_registry +mkdir -p %{buildroot}%{_docdir}/rpxy + +# Copy files +cp rpxy %{buildroot}%{_bindir}/ +cp rpxy.service %{buildroot}%{_sysconfdir}/systemd/system/ +cp config.toml %{buildroot}%{_sysconfdir}/rpxy/ +cp LICENSE README.md %{buildroot}%{_docdir}/rpxy/ + +# Clean section: Remove buildroot %clean rm -rf %{buildroot} +# Pre-install script %pre # Create the rpxy user if it does not exist -if ! id rpxy >/dev/null 2>&1; then - /usr/sbin/useradd -r -s /bin/false -d / -c "rpxy system user" rpxy +if ! getent passwd rpxy >/dev/null; then + useradd -r -s /sbin/nologin -d / -c "rpxy system user" rpxy fi +# Post-install script %post # Set ownership of config file to rpxy user chown -R rpxy:rpxy %{_sysconfdir}/rpxy # Reload systemd, enable and start rpxy service -systemctl daemon-reload -systemctl enable rpxy -if [ $1 -eq 1 ]; then - systemctl start rpxy -fi +%systemd_post rpxy.service +# Pre-uninstall script %preun -# Stop the service on uninstall or upgrade -if [ $1 -eq 0 ]; then - systemctl stop rpxy -fi +%systemd_preun rpxy.service +# Post-uninstall script %postun -# On uninstall, disable the service and reload systemd +%systemd_postun_with_restart rpxy.service + +# Only remove user and config on full uninstall if [ $1 -eq 0 ]; then - systemctl disable rpxy - systemctl daemon-reload -fi - -# Remove rpxy user only if package is being completely removed (not upgraded) -if [ $1 -eq 0 ]; then - # Check if the rpxy user exists before attempting to delete - if id rpxy >/dev/null 2>&1; then - /usr/sbin/userdel rpxy - fi - - # Remove the configuration directory if it exists and is empty - if [ -d %{_sysconfdir}/rpxy ]; then - rm -rf %{_sysconfdir}/rpxy - fi + # Remove rpxy user + userdel rpxy + + # Remove the configuration directory if it exists + [ -d %{_sysconfdir}/rpxy ] && rm -rf %{_sysconfdir}/rpxy fi +# Files section: List all files included in the package %files %license %{_docdir}/rpxy/LICENSE %doc %{_docdir}/rpxy/README.md %{_sysconfdir}/systemd/system/rpxy.service -%attr(-, rpxy, rpxy) %{_bindir}/rpxy -%attr(-, rpxy, rpxy) %config(noreplace) %{_sysconfdir}/rpxy/config.toml +%attr(755, rpxy, rpxy) %{_bindir}/rpxy +%attr(644, rpxy, rpxy) %config(noreplace) %{_sysconfdir}/rpxy/config.toml