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..476248c --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +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 +O ?= . + +RPM = $(O)/$(NAME)-$(VERSION)-$(RELEASE).$(ARCH).rpm +SRPM = $(0)$/(NAME)-$(VERSION)-$(RELEASE).src.rpm + +define rpmbuild + rpmbuild \ + -D '_topdir $(shell realpath "$(O)")' \ + -D '_builddir %_topdir' \ + -D '_rpmdir %_topdir' \ + -D '_sourcedir %_topdir' \ + -D '_specdir %_topdir' \ + -D '_srcrpmdir %_topdir' \ + +endef + +rpm: $(O)/$(ARCH)/$(RPM) + +sources: $(O)/$(NAME)-$(VERSION).tar.gz + +srpm: $(O)/$(SRPM) + +$(O)/$(NAME)-$(VERSION).tar.gz: + git archive --format=tar.gz --prefix $(NAME)-$(VERSION)/ $(GIT_REV) > $@ + +$(O)/$(ARCH)/$(RPM): $(O)/$(NAME)-$(VERSION).tar.gz + $(rpmbuild) -bb $(NAME).spec + +$(O)/$(SRPM): $(O)/$(NAME)-$(VERSION).tar.gz + $(rpmbuild) -bs $(NAME).spec + +.PHONY: rpm srpm diff --git a/dch-autoprovision.spec b/dch-autoprovision.spec new file mode 100644 index 0000000..d5d69a1 --- /dev/null +++ b/dch-autoprovision.spec @@ -0,0 +1,78 @@ +%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 + +BuildRequires: systemd-rpm-macros +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