Skip to content

Commit

Permalink
Add files to create a snap package
Browse files Browse the repository at this point in the history
  • Loading branch information
kmpm committed Jun 1, 2022
1 parent be409ff commit 1a3d422
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ venv/
credentials.ini
.idea
*.iml
*.snap
16 changes: 15 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ DNS01 challange for domains managed on `Loopia <https://www.loopia.se/>`_ DNS.

Installing
----------

Via snap (requires certbot to be installed via snap)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block::
$ sudo snap install certbot-dns-loopia
$ sudo snap set certbot trust-plugin-with-root=ok
$ sudo snap connect certbot:plugin certbot-dns-loopia
$ sudo snap connect certbot-dns-loopia:certbot-metadata certbot:certbot-metadata
Via pip3
~~~~~~~~
.. code-block::
$ sudo pip install certbot-dns-loopia
$ sudo pip3 install certbot-dns-loopia
Note that you should normally install this as ``root``, unless you know what
you are doing.
Expand Down
36 changes: 28 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import os
from setuptools import setup


try:
long_desc = open("README.rst").read()
except FileNotFoundError:
print("Skipping README.rst for long description as it was not found")
long_desc = None
version = '1.0.1'
cb_required = '1.8.0'

install_requires = [
'loopialib>=0.2.0',
'zope.interface>=4.4.0',
]


if not os.environ.get('SNAP_BUILD'):
install_requires.extend([
f'acme>={cb_required}',
f'certbot>={cb_required}',
])


if os.environ.get('SNAP_BUILD'):
install_requires.append('packaging')


BASE_PATH = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(BASE_PATH, 'README.rst')) as f:
long_desc = f.read()



setup(
name="certbot-dns-loopia",
version="1.0.1",
version=version,
description="Loopia DNS authentication plugin for Certbot",
long_description=long_desc,
long_description_content_type="text/x-rst",
Expand All @@ -33,8 +53,8 @@
],
},
entry_points={
"certbot.plugins": [
"dns-loopia = certbot_dns_loopia:LoopiaAuthenticator",
'certbot.plugins': [
'dns-loopia = certbot_dns_loopia:LoopiaAuthenticator',
],
},
classifiers=[
Expand Down
21 changes: 21 additions & 0 deletions snap/hooks/post-refresh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh -e
# This file is based on tools/snap/generate_dnsplugins_postrefreshhook.sh of Certbot
# get certbot version
if [ ! -f "$SNAP/certbot-shared/certbot-version.txt" ]; then
echo "No certbot version available; not doing version comparison check" >> "$SNAP_DATA/debuglog"
exit 0
fi
cb_installed=$(cat $SNAP/certbot-shared/certbot-version.txt)

# get required certbot version for plugin. certbot version must be at least the plugin's
# version. note that this is not the required version in setup.py, but the version number itself.
cb_required=$(grep -oP "cb_required = '\K.*(?=')" $SNAP/setup.py)


$SNAP/bin/python3 -c "import sys; from packaging import version; sys.exit(1) if \
version.parse('$cb_installed') < version.parse('$cb_required') else sys.exit(0)" || exit_code=$?
if [ "$exit_code" -eq 1 ]; then
echo "Certbot is version $cb_installed but needs to be at least $cb_required before" \
"this plugin can be updated; will try again on next refresh."
exit 1
fi
39 changes: 39 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: certbot-dns-loopia
summary: Loopia DNS authentication plugin for Certbot
description: Loopia DNS authentication plugin for Certbot
confinement: strict
grade: stable
base: core20

adopt-info: certbot-dns-loopia

parts:
certbot-dns-loopia:
plugin: python
source: .
override-pull: |
snapcraftctl pull
snapcraftctl set-version `grep ^version $SNAPCRAFT_PART_SRC/setup.py | cut -f2 -d= | tr -d "'[:space:]"`
build-environment:
- SNAP_BUILD: "True"

certbot-metadata:
plugin: dump
source: .
stage: [setup.py, certbot-shared]
override-pull: |
snapcraftctl pull
mkdir -p $SNAPCRAFT_PART_SRC/certbot-shared
slots:
certbot:
interface: content
content: certbot-1
read:
- $SNAP/lib/python3.8/site-packages

plugs:
certbot-metadata:
interface: content
content: metadata-1
target: $SNAP/certbot-shared

0 comments on commit 1a3d422

Please sign in to comment.