#!/usr/bin/make -f

%:
	dh $@

# bin/* lands in omarchy except the two scripts that run or restart the
# Quickshell process, which need the shell tree and quickshell itself and so
# ride with omarchy-shell. The plymouth theme is renamed on the way in
# (default/plymouth -> themes/omarchy), which dh_install cannot express.
override_dh_install:
	dh_install
	rm -f debian/omarchy/usr/bin/omarchy-launch-shell \
	      debian/omarchy/usr/bin/omarchy-restart-shell
	mkdir -p debian/omarchy-shell/usr/share/plymouth/themes/omarchy
	cp -a default/plymouth/. debian/omarchy-shell/usr/share/plymouth/themes/omarchy/

# Upstream keeps /usr/share/omarchy/bin/* as symlinks onto /usr/bin/* so a
# dev-linked checkout and the packaged tree resolve the same way.
override_dh_link:
	set -e; for pkg in omarchy omarchy-shell; do \
	  : > debian/$$pkg.links; \
	  for f in debian/$$pkg/usr/bin/*; do \
	    n=$$(basename $$f); \
	    echo "usr/bin/$$n usr/share/omarchy/bin/$$n" >> debian/$$pkg.links; \
	  done; \
	done
	dh_link

# Nothing is generated here, so the only thing left to normalise is upstream's
# own PNGs: it rewrites all 60 theme images and every third-party theme's
# checksum along with them, for no reproducibility gain.
override_dh_strip_nondeterminism:

override_dh_clean:
	rm -f debian/omarchy.links debian/omarchy-shell.links
	dh_clean

# sudo reads a sudoers.d drop-in only when nothing but root can write it;
# dh_fixperms would leave the four grants 0644.
override_dh_fixperms:
	dh_fixperms
	chmod 0440 debian/omarchy/etc/sudoers.d/*
