diff --git a/.gitignore b/.gitignore index ff1b1ea..d2d9601 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dist/ tmp/ venv/ credentials.ini +*.snap \ No newline at end of file diff --git a/README.rst b/README.rst index 82e4580..117200b 100644 --- a/README.rst +++ b/README.rst @@ -6,9 +6,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 feb7dd4..bbfc8f6 100644 --- a/setup.py +++ b/setup.py @@ -1,52 +1,67 @@ +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.0' +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.0", - description="Loopia DNS authentication plugin for Certbot", + name='certbot-dns-loopia', + version=version, + description='Loopia DNS authentication plugin for Certbot', long_description=long_desc, - license="BSD", - author="Andreas Runfalk", - author_email="andreas@runfalk.se", - url="https://www.github.com/runfalk/certbot-loopia", - py_modules=["certbot_dns_loopia"], - install_requires=[ - "acme>=1.8.0", - "certbot>=1.7.0", - "loopialib>=0.2.0", - "zope.interface>=4.4.0", - ], + license='BSD', + author='Andreas Runfalk', + author_email='andreas@runfalk.se', + url='https://www.github.com/runfalk/certbot-loopia', + py_modules=['certbot_dns_loopia'], + install_requires=install_requires, extras_require={ - "dev": [ - "pytest", - "wheel", + 'dev': [ + 'pytest', + 'wheel', ], }, entry_points={ - "certbot.plugins": [ - "dns-loopia = certbot_dns_loopia:LoopiaAuthenticator", + 'certbot.plugins': [ + 'dns-loopia = certbot_dns_loopia:LoopiaAuthenticator', ], }, classifiers=[ - "Development Status :: 2 - Pre-Alpha", - "Environment :: Plugins", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Programming Language :: Python", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Topic :: Internet :: Name Service (DNS)", - "Topic :: System :: Systems Administration", - "Topic :: Utilities", + 'Development Status :: 2 - Pre-Alpha', + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Topic :: Internet :: Name Service (DNS)', + 'Topic :: System :: Systems Administration', + 'Topic :: Utilities', ], ) 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