diff --git a/certbot.wrapper b/certbot.wrapper deleted file mode 100755 index 83576e47c..000000000 --- a/certbot.wrapper +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# TODO: We may want to consider rewriting this script in Python. See -# https://github.com/certbot/certbot/issues/8251 for more info. -set -e - -# This code is based on snapcraft's own patch to work around this problem at -# https://github.com/snapcore/snapcraft/blob/a97fb5c7ea553a1bd20f4887a7c3393e75761890/patches/ctypes_init.diff. -# We may not build the Certbot snap for all of these architectures (and as of -# writing this we do not), but we keep the code for them to avoid having to -# solve this problem again in the future if we add support for new -# architectures. -case "${SNAP_ARCH}" in - 'arm64') - ARCH_TRIPLET='aarch64-linux-gnu';; - 'armhf') - ARCH_TRIPLET='arm-linux-gnueabihf';; - 'i386') - ARCH_TRIPLET='i386-linux-gnu';; - 'ppc64el') - ARCH_TRIPLET='powerpc64le-linux-gnu';; - 'powerpc') - ARCH_TRIPLET='powerpc-linux-gnu';; - 'amd64') - ARCH_TRIPLET='x86_64-linux-gnu';; - 's390x') - ARCH_TRIPLET='s390x-linux-gnu';; - *) - echo "Unrecongized value of SNAP_ARCH: ${SNAP_ARCH}" >&2 - exit 1 -esac - -export CERTBOT_AUGEAS_PATH="${SNAP}/usr/lib/${ARCH_TRIPLET}/libaugeas.so.0" - -CERTBOT_PLUGIN_PATH="$(curl -s --unix-socket /run/snapd.socket "http://localhost/v2/connections?snap=certbot&interface=content" | jq -r '.result.established | map(select(.plug.plug == "plugin" and ."plug-attrs".content == "certbot-1") | "/snap/"+.slot.snap+"/current/lib/python3.8/site-packages/" ) | join(":")')" -export CERTBOT_PLUGIN_PATH - -exec certbot "$@" --preconfigured-renewal diff --git a/certbot/certbot/main.py b/certbot/certbot/main.py index c70eac406..34d3db74c 100644 --- a/certbot/certbot/main.py +++ b/certbot/certbot/main.py @@ -22,6 +22,8 @@ def main(cli_args=None): :rtype: `str` or `int` or `None` """ + cli_args = cli_args if cli_args else sys.argv[1:] + if os.environ.get('CERTBOT_SNAPPED') == 'True': cli_args = _prepare_snap_env(cli_args) @@ -35,15 +37,15 @@ def _prepare_snap_env(cli_args): elif snap_arch == 'armhf': arch_triplet = 'arm-linux-gnueabihf' elif snap_arch == 'i386': - arch_triplet = 'arm-linux-gnueabihf' + arch_triplet = 'i386-linux-gnu' elif snap_arch == 'ppc64el': - arch_triplet = 'arm-linux-gnueabihf' + arch_triplet = 'powerpc64le-linux-gnu' elif snap_arch == 'powerpc': - arch_triplet = 'arm-linux-gnueabihf' + arch_triplet = 'powerpc-linux-gnu' elif snap_arch == 'amd64': - arch_triplet = 'arm-linux-gnueabihf' + arch_triplet = 'x86_64-linux-gnu' elif snap_arch == 's390x': - arch_triplet = 'arm-linux-gnueabihf' + arch_triplet = 's390x-linux-gnu' else: print('Unrecognized value of SNAP_ARCH: {0}'.format(snap_arch), file=sys.stderr) sys.exit(1) @@ -59,8 +61,10 @@ def _prepare_snap_env(cli_args): try: response.raise_for_status() data = response.json() + print(data) except (HTTPError, JSONDecodeError): - print('Error while trying to fetch Certbot snap connections', file=sys.stderr) + print('An error occured while fetching Certbot snap plugins.', file=sys.stderr) + print('Please run "sudo snap install core" in your terminal and try again.', file=sys.stderr) sys.exit(1) connections = ['/snap/{0}/current/lib/python3.8/site-packages/'.format(item['slot']['snap']) @@ -70,7 +74,6 @@ def _prepare_snap_env(cli_args): os.environ['CERTBOT_PLUGIN_PATH'] = ':'.join(connections) - cli_args = cli_args if cli_args else [] cli_args.append('--preconfigured-renewal') return cli_args diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 2acbfa2f6..d0a8adba8 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -20,13 +20,13 @@ adopt-info: certbot apps: certbot: - command: certbot + command: bin/certbot environment: PATH: "$SNAP/bin:$SNAP/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" AUGEAS_LENS_LIB: "$SNAP/usr/share/augeas/lenses/dist" CERTBOT_SNAPPED: "True" renew: - command: certbot -q renew + command: bin/certbot -q renew daemon: oneshot environment: PATH: "$SNAP/bin:$SNAP/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" @@ -71,9 +71,6 @@ parts: - python3-distutils - python3-pkg-resources - python3.8-minimal - # added for certbot.wrapper script: - - curl - - jq # To build cryptography and cffi if needed build-packages: [gcc, libffi-dev, libssl-dev, git, libaugeas-dev, python3-dev] build-environment: