diff --git a/Makefile b/Makefile
index 3fc9852..3639ebd 100644
--- a/Makefile
+++ b/Makefile
@@ -17,11 +17,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-NAME := "kf2-srv"
+NAME := kf2-srv
-RPMBUILDDIR := "$$HOME/rpmbuild"
-ACTIVEDIR := $(shell readlink -e "$$HOME/rpmbuild")
-WORKDIR := $(shell readlink -e ".")
+RPMBUILDDIR := $$HOME/rpmbuild
+ACTIVEDIR := $(shell readlink -e $$HOME/rpmbuild)
+WORKDIR := $(shell readlink -e .)
BUILDDIR := $(WORKDIR)/BUILD
BUILDROOTDIR := $(WORKDIR)/BUILDROOT
@@ -32,9 +32,8 @@ SRPMSDIR := $(WORKDIR)/SRPMS
SCRIPTSDIR := $(SOURCESDIR)/scripts
SPEC := $(SPECSDIR)/$(NAME).spec
-SOURCETARBALL := $(SOURCESDIR)$(NAME)-$(VERSION).tar.gz
-
-VERSION := $(shell grep -Fi 'Version:' $(SPEC) | awk '{ print $$2 }')
+VERSION := $(shell grep -Fi 'Version:' $(SPEC) | awk '{ print $$2 }')
+SOURCETARBALL := $(SOURCESDIR)/$(NAME)-$(VERSION).tar.gz
.PHONY: all prep rpm srpm activate check-activate clean-tmp clean-pkg clean
diff --git a/SOURCES/scripts/COPYING b/SOURCES/COPYING
similarity index 100%
rename from SOURCES/scripts/COPYING
rename to SOURCES/COPYING
diff --git a/SOURCES/Makefile b/SOURCES/Makefile
new file mode 100644
index 0000000..329ac8d
--- /dev/null
+++ b/SOURCES/Makefile
@@ -0,0 +1,121 @@
+# kf2-srv is a command line tool for managing a set of Killing Floor 2 servers.
+# Copyright (C) 2019, 2020 GenZmeY
+# mailto: genzmey@gmail.com
+#
+# This file is part of kf2-srv.
+#
+# kf2-srv is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+BASH := /bin/bash
+
+NAME := kf2-srv
+
+SOURCEDIR := .
+
+MAINLOGDIR := /var/log/$(NAME)
+BETALOGDIR := /var/log/$(NAME)-beta
+CONFDIR := /etc/$(NAME)
+INSTMAINDIR := $(CONFDIR)/instances
+INSTBETADIR := $(CONFDIR)/instances-beta
+MAPCYCLEDIR := $(CONFDIR)/mapcycles
+CACHEDIR := /var/cache/$(NAME)
+LOGROTATEDIR := /etc/logrotate.d
+RSYSLOGDIR := /etc/rsyslog.d
+SERVICEDIR = $(if $(BUILDROOT),/lib/systemd/system,/etc/systemd/system)
+FIREWALLDDIR = $(if $(BUILDROOT),/lib/firewalld/services,/etc/firewalld/services)
+
+BUILDROOT =
+PREFIX = /usr/local
+BINDIR = $(BUILDROOT)$(PREFIX)/bin
+SBINDIR = $(BUILDROOT)$(PREFIX)/sbin
+GAMEDIR = $(BUILDROOT)$(PREFIX)/games
+DATADIR = $(BUILDROOT)$(PREFIX)/share
+LICENSEDIR = $(DATADIR)/licenses/$(NAME)
+KF2MAINDIR = $(GAMEDIR)/$(NAME)
+KF2BETADIR = $(GAMEDIR)/$(NAME)-beta
+
+.PHONY: all install uninstall filesystem
+
+all: install
+
+filesystem:
+ test -d '$(CONFDIR)' || install -m 775 -d '$(CONFDIR)'
+ test -d '$(INSTMAINDIR)' || install -m 775 -d '$(INSTMAINDIR)'
+ test -d '$(INSTBETADIR)' || install -m 775 -d '$(INSTBETADIR)'
+ test -d '$(MAPCYCLEDIR)' || install -m 775 -d '$(MAPCYCLEDIR)'
+ test -d '$(CACHEDIR)' || install -m 775 -d '$(CACHEDIR)'
+ test -d '$(BINDIR)' || install -m 755 -d '$(BINDIR)'
+ test -d '$(SBINDIR)' || install -m 755 -d '$(SBINDIR)'
+ test -d '$(KF2MAINDIR)' || install -m 775 -d '$(KF2MAINDIR)'
+ test -d '$(KF2BETADIR)' || install -m 775 -d '$(KF2BETADIR)'
+ test -d '$(LICENSEDIR)' || install -m 755 -d '$(LICENSEDIR)'
+ test -d '$(MAINLOGDIR)' || install -m 770 -d '$(MAINLOGDIR)'
+ test -d '$(BETALOGDIR)' || install -m 770 -d '$(BETALOGDIR)'
+ test -d '$(SERVICEDIR)' || install -m 755 -d '$(SERVICEDIR)'
+ test -d '$(FIREWALLDDIR)' || install -m 755 -d '$(FIREWALLDDIR)'
+ test -d '$(LOGROTATEDIR)' || install -m 755 -d '$(LOGROTATEDIR)'
+ test -d '$(RSYSLOGDIR)' || install -m 755 -d '$(RSYSLOGDIR)'
+
+install: filesystem
+ install -m 755 $(SOURCEDIR)/main/$(NAME) $(BINDIR)
+ install -m 755 $(SOURCEDIR)/main/$(NAME)-beta $(BINDIR)
+
+ install -m 644 $(SOURCEDIR)/main/systemd/$(NAME)@.service $(SERVICEDIR)
+ install -m 644 $(SOURCEDIR)/main/systemd/$(NAME)-beta@.service $(SERVICEDIR)
+ install -m 644 $(SOURCEDIR)/main/systemd/$(NAME)-beta-update.service $(SERVICEDIR)
+ install -m 644 $(SOURCEDIR)/main/systemd/$(NAME)-beta-update.timer $(SERVICEDIR)
+ install -m 644 $(SOURCEDIR)/main/systemd/$(NAME)-update.service $(SERVICEDIR)
+ install -m 644 $(SOURCEDIR)/main/systemd/$(NAME)-update.timer $(SERVICEDIR)
+
+ install -m 644 $(SOURCESIR)/main/firewalld/$(NAME).xml $(FIREWALLDDIR)
+ install -m 644 $(SOURCESIR)/main/logrotate/$(NAME) $(LOGROTATEDIR)
+ install -m 644 $(SOURCESIR)/main/rsyslog/$(NAME).conf $(RSYSLOGDIR)
+
+ install -m 755 $(SOURCEDIR)/force-attr/$(NAME)-force-attr $(SBINDIR)
+ install -m 755 $(SOURCEDIR)/force-attr/systemd/$(NAME)-force-attr.service $(SERVICEDIR)
+
+ install -m 644 $(SOURCEDIR)/conf/bot.conf $(CONFDIR)
+ install -m 644 $(SOURCEDIR)/conf/instance.conf.template $(CONFDIR)
+ install -m 644 $(SOURCEDIR)/conf/$(NAME).conf $(CONFDIR)
+
+ install -m 644 $(SOURCEDIR)/COPYING $(LICENSEDIR)
+
+uninstall:
+ rm -f $(BINDIR)/$(NAME)
+ rm -f $(BINDIR)/$(NAME)-beta
+
+ rm -f $(SERVICEDIR)/$(NAME)@.service
+ rm -f $(SERVICEDIR)/$(NAME)-beta@.service
+ rm -f $(SERVICEDIR)/$(NAME)-beta-update.service
+ rm -f $(SERVICEDIR)/$(NAME)-beta-update.timer
+ rm -f $(SERVICEDIR)/$(NAME)-update.service
+ rm -f $(SERVICEDIR)/$(NAME)-update.timer
+
+ rm -f $(FIREWALLDDIR)/$(NAME).xml
+ rm -f $(LOGROTATEDIR)/$(NAME)
+ rm -f $(RSYSLOGDIR)/$(NAME).conf
+
+ rm -f $(SBINDIR)/$(NAME)-force-attr
+ rm -f $(SERVICEDIR)/$(NAME)-force-attr.service
+
+ rm -rf $(LICENSEDIR)
+ rm -rf $(KF2MAINDIR)
+ rm -rf $(KF2BETADIR)
+ rm -rf $(CACHEDIR)
+
+test:
+ $(BASH) -n $(BINDIR)/$(NAME)
+ $(BASH) -n $(BINDIR)/$(NAME)-beta
+ $(BASH) -n $(SBINDIR)/$(NAME)-force-attr
+
diff --git a/SOURCES/bot.conf b/SOURCES/config/bot.conf
similarity index 100%
rename from SOURCES/bot.conf
rename to SOURCES/config/bot.conf
diff --git a/SOURCES/instance.conf.template b/SOURCES/config/instance.conf.template
similarity index 100%
rename from SOURCES/instance.conf.template
rename to SOURCES/config/instance.conf.template
diff --git a/SOURCES/kf2-srv.conf b/SOURCES/config/kf2-srv.conf
similarity index 100%
rename from SOURCES/kf2-srv.conf
rename to SOURCES/config/kf2-srv.conf
diff --git a/SOURCES/scripts/kf2-srv-force-attr b/SOURCES/force-attr/kf2-srv-force-attr
similarity index 100%
rename from SOURCES/scripts/kf2-srv-force-attr
rename to SOURCES/force-attr/kf2-srv-force-attr
diff --git a/SOURCES/kf2-srv-force-attr.service b/SOURCES/force-attr/systemd/kf2-srv-force-attr.service
similarity index 100%
rename from SOURCES/kf2-srv-force-attr.service
rename to SOURCES/force-attr/systemd/kf2-srv-force-attr.service
diff --git a/SOURCES/kf2-srv.xml b/SOURCES/main/firewalld/kf2-srv.xml
similarity index 100%
rename from SOURCES/kf2-srv.xml
rename to SOURCES/main/firewalld/kf2-srv.xml
diff --git a/SOURCES/scripts/kf2-srv b/SOURCES/main/kf2-srv
similarity index 100%
rename from SOURCES/scripts/kf2-srv
rename to SOURCES/main/kf2-srv
diff --git a/SOURCES/scripts/kf2-srv-beta b/SOURCES/main/kf2-srv-beta
similarity index 100%
rename from SOURCES/scripts/kf2-srv-beta
rename to SOURCES/main/kf2-srv-beta
diff --git a/SOURCES/logrotate-kf2-srv b/SOURCES/main/logrotate/kf2-srv
similarity index 100%
rename from SOURCES/logrotate-kf2-srv
rename to SOURCES/main/logrotate/kf2-srv
diff --git a/SOURCES/rsyslog-kf2-srv.conf b/SOURCES/main/rsyslog/kf2-srv.conf
similarity index 100%
rename from SOURCES/rsyslog-kf2-srv.conf
rename to SOURCES/main/rsyslog/kf2-srv.conf
diff --git a/SOURCES/kf2-srv-beta-update.service b/SOURCES/main/systemd/kf2-srv-beta-update.service
similarity index 100%
rename from SOURCES/kf2-srv-beta-update.service
rename to SOURCES/main/systemd/kf2-srv-beta-update.service
diff --git a/SOURCES/kf2-srv-beta-update.timer b/SOURCES/main/systemd/kf2-srv-beta-update.timer
similarity index 100%
rename from SOURCES/kf2-srv-beta-update.timer
rename to SOURCES/main/systemd/kf2-srv-beta-update.timer
diff --git a/SOURCES/kf2-srv-beta@.service b/SOURCES/main/systemd/kf2-srv-beta@.service
similarity index 100%
rename from SOURCES/kf2-srv-beta@.service
rename to SOURCES/main/systemd/kf2-srv-beta@.service
diff --git a/SOURCES/kf2-srv-update.service b/SOURCES/main/systemd/kf2-srv-update.service
similarity index 100%
rename from SOURCES/kf2-srv-update.service
rename to SOURCES/main/systemd/kf2-srv-update.service
diff --git a/SOURCES/kf2-srv-update.timer b/SOURCES/main/systemd/kf2-srv-update.timer
similarity index 100%
rename from SOURCES/kf2-srv-update.timer
rename to SOURCES/main/systemd/kf2-srv-update.timer
diff --git a/SOURCES/kf2-srv@.service b/SOURCES/main/systemd/kf2-srv@.service
similarity index 100%
rename from SOURCES/kf2-srv@.service
rename to SOURCES/main/systemd/kf2-srv@.service
diff --git a/SPECS/kf2-srv.spec b/SPECS/kf2-srv.spec
index 98e568c..bc73684 100644
--- a/SPECS/kf2-srv.spec
+++ b/SPECS/kf2-srv.spec
@@ -9,23 +9,6 @@ License: GNU GPLv3
BuildArch: noarch
Source0: %{name}-%{version}.tar.gz
-Source1: %{name}
-Source2: %{name}-beta
-Source3: %{name}.xml
-Source4: %{name}@.service
-Source5: %{name}-update.service
-Source6: %{name}-update.timer
-Source7: instance.conf.template
-Source8: %{name}-beta@.service
-Source9: %{name}-beta-update.service
-Source10: %{name}-beta-update.timer
-Source11: %{name}.conf
-Source12: COPYING
-Source13: rsyslog-%{name}.conf
-Source14: logrotate-%{name}
-Source15: bot.conf
-Source16: %{name}-force-attr
-Source17: %{name}-force-attr.service
Requires: systemd >= 219
Requires: steamcmd
@@ -50,50 +33,17 @@ Provides: %{name}
Command line tool for managing a set of Killing Floor 2 servers.
%prep
+%setup -q -c
%build
%install
rm -rf $RPM_BUILD_ROOT
-install -d %{buildroot}/%{_bindir}
-install -d %{buildroot}/%{_sbindir}
-install -d %{buildroot}/%{_prefix}/lib/systemd/system
-install -d %{buildroot}/%{_prefix}/lib/firewalld/services
-install -d %{buildroot}/%{_sysconfdir}/%{name}/instances
-install -d %{buildroot}/%{_sysconfdir}/%{name}/instances-beta
-install -d %{buildroot}/%{_sysconfdir}/%{name}/mapcycles
-install -d %{buildroot}/%{_sysconfdir}/rsyslog.d
-install -d %{buildroot}/%{_sysconfdir}/logrotate.d
-install -d %{buildroot}/%{_prefix}/games/%{name}
-install -d %{buildroot}/%{_prefix}/games/%{name}-beta
-install -d %{buildroot}/%{_datadir}/licenses/%{name}
-install -d %{buildroot}/%{_localstatedir}/log/%{name}
-install -d %{buildroot}/%{_localstatedir}/log/%{name}-beta
-install -d %{buildroot}/%{_localstatedir}/cache/kf2-srv
-
-# access rights are used here to prevent warnings when building the package
-install -m 755 %{SOURCE1} %{buildroot}/%{_bindir}
-install -m 755 %{SOURCE2} %{buildroot}/%{_bindir}
-install -m 644 %{SOURCE3} %{buildroot}/%{_prefix}/lib/firewalld/services
-install -m 644 %{SOURCE4} %{buildroot}/%{_prefix}/lib/systemd/system
-install -m 644 %{SOURCE5} %{buildroot}/%{_prefix}/lib/systemd/system
-install -m 644 %{SOURCE6} %{buildroot}/%{_prefix}/lib/systemd/system
-install -m 644 %{SOURCE7} %{buildroot}/%{_sysconfdir}/%{name}
-install -m 644 %{SOURCE8} %{buildroot}/%{_prefix}/lib/systemd/system
-install -m 644 %{SOURCE9} %{buildroot}/%{_prefix}/lib/systemd/system
-install -m 644 %{SOURCE10} %{buildroot}/%{_prefix}/lib/systemd/system
-install -m 644 %{SOURCE11} %{buildroot}/%{_sysconfdir}/%{name}
-install -m 644 %{SOURCE12} %{buildroot}/%{_datadir}/licenses/%{name}
-install -m 644 %{SOURCE13} %{buildroot}/%{_sysconfdir}/rsyslog.d/%{name}.conf
-install -m 644 %{SOURCE14} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name}
-install -m 644 %{SOURCE15} %{buildroot}/%{_sysconfdir}/%{name}
-install -m 755 %{SOURCE16} %{buildroot}/%{_sbindir}
-install -m 644 %{SOURCE17} %{buildroot}/%{_prefix}/lib/systemd/system
+make install PREFIX=%{buildroot}/%{_prefix}
%check
-bash -n %{buildroot}/%{_bindir}/%{name}
-bash -n %{buildroot}/%{_bindir}/%{name}-beta
+make test PREFIX=%{buildroot}/%{_prefix}
%clean
rm -rf $RPM_BUILD_ROOT