Files
netoik-rp/netoik-rp.spec
samuel c76193dcc5
All checks were successful
Continuous Integration / lint_n_build (push) Successful in 35s
Continuous Delivery / build_n_upload (push) Successful in 25s
feat: adapt on nginx versionning
2026-08-30 14:27:43 +02:00

112 lines
3.8 KiB
RPMSpec

%define debug_package %{nil}
Name: %(make name)
Epoch: %(make epoch)
Version: %(make version)
Release: %(make release)
Summary: %(make summary)
License: %(make license)
URL: %(make url)
Source0: %(make source0)
Buildarch: %(make arch)
BuildRequires: make
Requires: nginx = %{epoch}:%{version}-%(make release_nginx)
Requires: python3
Requires: python-devel
Requires: (augeas-devel or augeas-libs)
Requires: gcc
Requires: openssl
%description
Install the reverse proxy called nginx with a predefined configuration and with TLS certificates attached to netoik.io
%prep
%autosetup -v
%install
%make_install
%post
if [ -z $SKIP_CERTBOT ]; then
# Check required OVH variables
if [ -z $OVH_ENDPOINT ]; then echo "Missing env var OVH_ENDPOINT!" 1>&2; exit 1; fi
if [ -z $OVH_APPLICATION_NAME ]; then echo "Missing env var OVH_APPLICATION_KEY!" 1>&2; exit 1; fi
if [ -z $OVH_APPLICATION_DESCRIPTION ]; then echo "Missing env var OVH_APPLICATION_DESCRIPTION!" 1>&2; exit 1; fi
if [ -z $OVH_APPLICATION_KEY ]; then echo "Missing env var OVH_APPLICATION_KEY!" 1>&2; exit 1; fi
if [ -z $OVH_APPLICATION_SECRET ]; then echo "Missing env var OVH_APPLICATION_SECRET!" 1>&2; exit 1; fi
if [ -z $OVH_CONSUMER_KEY ]; then echo "Missing env var OVH_CONSUMER_KEY!" 1>&2; exit 1; fi
# Replace secrets in ovh.ini
envsubst < %{_sysconfdir}/certbot/ovh.ini > %{_sysconfdir}/certbot/.ovh.ini.new
mv %{_sysconfdir}/certbot/.ovh.ini.new %{_sysconfdir}/certbot/ovh.ini
chmod 600 %{_sysconfdir}/certbot/ovh.ini
# Create virtualenv with certot
if [ ! -d "/opt/certbot" ]; then
python3 -m venv /opt/certbot
/opt/certbot/bin/pip install --upgrade pip certbot certbot-nginx certbot-dns-ovh
ln --symbolic --force --target-directory %{_sbindir} /opt/certbot/bin/certbot
fi
# Create certbot certificates
if ! certbot certificates --cert-name netoik.io | grep --quiet netoik.io; then
certbot certonly --cert-name netoik.io \
--non-interactive \
--agree-tos \
--email samuel.campos@netoik.io \
--dns-ovh --dns-ovh-credentials %{_sysconfdir}/certbot/ovh.ini \
-d *.netoik.io \
-d *.samuel-campos.fr
fi
else
# Skipping certbot, so create self-signed certificate
mkdir --parents /etc/letsencrypt/live/netoik.io
openssl req -newkey rsa:4096 \
-nodes \
-keyout /etc/letsencrypt/live/netoik.io/privkey.pem \
-x509 \
-days 365 \
-out /etc/letsencrypt/live/netoik.io/fullchain.pem \
-subj "/C=US/ST=State/L=City/O=Organization/OU=Department/CN=netoik.io"
fi
# Create ssl dh params if not already exists
if [ ! -f "%{_sysconfdir}/letsencrypt/ssl-dhparams.pem" ]; then
openssl dhparam -out %{_sysconfdir}/letsencrypt/ssl-dhparams.pem 2048
fi
# Restart services
systemctl daemon-reload
systemctl reenable nginx.service certbot-renew.timer
systemctl restart nginx.service certbot-renew.timer
%postun
# Remove folders after uninstall
if [ $1 == 0 ]; then
/opt/certbot/bin/certbot delete --cert-name netoik.io --non-interactive
rm --recursive --force /opt/certbot
rm --recursive --force %{_sysconfdir}/certbot
fi
%files
%config %attr(644, root, root) %{_sysconfdir}/nginx/conf.d/0_security.conf
%config %attr(644, root, root) %{_sysconfdir}/nginx/conf.d/z_default.conf
%attr(755, root, root) %dir %{_sysconfdir}/certbot
%attr(600, root, root) %{_sysconfdir}/certbot/ovh.ini
%attr(644, root, root) %{_unitdir}/certbot-renew.timer
%attr(644, root, root) %{_unitdir}/certbot-renew.service
%attr(755, root, root) %{_sbindir}/certbot_renew
%ghost %attr(755, root, root) %dir /opt/certbot
%ghost %attr(755, root, root) %{_sbindir}/certbot
%ghost %attr(644, root, root) %{_sysconfdir}/letsencrypt/ssl-dhparams.pem
%changelog
%autochangelog