Skip to content

Commit

Permalink
Fix absolute paths in scripts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
knarfS committed Jun 12, 2021
1 parent 0ead8b8 commit 07491c6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions linuxdeploy-plugin-conda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fi

script=$(readlink -f "$0")

CONDA_SKIP_ADJUST_PATHS=${CONDA_SKIP_ADJUST_PATHS:-"1"}
ARCH="${ARCH:-"$(uname -m)"}"

show_usage() {
Expand All @@ -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;]\""
}

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 07491c6

Please sign in to comment.