diff --git a/.gitignore b/.gitignore index 6765678..31e6a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ venv/ credentials.ini .idea *.iml +*.snap diff --git a/README.rst b/README.rst index b822ac3..a7f6aae 100644 --- a/README.rst +++ b/README.rst @@ -9,9 +9,23 @@ DNS01 challange for domains managed on `Loopia `_ 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. diff --git a/setup.py b/setup.py index 2b64dbe..c0a7fdc 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -33,8 +53,8 @@ ], }, entry_points={ - "certbot.plugins": [ - "dns-loopia = certbot_dns_loopia:LoopiaAuthenticator", + 'certbot.plugins': [ + 'dns-loopia = certbot_dns_loopia:LoopiaAuthenticator', ], }, classifiers=[ diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 100644 index 0000000..1782e06 --- /dev/null +++ b/snap/hooks/post-refresh @@ -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 diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..f5240b1 --- /dev/null +++ b/snap/snapcraft.yaml @@ -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