Files
adamandClaude Opus 5.5 fc2c08d47b
release / deb (push) Successful in 17s
add doctor, scheduled backups and fetch; release 0.0.12
- doctor [<name>] [--fix]: checks the system (user, programs, folders,
  zips, units and leftover copies in /etc, sandbox access to moved
  folders, journal, polkit, daemon, orphaned boot links and schedules)
  and each instance (ownership, server zip, config paths, mods, ports,
  failed starts/backups), with a fix for each. --fix applies the safe
  ones and re-checks them.
- backup enable|disable|now|list: a systemd timer per instance
  (terraria-backup@.timer, Persistent=), saving the world first, into
  /var/lib/terraria/backups/<name>/ (group-readable), pruning only
  scheduled backups. rename carries the schedule, delete removes it.
  upgrade's backups move there too.
- fetch vanilla|tmodloader [<version>] [--list] [--upgrade <name>]:
  downloads from terraria.org / tModLoader's GitHub releases, checks
  GitHub's sha256 and the zip, names it with its version.
- terractld may write /etc/systemd/system, for backup enable and
  doctor --fix over --host.
- Units, tmpfiles, packaging, completion, docs and changelog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 22:26:56 +00:00

133 lines
6.1 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
# 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
.PHONY: all check install uninstall deb 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 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 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)
clean:
rm -rf build