Advanced building

- makefiles;
- customizable PREFIX;
- tests;
- other useful stuff.
This commit is contained in:
GenZmeY 2020-08-05 12:36:08 +03:00
parent 5f2b6075ba
commit 75d79078e2
11 changed files with 125 additions and 84 deletions

View File

@ -29,20 +29,24 @@ RPMSDIR := $(WORKDIR)/RPMS
SOURCESDIR := $(WORKDIR)/SOURCES
SPECSDIR := $(WORKDIR)/SPECS
SRPMSDIR := $(WORKDIR)/SRPMS
SCRIPTSDIR := $(SOURCESDIR)/scripts
SPEC := $(SPECSDIR)/$(NAME).spec
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
.PHONY: all prep rpm srpm activate active check-activate clean-tmp clean-pkg clean
all: check-activate prep
rpmbuild -ba $(SPEC)
$(MAKE) clean-tmp
prep: clean-tmp
tar czf $(SOURCETARBALL) -C $(SCRIPTSDIR) .
cd $(SOURCESDIR) && tar czf $(SOURCETARBALL) \
config \
force-attr \
main \
COPYING \
Makefile
rpm: check-activate prep
rpmbuild -bb $(SPEC)
@ -52,6 +56,8 @@ srpm: check-activate prep
rpmbuild -bs $(SPEC)
$(MAKE) clean-tmp
active: activate
activate:
ifeq ($(shell test -d $(RPMBUILDDIR); echo $$?), 0)
mv -f $(RPMBUILDDIR) $(RPMBUILDDIR).old

View File

@ -17,38 +17,56 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
BASH := /bin/bash
NAME := kf2-srv
NAME := kf2-srv
SOURCEDIR := .
RELEASEDIR := $(SOURCEDIR)/release
BUILDROOT =
PREFIX = /usr/local
SOURCEDIR := .
MAINLOGDIR = $(BUILDROOT)/var/log/$(NAME)
BETALOGDIR = $(BUILDROOT)/var/log/$(NAME)-beta
CONFDIR = $(BUILDROOT)/etc/$(NAME)
INSTMAINDIR = $(CONFDIR)/instances
INSTBETADIR = $(CONFDIR)/instances-beta
MAPCYCLEDIR = $(CONFDIR)/mapcycles
CACHEDIR = $(BUILDROOT)/var/cache/$(NAME)
LOGROTATEDIR = $(BUILDROOT)/etc/logrotate.d
RSYSLOGDIR = $(BUILDROOT)/etc/rsyslog.d
UNITDIR = $(if $(BUILDROOT),$(BUILDROOT)/usr/lib/systemd/system,/etc/systemd/system)
FIREWALLDDIR = $(if $(BUILDROOT),$(BUILDROOT)/usr/lib/firewalld/services,/etc/firewalld/services)
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
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)
BASHCHECK := bash -n
SYSTEMDCHECK := systemd-analyze verify
LOGROTATECHECK := logrotate -d
XMLCHECK := xmllint --noout
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
.PHONY: build fake-systemd-build install uninstall filesystem test clean all
all: install
build:
mkdir $(RELEASEDIR)
cp -r $(SOURCEDIR)/main $(RELEASEDIR)
cp -r $(SOURCEDIR)/config $(RELEASEDIR)
cp -r $(SOURCEDIR)/force-attr $(RELEASEDIR)
find $(RELEASEDIR) -type f -exec sed -i 's|:DEFINE_PREFIX:|$(PREFIX)|g;' {} \;
fake-systemd-build:
find $(SOURCEDIR)/main -type f -name '*.service' -exec cp -f {} $(RELEASEDIR)/{} \;
find $(SOURCEDIR)/force-attr -type f -name '*.service' -exec cp -f {} $(RELEASEDIR)/{} \;
find $(RELEASEDIR) -type f -exec sed -i 's|:DEFINE_PREFIX:|$(BUILDROOT)$(PREFIX)|g;' {} \;
find $(RELEASEDIR) -type f -exec sed -i -r 's|ExecStart=.+KFGameSteamServer.bin.x86_64|ExecStart=/bin/bash|g;' {} \;
filesystem:
test -d '$(CONFDIR)' || install -m 775 -d '$(CONFDIR)'
test -d '$(INSTMAINDIR)' || install -m 775 -d '$(INSTMAINDIR)'
@ -62,60 +80,77 @@ filesystem:
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 '$(UNITDIR)' || install -m 755 -d '$(UNITDIR)'
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: filesystem build
install -m 755 $(RELEASEDIR)/main/$(NAME) $(BINDIR)
install -m 755 $(RELEASEDIR)/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 $(RELEASEDIR)/main/systemd/$(NAME)@.service $(UNITDIR)
install -m 644 $(RELEASEDIR)/main/systemd/$(NAME)-beta@.service $(UNITDIR)
install -m 644 $(RELEASEDIR)/main/systemd/$(NAME)-beta-update.service $(UNITDIR)
install -m 644 $(RELEASEDIR)/main/systemd/$(NAME)-beta-update.timer $(UNITDIR)
install -m 644 $(RELEASEDIR)/main/systemd/$(NAME)-update.service $(UNITDIR)
install -m 644 $(RELEASEDIR)/main/systemd/$(NAME)-update.timer $(UNITDIR)
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 644 $(RELEASEDIR)/main/firewalld/$(NAME).xml $(FIREWALLDDIR)
install -m 644 $(RELEASEDIR)/main/logrotate/$(NAME) $(LOGROTATEDIR)
install -m 644 $(RELEASEDIR)/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 755 $(RELEASEDIR)/force-attr/$(NAME)-force-attr $(SBINDIR)
install -m 644 $(RELEASEDIR)/force-attr/systemd/$(NAME)-force-attr.service $(UNITDIR)
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 640 $(RELEASEDIR)/config/bot.conf $(CONFDIR)
install -m 644 $(RELEASEDIR)/config/instance.conf.template $(CONFDIR)
install -m 644 $(RELEASEDIR)/config/$(NAME).conf $(CONFDIR)
install -m 644 $(SOURCEDIR)/COPYING $(LICENSEDIR)
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 $(UNITDIR)/$(NAME)@.service
rm -f $(UNITDIR)/$(NAME)-beta@.service
rm -f $(UNITDIR)/$(NAME)-beta-update.service
rm -f $(UNITDIR)/$(NAME)-beta-update.timer
rm -f $(UNITDIR)/$(NAME)-update.service
rm -f $(UNITDIR)/$(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 -f $(UNITDIR)/$(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
test: fake-systemd-build
ifeq ($(shell $(LOGROTATECHECK) $(RELEASEDIR)/main/logrotate/$(NAME) 2>&1 | grep -qi 'error'; echo $$?), 0)
$(LOGROTATECHECK) $(RELEASEDIR)/main/logrotate/$(NAME)
endif
$(XMLCHECK) $(RELEASEDIR)/main/firewalld/$(NAME).xml
$(SYSTEMDCHECK) $(RELEASEDIR)/main/systemd/$(NAME)@.service
$(SYSTEMDCHECK) $(RELEASEDIR)/main/systemd/$(NAME)-beta@.service
$(SYSTEMDCHECK) $(RELEASEDIR)/main/systemd/$(NAME)-beta-update.service
$(SYSTEMDCHECK) $(RELEASEDIR)/main/systemd/$(NAME)-beta-update.timer
$(SYSTEMDCHECK) $(RELEASEDIR)/main/systemd/$(NAME)-update.service
$(SYSTEMDCHECK) $(RELEASEDIR)/main/systemd/$(NAME)-update.timer
$(SYSTEMDCHECK) $(RELEASEDIR)/force-attr/systemd/$(NAME)-force-attr.service
$(BASHCHECK) $(RELEASEDIR)/main/$(NAME)
$(BASHCHECK) $(RELEASEDIR)/main/$(NAME)-beta
$(BASHCHECK) $(RELEASEDIR)/force-attr/$(NAME)-force-attr
clean:
rm -rf $(RELEASEDIR)

View File

@ -21,7 +21,7 @@
declare -A ModeNames MutNames
source /etc/kf2-srv/kf2-srv.conf
source "/etc/kf2-srv/kf2-srv.conf"
DirLog="/var/log/kf2-srv"
DirLogBeta="/var/log/kf2-srv-beta"

View File

@ -5,7 +5,7 @@ Description=kf2-srv force attr service
Type=simple
StandardOutput=null
StandardError=null
ExecStart=/usr/sbin/kf2-srv-force-attr
ExecStart=:DEFINE_PREFIX:/sbin/kf2-srv-force-attr
Restart=always
NoNewPrivileges=yes

View File

@ -446,9 +446,9 @@ function fix_steamclient_so ()
rm -f "$InstallDir/linux64/steamclient.so"
rm -f "$InstallDir/steamclient.so"
rm -f "$InstallDir/Binaries/Win64/lib64/steamclient.so"
ln -s "/usr/share/steamcmd/linux64/steamclient.so" "$InstallDir/linux64/steamclient.so"
ln -s "/usr/share/steamcmd/linux64/steamclient.so" "$InstallDir/steamclient.so"
ln -s "/usr/share/steamcmd/linux64/steamclient.so" "$InstallDir/Binaries/Win64/lib64/steamclient.so"
ln -s "/usr/games/steamcmd/linux64/steamclient.so" "$InstallDir/linux64/steamclient.so"
ln -s "/usr/games/steamcmd/linux64/steamclient.so" "$InstallDir/steamclient.so"
ln -s "/usr/games/steamcmd/linux64/steamclient.so" "$InstallDir/Binaries/Win64/lib64/steamclient.so"
}
function create_cache ()
@ -1234,7 +1234,7 @@ if [[ "$1" == "beta" ]]; then
BetaPostfix="-beta"; shift
fi
InstallDir="/usr/games/kf2-srv$BetaPostfix"
InstallDir=":DEFINE_PREFIX:/games/kf2-srv$BetaPostfix"
AppBin="$InstallDir/Binaries/Win64/KFGameSteamServer.bin.x86_64"
DefaultConfigDir="$InstallDir/KFGame/Config"

View File

@ -19,4 +19,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
/usr/bin/kf2-srv beta $*
":DEFINE_PREFIX:/bin/kf2-srv" beta $*

View File

@ -6,20 +6,20 @@ Requires=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/kf2-srv-beta --chat 'Scheduled server restart at 4:00 (MSK)'
ExecStart=/usr/bin/kf2-srv-beta --chat 'Server will restart after 30 minutes'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv-beta --chat '.'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv-beta --chat 'Server will restart after 30 minutes'
ExecStart=/bin/sleep 15m
ExecStart=/usr/bin/kf2-srv-beta --chat 'Server will restart after 15 minutes'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv-beta --chat 'Server will restart after 15 minutes'
ExecStart=/bin/sleep 10m
ExecStart=/usr/bin/kf2-srv-beta --chat 'Server will restart after 5 minutes'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv-beta --chat 'Server will restart after 5 minutes'
ExecStart=/bin/sleep 5m
ExecStart=/usr/bin/kf2-srv-beta --chat 'Server shutting down...'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv-beta --chat 'Server shutting down...'
ExecStart=/bin/sleep 5s
ExecStart=/usr/bin/kf2-srv-beta --update
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv-beta --update
PrivateTmp=true
PrivateDevices=true

View File

@ -12,7 +12,7 @@ StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=kf2-srv-beta/%i
EnvironmentFile=/etc/kf2-srv/instances-beta/%i/instance.conf
ExecStart=/usr/games/kf2-srv-beta/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame}
ExecStart=:DEFINE_PREFIX:/games/kf2-srv-beta/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame}
Restart=always
NoNewPrivileges=yes

View File

@ -6,20 +6,20 @@ Requires=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/kf2-srv --chat 'Scheduled server restart at 4:00 (MSK)'
ExecStart=/usr/bin/kf2-srv --chat 'Server will restart after 30 minutes'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv --chat '.'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv --chat 'Server will restart after 30 minutes'
ExecStart=/bin/sleep 15m
ExecStart=/usr/bin/kf2-srv --chat 'Server will restart after 15 minutes'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv --chat 'Server will restart after 15 minutes'
ExecStart=/bin/sleep 10m
ExecStart=/usr/bin/kf2-srv --chat 'Server will restart after 5 minutes'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv --chat 'Server will restart after 5 minutes'
ExecStart=/bin/sleep 5m
ExecStart=/usr/bin/kf2-srv --chat 'Server shutting down...'
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv --chat 'Server shutting down...'
ExecStart=/bin/sleep 5s
ExecStart=/usr/bin/kf2-srv --update
ExecStart=:DEFINE_PREFIX:/bin/kf2-srv --update
PrivateTmp=true
PrivateDevices=true

View File

@ -12,7 +12,7 @@ StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=kf2-srv/%i
EnvironmentFile=/etc/kf2-srv/instances/%i/instance.conf
ExecStart=/usr/games/kf2-srv/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame}
ExecStart=:DEFINE_PREFIX:/games/kf2-srv/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame}
Restart=always
NoNewPrivileges=yes

View File

@ -1,7 +1,7 @@
%global steamuser steam
Name: kf2-srv
Version: 0.13.0
Version: 0.14.0
Release: 1%{dist}
Summary: Killing Floor 2 server
Group: Amusements/Games
@ -11,7 +11,7 @@ BuildArch: noarch
Source0: %{name}-%{version}.tar.gz
Requires: systemd >= 219
Requires: steamcmd
Requires: steamcmd >= 2018.01.05-5
Requires: libxml2
Requires: dos2unix
Requires: curl
@ -40,10 +40,10 @@ Command line tool for managing a set of Killing Floor 2 servers.
%install
rm -rf $RPM_BUILD_ROOT
make install PREFIX=%{buildroot}/%{_prefix}
make install BUILDROOT=%{buildroot} PREFIX=%{_prefix}
%check
make test PREFIX=%{buildroot}/%{_prefix}
make test BUILDROOT=%{buildroot} PREFIX=%{_prefix}
%clean
rm -rf $RPM_BUILD_ROOT
@ -65,7 +65,7 @@ rm -rf $RPM_BUILD_ROOT
%attr(0755,root,root) %{_bindir}/%{name}
%attr(0755,root,root) %{_bindir}/%{name}-beta
%attr(0755,root,root) %{_sbindir}/%{name}-force-attr
%attr(0644,root,root) %{_prefix}/lib/systemd/system/*
%attr(0644,root,root) %{_unitdir}/*
%attr(0644,root,root) %doc %{_datadir}/licenses/%{name}/*
%attr(0644,root,root) %{_sysconfdir}/rsyslog.d/%{name}.conf
%attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}