LICENSE (MIT), installed as /usr/share/doc/terraria-server-manager/copyright in both packages and with %license in the RPM. README gains a License section and an up-to-date repository layout and build section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
7.5 KiB
Makefile
159 lines
7.5 KiB
Makefile
# terraria-server-manager
|
|
#
|
|
# make check syntax-check the scripts (and shellcheck, if installed)
|
|
# make deb build build/terraria-server-manager_<version>_all.deb
|
|
# make rpm build build/terraria-server-manager-<version>-1.noarch.rpm
|
|
# sudo make install install directly (default PREFIX=/usr/local), no package
|
|
# sudo make uninstall remove what 'make install' installed (keeps your data)
|
|
# make clean remove build/
|
|
|
|
NAME := terraria-server-manager
|
|
VERSION := $(shell cat VERSION)
|
|
|
|
PREFIX ?= /usr/local
|
|
SYSCONFDIR ?= /etc
|
|
BINDIR := $(PREFIX)/bin
|
|
UNITDIR := $(PREFIX)/lib/systemd/system
|
|
SYSUSERSDIR := $(PREFIX)/lib/sysusers.d
|
|
TMPFILESDIR := $(PREFIX)/lib/tmpfiles.d
|
|
DOCDIR := $(PREFIX)/share/doc/$(NAME)
|
|
DATADIR := $(PREFIX)/share/$(NAME)
|
|
PKGLIBDIR := $(PREFIX)/lib/$(NAME)
|
|
COMPLETIONDIR := $(PREFIX)/share/bash-completion/completions
|
|
# polkit only reads /usr/share/polkit-1/rules.d and /etc/polkit-1/rules.d
|
|
ifeq ($(PREFIX),/usr)
|
|
POLKITDIR ?= /usr/share/polkit-1/rules.d
|
|
else
|
|
POLKITDIR ?= $(SYSCONFDIR)/polkit-1/rules.d
|
|
endif
|
|
|
|
# Fill in version and install paths
|
|
SUBST = sed -e 's|@VERSION@|$(VERSION)|g' -e 's|@BINDIR@|$(BINDIR)|g' -e 's|@DOCDIR@|$(DOCDIR)|g' \
|
|
-e 's|@PKGLIBDIR@|$(PKGLIBDIR)|g'
|
|
|
|
MAINT_SCRIPTS := packaging/deb/postinst packaging/deb/prerm packaging/deb/postrm
|
|
STAGE := build/deb-root
|
|
DEB := build/$(NAME)_$(VERSION)_all.deb
|
|
RPMTOP := build/rpm
|
|
RPM := build/$(NAME)-$(VERSION)-1.noarch.rpm
|
|
# What goes in the source tarball the RPM is built from
|
|
RPM_SOURCES := Makefile VERSION LICENSE README.md CHANGELOG.md bin lib completions config docs \
|
|
packaging systemd tools
|
|
|
|
.PHONY: all check install uninstall deb rpm clean
|
|
|
|
all: check
|
|
|
|
check:
|
|
bash -n bin/terractl
|
|
bash -n completions/bash/terractl
|
|
for f in $(MAINT_SCRIPTS); do sh -n $$f; done
|
|
python3 -c 'import ast, sys; ast.parse(open(sys.argv[1]).read(), sys.argv[1])' lib/terractl-remote
|
|
@if command -v shellcheck >/dev/null; then \
|
|
shellcheck bin/terractl completions/bash/terractl $(MAINT_SCRIPTS); \
|
|
else \
|
|
echo "shellcheck not installed; skipped (apt install shellcheck)"; \
|
|
fi
|
|
@if command -v rpmspec >/dev/null; then \
|
|
spec=$$(mktemp --suffix=.spec); \
|
|
sed 's|@VERSION@|$(VERSION)|' packaging/rpm/$(NAME).spec.in > $$spec; \
|
|
rpmspec -P $$spec >/dev/null; rc=$$?; rm -f $$spec; [ $$rc -eq 0 ]; \
|
|
else \
|
|
echo "rpmspec not installed; RPM spec not checked (apt install rpm, or dnf install rpm-build)"; \
|
|
fi
|
|
@if python3 -m pyflakes --version >/dev/null 2>&1; then \
|
|
python3 -m pyflakes lib/terractl-remote; \
|
|
else \
|
|
echo "pyflakes not installed; skipped (apt install python3-pyflakes)"; \
|
|
fi
|
|
|
|
install:
|
|
install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(UNITDIR) $(DESTDIR)$(SYSUSERSDIR) \
|
|
$(DESTDIR)$(TMPFILESDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(DATADIR) $(DESTDIR)$(PKGLIBDIR) \
|
|
$(DESTDIR)$(COMPLETIONDIR) $(DESTDIR)$(SYSCONFDIR)/default $(DESTDIR)$(SYSCONFDIR)/systemd \
|
|
$(DESTDIR)$(POLKITDIR)
|
|
$(SUBST) bin/terractl > $(DESTDIR)$(BINDIR)/terractl
|
|
chmod 755 $(DESTDIR)$(BINDIR)/terractl
|
|
install -m 755 lib/terractl-remote $(DESTDIR)$(PKGLIBDIR)/terractl-remote
|
|
$(SUBST) systemd/terraria@.service > $(DESTDIR)$(UNITDIR)/terraria@.service
|
|
$(SUBST) systemd/terractld.service > $(DESTDIR)$(UNITDIR)/terractld.service
|
|
$(SUBST) systemd/terraria-backup@.service > $(DESTDIR)$(UNITDIR)/terraria-backup@.service
|
|
$(SUBST) systemd/terraria-backup@.timer > $(DESTDIR)$(UNITDIR)/terraria-backup@.timer
|
|
chmod 644 $(DESTDIR)$(UNITDIR)/terraria@.service $(DESTDIR)$(UNITDIR)/terractld.service \
|
|
$(DESTDIR)$(UNITDIR)/terraria-backup@.service $(DESTDIR)$(UNITDIR)/terraria-backup@.timer
|
|
install -m 644 systemd/terraria@.socket $(DESTDIR)$(UNITDIR)/
|
|
install -m 644 config/sysusers.d/terractl.conf $(DESTDIR)$(SYSUSERSDIR)/
|
|
install -m 644 config/tmpfiles.d/terractl.conf $(DESTDIR)$(TMPFILESDIR)/
|
|
install -m 644 config/polkit/terractl.rules $(DESTDIR)$(POLKITDIR)/50-terractl.rules
|
|
install -m 644 docs/guide.md $(DESTDIR)$(DOCDIR)/README.md
|
|
install -m 644 LICENSE $(DESTDIR)$(DOCDIR)/copyright
|
|
install -m 644 tools/windows/export-tmod-mods.ps1 $(DESTDIR)$(DATADIR)/
|
|
install -m 644 completions/bash/terractl $(DESTDIR)$(COMPLETIONDIR)/terractl
|
|
@# Never overwrite local settings
|
|
@if [ -e $(DESTDIR)$(SYSCONFDIR)/default/terractl ]; then \
|
|
echo "keeping existing $(DESTDIR)$(SYSCONFDIR)/default/terractl"; \
|
|
else \
|
|
install -m 644 config/default/terractl $(DESTDIR)$(SYSCONFDIR)/default/terractl; \
|
|
fi
|
|
@if [ -e $(DESTDIR)$(SYSCONFDIR)/systemd/journald@terraria.conf ]; then \
|
|
echo "keeping existing $(DESTDIR)$(SYSCONFDIR)/systemd/journald@terraria.conf"; \
|
|
else \
|
|
install -m 644 config/journald/journald@terraria.conf $(DESTDIR)$(SYSCONFDIR)/systemd/journald@terraria.conf; \
|
|
fi
|
|
@# On a real install (not staging for a package), set up the user and directories
|
|
@if [ -z "$(DESTDIR)" ]; then \
|
|
systemd-sysusers terractl.conf && \
|
|
systemd-tmpfiles --create terractl.conf && \
|
|
if [ -d /run/systemd/system ]; then \
|
|
systemctl daemon-reload && systemctl try-restart terractld.service; \
|
|
fi && \
|
|
$(BINDIR)/terractl journal-access && \
|
|
echo "Installed terractl $(VERSION). See $(DOCDIR)/README.md"; \
|
|
fi
|
|
|
|
uninstall:
|
|
@if [ -z "$(DESTDIR)" ] && [ -d /run/systemd/system ]; then \
|
|
systemctl disable --now terractld.service 2>/dev/null || true; \
|
|
for t in $$(systemctl list-unit-files --plain --no-legend 'terraria-backup@*.timer' | awk '{print $$1}'); do \
|
|
systemctl disable --now "$$t" 2>/dev/null || true; \
|
|
done; \
|
|
fi
|
|
rm -f $(DESTDIR)$(BINDIR)/terractl \
|
|
$(DESTDIR)$(UNITDIR)/terraria@.service $(DESTDIR)$(UNITDIR)/terraria@.socket \
|
|
$(DESTDIR)$(UNITDIR)/terractld.service \
|
|
$(DESTDIR)$(UNITDIR)/terraria-backup@.service $(DESTDIR)$(UNITDIR)/terraria-backup@.timer \
|
|
$(DESTDIR)$(SYSUSERSDIR)/terractl.conf $(DESTDIR)$(TMPFILESDIR)/terractl.conf \
|
|
$(DESTDIR)$(COMPLETIONDIR)/terractl $(DESTDIR)$(POLKITDIR)/50-terractl.rules
|
|
rm -rf $(DESTDIR)$(DOCDIR) $(DESTDIR)$(DATADIR) $(DESTDIR)$(PKGLIBDIR)
|
|
@if [ -z "$(DESTDIR)" ] && [ -d /run/systemd/system ]; then systemctl daemon-reload; fi
|
|
@echo "Removed. Kept: $(SYSCONFDIR)/default/terractl, $(SYSCONFDIR)/systemd/journald@terraria.conf,"
|
|
@echo "/var/lib/terraria, /var/lib/terractl (the daemon's certificate and trusted"
|
|
@echo "computers), the servers' journal and the terraria user."
|
|
|
|
deb: check
|
|
rm -rf $(STAGE)
|
|
$(MAKE) --no-print-directory install DESTDIR=$(CURDIR)/$(STAGE) PREFIX=/usr
|
|
install -d -m 755 $(STAGE)/DEBIAN
|
|
install -m 644 packaging/deb/conffiles $(STAGE)/DEBIAN/
|
|
install -m 755 $(MAINT_SCRIPTS) $(STAGE)/DEBIAN/
|
|
sed -e 's|@VERSION@|$(VERSION)|' \
|
|
-e "s|@INSTALLED_SIZE@|$$(du -sk --exclude=DEBIAN $(STAGE) | cut -f1)|" \
|
|
packaging/deb/control > $(STAGE)/DEBIAN/control
|
|
find $(STAGE) -type d -exec chmod 755 {} +
|
|
dpkg-deb --build --root-owner-group $(STAGE) $(DEB)
|
|
|
|
# Builds with plain rpmbuild (no Fedora-specific macros), so it works on Debian
|
|
# and Ubuntu too, with: apt install rpm
|
|
rpm: check
|
|
rm -rf $(RPMTOP)
|
|
install -d $(RPMTOP)/SOURCES $(RPMTOP)/SPECS
|
|
tar -czf $(RPMTOP)/SOURCES/$(NAME)-$(VERSION).tar.gz --exclude=__pycache__ \
|
|
--transform 's|^|$(NAME)-$(VERSION)/|' $(RPM_SOURCES)
|
|
sed 's|@VERSION@|$(VERSION)|' packaging/rpm/$(NAME).spec.in > $(RPMTOP)/SPECS/$(NAME).spec
|
|
@# --nodeps: on Debian and Ubuntu there is no RPM database to check BuildRequires against
|
|
rpmbuild -bb --nodeps --define "_topdir $(CURDIR)/$(RPMTOP)" $(RPMTOP)/SPECS/$(NAME).spec
|
|
cp $(RPMTOP)/RPMS/noarch/$(NAME)-$(VERSION)-1.noarch.rpm $(RPM)
|
|
|
|
clean:
|
|
rm -rf build
|