From 37d3bdd936e26bc80b7fa2bb93cad513f23558db Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Mon, 10 Aug 2020 11:18:55 +0200 Subject: [PATCH] Bundle SSL_CERT_FILE if in env (e.g. on manylinux) --- python_appimage/appimage/relocate.py | 32 ++++++++++++++++++++++++---- python_appimage/data/apprun.sh | 2 ++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/python_appimage/appimage/relocate.py b/python_appimage/appimage/relocate.py index 2925ea6..5331578 100644 --- a/python_appimage/appimage/relocate.py +++ b/python_appimage/appimage/relocate.py @@ -6,7 +6,7 @@ import sys from ..utils.deps import EXCLUDELIST, PATCHELF, PREFIX, ensure_excludelist, \ ensure_patchelf -from ..utils.fs import make_tree, copy_file, copy_tree, remove_file, remove_tree +from ..utils.fs import copy_file, copy_tree, make_tree, remove_file, remove_tree from ..utils.log import debug, log from ..utils.system import ldd, system from ..utils.template import copy_template, load_template @@ -43,8 +43,20 @@ def tcltk_env_string(python_pkg): # Export TCl/Tk export TCL_LIBRARY="${{APPDIR}}/usr/share/tcltk/tcl{tk_version:}" export TK_LIBRARY="${{APPDIR}}/usr/share/tcltk/tk{tk_version:}" -export TKPATH="${{TK_LIBRARY}}" -'''.format(tk_version=tk_version) +export TKPATH="${{TK_LIBRARY}}"'''.format( + tk_version=tk_version) + else: + return '' + + +def cert_file_env_string(cert_file): + '''Environment for using a bundled certificate + ''' + if cert_file: + return ''' +# Export SSL certificate +export SSL_CERT_FILE="${{APPDIR}}{cert_file:}"'''.format( + cert_file=cert_file) else: return '' @@ -289,6 +301,17 @@ def relocate_python(python=None, appdir=None): copy_tree(tkpath, tcltkdir + '/tk' + tk_version) + # Copy any SSL certificate + cert_file = os.getenv('SSL_CERT_FILE') + if cert_file: + # Package certificates as well for SSL + # (see https://github.com/niess/python-appimage/issues/24) + dirname, basename = os.path.split(cert_file) + make_tree('AppDir' + dirname) + copy_file(cert_file, 'AppDir' + cert_file) + log('INSTALL', basename) + + # Bundle the entry point apprun = APPDIR + '/AppRun' if not os.path.exists(apprun): @@ -297,7 +320,8 @@ def relocate_python(python=None, appdir=None): entrypoint = load_template(entrypoint_path, python=PYTHON_X_Y) dictionary = {'entrypoint': entrypoint, 'shebang': '#! /bin/bash', - 'tcltk-env': tcltk_env_string(PYTHON_PKG)} + 'tcltk-env': tcltk_env_string(PYTHON_PKG), + 'cert-file': cert_file_env_string(cert_file)} _copy_template('apprun.sh', apprun, **dictionary) diff --git a/python_appimage/data/apprun.sh b/python_appimage/data/apprun.sh index a0315d2..b732bcf 100755 --- a/python_appimage/data/apprun.sh +++ b/python_appimage/data/apprun.sh @@ -5,5 +5,7 @@ self="$(readlink -f -- $0)" here="${self%/*}" APPDIR="${APPDIR:-${here}}" {{ tcltk-env }} +{{ cert-file }} + # Call the entry point {{ entrypoint }}