From 07491c6dbfe0eeb19ce85869893744163d99acb5 Mon Sep 17 00:00:00 2001 From: Frank Stettner Date: Thu, 10 Jun 2021 19:18:08 +0200 Subject: [PATCH] Fix absolute paths in scripts This removes some of the wrong, absolute paths pointing to the build location of the AppImage by using a different shebang and some environment variables, set by the linuxdeploy-plugin-conda-hook at the AppImage start. Fixes #12, fixes #25 and fixes #32 --- linuxdeploy-plugin-conda.sh | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/linuxdeploy-plugin-conda.sh b/linuxdeploy-plugin-conda.sh index f798100..e5ee238 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,44 @@ 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" + pushd "$APPDIR_FULL" + # NOTE: --follow-symlinks is only working for GNU sed + # replace absolute paths in some specific files (regex could result in false replacements in other files) + [ -f usr/conda/etc/profile.d/conda.sh ] && sed -i --follow-symlinks "s|'$APPDIR_FULL|\"\${APPDIR}\"'|g" usr/conda/etc/profile.d/conda.sh + [ -f usr/conda/etc/profile.d/conda.csh ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/etc/profile.d/conda.csh + [ -f usr/conda/etc/fish/conf.d/conda.fish ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\$APPDIR|g" usr/conda/etc/fish/conf.d/conda.fish + # generic files in usr/conda/bin/ and usr/conda/condabin/ + for i in usr/conda/bin/* usr/conda/condabin/*; do + [ -f "$i" ] || continue + # shebangs + sed -i --follow-symlinks "s|^#!$APPDIR_FULL/usr/conda/bin/|#!/usr/bin/env |" "$i" + # perl assignments (must be before bash assignments) + sed -ri --follow-symlinks "s|^(my.*=[[:space:]]*\")$APPDIR_FULL|\1\$ENV{APPDIR} . \"|g" "$i" + # bash assignments + sed -ri --follow-symlinks "s|(=[[:space:]]*\")$APPDIR_FULL|\1\${APPDIR}|g" "$i" + done + # specific files in usr/conda/bin/ (regex could result in false replacements in other files) + [ -f usr/conda/bin/python3-config ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/bin/python3-config + [ -f usr/conda/bin/ncursesw6-config ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/bin/ncursesw6-config + 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"