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 paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes #12, #25 and #32
  • Loading branch information
knarfS committed Jun 12, 2021
1 parent 0ead8b8 commit 8df6f50
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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,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"
Expand Down

0 comments on commit 8df6f50

Please sign in to comment.