From fefcfd4b7ccc9d094f350b1e7b96ea54d61469ae Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 13 Aug 2025 18:45:16 -0500 Subject: [PATCH] Add RPM spec file --- .editorconfig | 9 +++++ .gitignore | 2 ++ Makefile | 37 ++++++++++++++++++++ dch-autoprovision.spec | 77 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 dch-autoprovision.spec diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..02967c0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.spec] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ae7f2c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dch-autoprovision-*.tar.gz +dch-autoprovision-*.rpm diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9e818af --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +NAME = dch-autoprovision +VERSION = $(shell rpmspec -q --qf '%{VERSION}' $(NAME).spec) +RELEASE = $(shell rpmspec -q --qf '%{RELEASE}' $(NAME).spec) +ARCH = $(shell uname -m) + +GIT_REV = HEAD + +RPM = $(NAME)-$(VERSION)-$(RELEASE).$(ARCH).rpm +SRPM = $(NAME)-$(VERSION)-$(RELEASE).src.rpm + +define rpmbuild + rpmbuild \ + -D "_topdir ${PWD}" \ + -D '_builddir %_topdir' \ + -D '_rpmdir %_topdir' \ + -D '_sourcedir %_topdir' \ + -D '_specdir %_topdir' \ + -D '_srcrpmdir %_topdir' \ + +endef + +sources: $(NAME)-$(VERSION).tar.gz + +rpm: $(ARCH)/$(RPM) + +srpm: $(SRPM) + +$(NAME)-$(VERSION).tar.gz: + git archive --format=tar.gz --prefix $(NAME)-$(VERSION)/ $(GIT_REV) > $@ + +$(RPM): + $(rpmbuild) -bb $(NAME).spec + +$(SRPM): + $(rpmbuild) -bs $(NAME).spec + +.PHONY: rpm srpm diff --git a/dch-autoprovision.spec b/dch-autoprovision.spec new file mode 100644 index 0000000..0e9b9f9 --- /dev/null +++ b/dch-autoprovision.spec @@ -0,0 +1,77 @@ +%global dch_libexecdir %{_libexecdir}/dch +%global dch_datadir %{_datarootdir}/dch + +%define _debugsource_template %{nil} + +Name: dch-autoprovision +Version: 1 +Release: %autorelease +Summary: Automation for provisioning hosts on Dustin's infrastructure. + +License: 0BSD +URL: https://git.pyrocufflink.net/infra/dch-autoprovision +Source0: %{name}-%{version}.tar.gz + +Requires: /usr/bin/curl +%{systemd_requires} + +%description +%{summary}. + +%prep +%autosetup + + +%build +: + + +%install +%__install -m u=rwx,go=rx -d \ + "${RPM_BUILD_ROOT}%{dch_libexecdir}" +%__install -m u=rwx,go=rx \ + notify-online.sh \ + "${RPM_BUILD_ROOT}%{dch_libexecdir}"/notify-online + +mkdir -p "${RPM_BUILD_ROOT}%{_unitdir}" +%__install -m u=rw,go=r \ + notify-online.service \ + "${RPM_BUILD_ROOT}%{_unitdir}" +mkdir -p "${RPM_BUILD_ROOT}%{_presetdir}" +%__install -m u=rw,go=r \ + notify-online.preset \ + "${RPM_BUILD_ROOT}%{_presetdir}" + +%__install -m u=rwx,go=rx -d \ + "${RPM_BUILD_ROOT}%{dch_datadir}" +%__install -m u=rw,go=r \ + host-provisioner.key \ + "${RPM_BUILD_ROOT}%{dch_datadir}/" + + +%post +%systemd_post notify-online.service + + +%preun +%systemd_preun notify-online.service + + +%posttrans +if [ $1 -eq 1 ]; then + printf 'expiry-time=%s,restrict,pty %s\n' \ + "$(date -d +1hour +%Y%m%d%H%M)" \ + "$(cat %{dch_datadir}/host-provisioner.key)" \ + >> /root/.ssh/authorized_keys +fi + + +%files +%{dch_libexecdir} +%{dch_datadir} +%{_unitdir}/* +%{_presetdir}/* + + +%changelog +%autochangelog