python-wrapper.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. SCRIPT="$(readlink -f -- $0)"
  3. SCRIPTPATH="$(dirname $SCRIPT)"
  4. APPDIR="${APPDIR:-$SCRIPTPATH/../..}"
  5. # Configure the environment
  6. if [ -d "${APPDIR}/usr/share/tcltk" ]; then
  7. export TCL_LIBRARY="$(ls -d ${APPDIR}/usr/share/tcltk/tcl* | tail -1)"
  8. export TK_LIBRARY="$(ls -d ${APPDIR}/usr/share/tcltk/tk* | tail -1)"
  9. export TKPATH="${TK_LIBRARY}"
  10. fi
  11. # Resolve symlinks within the image
  12. prefix="opt/{{PYTHON}}"
  13. nickname="{{PYTHON}}"
  14. executable="${APPDIR}/${prefix}/bin/${nickname}"
  15. if [ -L "${executable}" ]; then
  16. nickname="$(basename $(readlink -f ${executable}))"
  17. fi
  18. for opt in "$@"
  19. do
  20. [ "${opt:0:1}" != "-" ] && break
  21. if [[ "${opt}" =~ "I" ]] || [[ "${opt}" =~ "E" ]]; then
  22. # Environment variables are disabled ($PYTHONHOME). Let's run in a safe
  23. # mode from the raw Python binary inside the AppImage
  24. "$APPDIR/${prefix}/bin/${nickname}" "$@"
  25. exit "$?"
  26. fi
  27. done
  28. # But don't resolve symlinks from outside!
  29. if [[ "${ARGV0}" =~ "/" ]]; then
  30. executable="$(cd $(dirname ${ARGV0}) && pwd)/$(basename ${ARGV0})"
  31. elif [[ "${ARGV0}" != "" ]]; then
  32. executable=$(which "${ARGV0}")
  33. fi
  34. # Wrap the call to Python in order to mimic a call from the source
  35. # executable ($ARGV0), but potentially located outside of the Python
  36. # install ($PYTHONHOME)
  37. (PYTHONHOME="${APPDIR}/${prefix}" exec -a "${executable}" "$APPDIR/${prefix}/bin/${nickname}" "$@")
  38. exit "$?"