diff --git a/linuxdeploy-plugin-conda.sh b/linuxdeploy-plugin-conda.sh index f798100..88815b8 100755 --- a/linuxdeploy-plugin-conda.sh +++ b/linuxdeploy-plugin-conda.sh @@ -9,6 +9,7 @@ fi script=$(readlink -f "$0") +CONDA_SKIP_ADJUST_PATHS=${CONDA_SKIP_ADJUST_PATHS:-"1"} ARCH="${ARCH:-"$(uname -m)"}" show_usage() { @@ -23,6 +24,7 @@ show_usage() { echo " PIP_REQUIREMENTS=\"packageA packageB -r requirements.txt -e git+https://...\"" echo " PIP_PREFIX=\"AppDir/usr/share/conda\"" echo " ARCH=\"$ARCH\" (supported values: x86_64, i368, i686)" + echo " CONDA_SKIP_ADJUST_PATHS=\"1\" (default: skip)" echo " CONDA_SKIP_CLEANUP=\"[all;][conda-pkgs;][__pycache__;][strip;][.a;][cmake;][doc;][man;][site-packages;]\"" } @@ -187,6 +189,41 @@ for i in usr/conda/bin/*; do done popd +# adjust absolute paths, by default skipped via $CONDA_SKIP_ADJUST_PATHS +if [ "$CONDA_SKIP_ADJUST_PATHS" != "1" ]; then + # disable history substitution, b/c we use ! in quoted strings + set +H + APPDIR_FULL="$(pwd)/$APPDIR" + # replace absolute paths in some scripts + sed -i "s|'$APPDIR_FULL|\"\${APPDIR}\"'|g" "$APPDIR"/usr/conda/etc/profile.d/conda.sh + sed -i "s|$APPDIR_FULL|\${APPDIR}|g" "$APPDIR"/usr/conda/etc/profile.d/conda.csh + sed -i "s|$APPDIR_FULL|\$APPDIR|g" "$APPDIR"/usr/conda/etc/fish/conf.d/conda.fish + sed -i "s|^#!$APPDIR_FULL/usr/conda/bin/|#!/usr/bin/env |" "$APPDIR"/usr/conda/condabin/conda + sed -i "s|$APPDIR_FULL|\${APPDIR}|g" "$APPDIR"/usr/bin/python3-config + sed -i "s|$APPDIR_FULL|\${APPDIR}|g" "$APPDIR"/usr/bin/python3.8-config + sed -i "s|$APPDIR_FULL|\${APPDIR}|g" "$APPDIR"/usr/bin/ncursesw6-config + # perl + sed -i "s|^#!$APPDIR_FULL/usr/conda/bin/|#!/usr/bin/env |" "$APPDIR"/usr/bin/c_rehash + sed -i "s|= \"$APPDIR_FULL|= \$ENV{APPDIR} . \"|g" "$APPDIR"/usr/bin/c_rehash + pushd "$APPDIR" + for i in usr/conda/bin/*; do + sed -i "s|^#!$APPDIR_FULL/usr/conda/bin/|#!/usr/bin/env |" "$i" + sed -i "s|=\"$APPDIR_FULL|=\"\${APPDIR}|g" "$i" + done + popd + + # generate linuxdeploy-plugin-conda-hook + mkdir -p "$APPDIR"/apprun-hooks + cat > "$APPDIR"/apprun-hooks/linuxdeploy-plugin-conda-hook.sh <<\EOF +# generated by linuxdeploy-plugin-conda + +# export APPDIR variable to allow for running from extracted AppDir as well +export APPDIR=${APPDIR:-$(readlink -f $(dirname "$0"))} +# export PATH to allow /usr/bin/env shebangs to use the supplied applications +export PATH="$APPDIR"/usr/bin:"$PATH" +EOF + +fi # remove bloat, optionally skipped via $CONDA_SKIP_CLEANUP IFS=';' read -ra cleanup <<< "$CONDA_SKIP_CLEANUP"