Skip to content

Commit 88376ac

Browse files
committed
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
1 parent 812dce1 commit 88376ac

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

linuxdeploy-plugin-conda.sh

+41
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fi
99

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

12+
CONDA_SKIP_ADJUST_PATHS=${CONDA_SKIP_ADJUST_PATHS:-"1"}
1213
ARCH="${ARCH:-"$(uname -m)"}"
1314

1415
show_usage() {
@@ -23,6 +24,7 @@ show_usage() {
2324
echo " PIP_REQUIREMENTS=\"packageA packageB -r requirements.txt -e git+https://...\""
2425
echo " PIP_PREFIX=\"AppDir/usr/share/conda\""
2526
echo " ARCH=\"$ARCH\" (supported values: x86_64, i368, i686)"
27+
echo " CONDA_SKIP_ADJUST_PATHS=\"1\" (default: skip)"
2628
echo " CONDA_SKIP_CLEANUP=\"[all;][conda-pkgs;][__pycache__;][strip;][.a;][cmake;][doc;][man;][site-packages;]\""
2729
}
2830

@@ -187,6 +189,45 @@ for i in usr/conda/bin/*; do
187189
done
188190
popd
189191

192+
# adjust absolute paths, by default skipped via $CONDA_SKIP_ADJUST_PATHS
193+
if [ "$CONDA_SKIP_ADJUST_PATHS" != "1" ]; then
194+
# disable history substitution, b/c we use ! in quoted strings
195+
set +H
196+
APPDIR_FULL="$(pwd)/$APPDIR"
197+
pushd "$APPDIR_FULL"
198+
# NOTE: --follow-symlinks is only working for GNU sed
199+
# replace absolute paths in some specific files (regex could result in false replacements in other files)
200+
[ -f usr/conda/etc/profile.d/conda.sh ] && sed -i --follow-symlinks "s|'$APPDIR_FULL|\"\${APPDIR}\"'|g" usr/conda/etc/profile.d/conda.sh
201+
[ -f usr/conda/etc/profile.d/conda.sh ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/etc/profile.d/conda.sh
202+
[ -f usr/conda/etc/profile.d/conda.csh ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/etc/profile.d/conda.csh
203+
[ -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
204+
# generic files in usr/conda/bin/ and usr/conda/condabin/
205+
for i in usr/conda/bin/* usr/conda/condabin/*; do
206+
[ -f "$i" ] || continue
207+
# shebangs
208+
sed -i --follow-symlinks "s|^#!$APPDIR_FULL/usr/conda/bin/|#!/usr/bin/env |" "$i"
209+
# perl assignments (must be before bash assignments)
210+
sed -ri --follow-symlinks "s|^(my.*=[[:space:]]*\")$APPDIR_FULL|\1\$ENV{APPDIR} . \"|g" "$i"
211+
# bash assignments
212+
sed -ri --follow-symlinks "s|(=[[:space:]]*\")$APPDIR_FULL|\1\${APPDIR}|g" "$i"
213+
done
214+
# specific files in usr/conda/bin/ (regex could result in false replacements in other files)
215+
[ -f usr/conda/bin/python3-config ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/bin/python3-config
216+
[ -f usr/conda/bin/ncursesw6-config ] && sed -i --follow-symlinks "s|$APPDIR_FULL|\${APPDIR}|g" usr/conda/bin/ncursesw6-config
217+
popd
218+
219+
# generate linuxdeploy-plugin-conda-hook
220+
mkdir -p "$APPDIR"/apprun-hooks
221+
cat > "$APPDIR"/apprun-hooks/linuxdeploy-plugin-conda-hook.sh <<\EOF
222+
# generated by linuxdeploy-plugin-conda
223+
224+
# export APPDIR variable to allow for running from extracted AppDir as well
225+
export APPDIR="${APPDIR:-$(readlink -f "$(dirname "$0")")}"
226+
# export PATH to allow /usr/bin/env shebangs to use the supplied applications
227+
export PATH="$APPDIR"/usr/bin:"$PATH"
228+
EOF
229+
230+
fi
190231

191232
# remove bloat, optionally skipped via $CONDA_SKIP_CLEANUP
192233
IFS=';' read -ra cleanup <<< "$CONDA_SKIP_CLEANUP"

0 commit comments

Comments
 (0)