From 3505aad59297bf2809f8478eabcc48cf1eb23930 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Tue, 12 Apr 2022 23:40:03 +0200 Subject: [PATCH] Productionize - Remove superfluous comments - Adjust permissions - Improve post-hooks Signed-off-by: Georg Pfuetzenreuter --- ergo.spec | 86 +++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/ergo.spec b/ergo.spec index 5d6961e..2de19e3 100644 --- a/ergo.spec +++ b/ergo.spec @@ -19,7 +19,6 @@ %define __arch_install_post export NO_BRP_STRIP_DEBUG=true %global provider_prefix github.com/ergochat/ergo %global import_path %{provider_prefix} -# Make go-rpm-macros happy! %if 0%{?fedora} %global goipath github.com/ergochat/ergo %global debug_package %{nil} @@ -30,7 +29,7 @@ Release: 0 Summary: IRCv3 Server License: MIT Group: Productivity/Networking/IRC -URL: https://oragono.io +URL: https://ergo.chat/ #Original source: #https://github.com/ergochat/ergo/tree/master #Modified source (custom ircd.yaml configuration and systemd unit file): @@ -38,7 +37,7 @@ Source0: %{name}-%{version}.tar.gz Source1: vendor.tar.gz Patch0: default.yaml.patch Patch1: ergo.service.patch -# Dependencies for openSUSE: +# Dependencies for openSUSE and SLES: %if 0%{?suse_version} BuildRequires: fdupes BuildRequires: go >= 1.18 @@ -58,36 +57,30 @@ BuildRequires: systemd-rpm-macros Requires(pre): %{_bindir}/getent Requires(pre): %{_sbindir}/useradd %endif -# Okay openSUSE, let's stretch first! %if 0%{?suse_version} %{go_nostrip} %{go_provides} %endif -# Come on Fedora, you go along! %if 0%{?fedora} %gopkg %endif %description Ergo is a modern IRC server written in Go. -#A pretty cool one, that is! %pre -# Introducing Ms. Oragono! -%{_bindir}/getent group ergo || %{_sbindir}/groupadd -r ergo -%{_bindir}/getent passwd ergo || %{_sbindir}/useradd -r -g ergo -d %{_sysconfdir}/ergo -s /sbin/nologin ergo +%{_bindir}/getent group ergo > /dev/null || %{_sbindir}/groupadd -r ergo +%{_bindir}/getent passwd ergo > /dev/null || %{_sbindir}/useradd -r -g ergo -d %{_sysconfdir}/ergo -s /sbin/nologin ergo %if 0%{?suse_version} %service_add_pre ergo.service %endif %prep -# Alright openSUSE, here we go! %setup -q %patch0 -p1 %patch1 -p1 -# Oh Fedora, you having bit of an headstart, eh? %if 0%{?fedora} %goprep %endif @@ -95,13 +88,11 @@ Ergo is a modern IRC server written in Go. %build export GOFLAGS="-mod=vendor" -# "I'm prepping too now!! Don't rush me!", shouts openSUSE %if 0%{?suse_version} %goprep %{import_path} %gobuild . %endif -# S'ok! I've got some extra work here... %if 0%{?fedora} rm -rf "%{_builddir}/%{extractdir0}/_build/src/github.com/ergochat/ergo" ln -s "%{_builddir}/%{name}-%{version}" "%{_builddir}/%{extractdir0}/_build/src/github.com/ergochat/ergo" @@ -109,28 +100,23 @@ ln -s "%{_builddir}/%{name}-%{version}" "%{_builddir}/%{extractdir0}/_build/src/ %endif %install -# And.. installaction! %if 0%{?suse_version} %goinstall %gosrc %endif -# "Lame", moans Fedora, "I'm lifting some extra weights, not use some weird macro for my copyjobs!" %if 0%{?fedora} install -m 0755 -vd %{buildroot}%{_bindir} -install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/ +install -m 0755 -vp %{gobuilddir}/bin/%{name} %{buildroot}%{_bindir}/ %endif -# However after a short fight between the two, they continue doing some tasks in common, and achieve great teamwork. -install -d -m 700 %{buildroot}%{_sysconfdir}/%{name} +install -d -m 755 %{buildroot}%{_sysconfdir}/%{name} install -d -m 700 %{buildroot}%{_sharedstatedir}/%{name} -install -D -m 600 %{_builddir}/%{name}-%{version}/default.yaml %{buildroot}%{_sysconfdir}/%{name}/ircd.yaml +install -D -m 660 %{_builddir}/%{name}-%{version}/default.yaml %{buildroot}%{_sysconfdir}/%{name}/ircd.yaml install -D -m 644 %{_builddir}/%{name}-%{version}/distrib/systemd/%{name}.service %{buildroot}%{_unitdir}/%{name}.service install -d -m 755 %{buildroot}%{_sbindir} -#ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name} %check -# Let's see who made their job well... %if 0%{?suse_version} %gotest %{import_path} %endif @@ -139,49 +125,63 @@ install -d -m 755 %{buildroot}%{_sbindir} %gocheck %endif -# Alright, time to sum things up!! - -# "Hah, I have a nice filelist ready to go!" %if 0%{?suse_version} %gofilelist - %files -f file.lst %endif -# "Says the one WHO NEEDS a filelist!" %if 0%{?fedora} %files %endif %license LICENSE %doc README.md -%attr(750,ergo,ergo) %{_bindir}/%{name} -%dir %attr (700,ergo,ergo) %{_sysconfdir}/%{name} +%attr(755,ergo,ergo) %{_bindir}/%{name} +%dir %attr (755,ergo,ergo) %{_sysconfdir}/%{name} %dir %attr (700,ergo,ergo) %{_sharedstatedir}/%{name} %attr (-,ergo,ergo) %config(noreplace) %{_sysconfdir}/%{name}/ircd.yaml %{_unitdir}/%{name}.service -#%{_sbindir}/rc%{name} %post -# Some finishing touches, Fedora and openSUSE walk hand in hand, through filesystem's wonderland! %if 0%{?suse_version} %service_add_post ergo.service %endif %if 0%{?fedora} %systemd_post ergo.service %endif -install -d -o ergo -g ergo -m 700 %{_sysconfdir}/ssl/ergo -%{_bindir}/%{name} mkcerts --conf %{_sysconfdir}/%{name}/ircd.yaml || true -%{_bindir}/%{name} initdb --conf %{_sysconfdir}/%{name}/ircd.yaml || true -chown ergo:ergo %{_sysconfdir}/ssl/%{name}/crt -chown ergo:ergo %{_sysconfdir}/ssl/%{name}/key -chown ergo:ergo %{_sharedstatedir}/%{name}/ircd.db -chmod 600 %{_sharedstatedir}/%{name}/ircd.db -# Nice! All the distros cheer in excitement about the newly installed package! -echo "Welcome to Ergo!" -echo "To enable the service (auto-start): sudo systemctl enable ergo" -echo "To start the service now: sudo systemctl start ergo" -echo "The configuration is located in %{_sysconfdir}/ergo/ircd.yaml" +install -d -o ergo -g ergo -m 750 %{_sysconfdir}/ssl/ergo +if [ $1 -eq 1 ] +then + if %{_bindir}/%{name} mkcerts --conf %{_sysconfdir}/%{name}/ircd.yaml --quiet + then + chown ergo:ergo %{_sysconfdir}/ssl/%{name}/crt + chown ergo:ergo %{_sysconfdir}/ssl/%{name}/key + echo "Generated a self signed certificate. Please replace /etc/ssl/%{name}/crt and /etc/ssl/%{name}/key for production use." + fi +fi +if [ -f %{_sharedstatedir}/%{name}/ircd.db ] +then + %{_bindir}/%{name} upgradedb --conf %{_sysconfdir}/%{name}/ircd.yaml +fi +if [ ! -f %{_sharedstatedir}/%{name}/ircd.db ] +then + if %{_bindir}/%{name} initdb --conf %{_sysconfdir}/%{name}/ircd.yaml --quiet + then + chown ergo:ergo %{_sharedstatedir}/%{name}/ircd.db + chmod 600 %{_sharedstatedir}/%{name}/ircd.db + fi +fi +if [ $1 -eq 1 ] +then + echo "Welcome to Ergo!" + echo "To enable the service (auto-start): \`sudo systemctl enable ergo\`" + echo "To start the service now: \`sudo systemctl start ergo\`" + echo "The configuration is located in %{_sysconfdir}/ergo/ircd.yaml" +fi +if [ $1 -eq 2 ] +then + echo "Restart IRC daemon using \`systemctl restart ergo\` to complete upgrade." +fi %preun %if 0%{?suse_version} @@ -198,7 +198,5 @@ echo "The configuration is located in %{_sysconfdir}/ergo/ircd.yaml" %if 0%{?fedora} %systemd_postun ergo.service %endif -echo "NOTE - The ergo.service does NOT restart automatically." -# Rants from some h00man %changelog