certbot/tools/snap/generate_dnsplugins_postrefreshhook.sh
ohemorange fc864543a7
Simplify/document snap creation (#8404)
This PR adds the following documentation improvements to fix https://github.com/certbot/certbot/issues/7958:

- Simplify building external plugins
- Separate out certbot snap instructions from plugin instructions
- Mention that dnsimple is just an example for the plugin instructions
- Mention remote build for other architectures
- Mention snap doc exists elsewhere in developer guide (`contributing.rst`)

* Set up generate_dnsplugins_all.sh for all files and parametrize snapcraft and postrefreshhook files

* Create constraints file in the generate_dnsplugins_all script

* Separate out plugin and certbot snaps and update instructions

* Add remote build instructions

* Add pointers to the README to contributing.rst
2020-10-27 10:22:40 -07:00

33 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
# Generate the hooks/post-refresh file for a DNS plugin
# Usage: bash generate_dnsplugins_postrefreshhook.sh path/to/dns/plugin
# For example, from the certbot home directory:
# tools/snap/generate_dnsplugins_postrefreshhook.sh certbot-dns-dnsimple
set -eu
PLUGIN_PATH=$1
mkdir -p "${PLUGIN_PATH}/snap/hooks"
cat <<EOF > "${PLUGIN_PATH}/snap/hooks/post-refresh"
#!/bin/sh -e
# This file is generated by tools/generate_dnsplugins_postrefreshhook.sh and should not be edited manually.
# 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 "version = '\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
EOF