Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions PINCE.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@ if [ ! -d "${SCRIPTDIR}/.venv/bin" ]; then
echo "Please run \"sh install.sh\" first!"
exit 1
fi
. ${SCRIPTDIR}/.venv/bin/activate

# Preserve env vars to keep settings like theme preferences.
# Debian/Ubuntu does not preserve PATH through sudo even with -E for security reasons
# so we need to force PATH preservation with venv activated user's PATH.
sudo -E --preserve-env=PATH PYTHONDONTWRITEBYTECODE=1 ${SCRIPTDIR}/.venv/bin/python3 ${SCRIPTDIR}/PINCE.py
. ${SCRIPTDIR}/.venv/PINCE/bin/activate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong and makes an error with sh PINCE.sh.

We don't have the PINCE folder inside venv anymore. You can just restore the old line you replaced as that one was fine.

PYTHON="${SCRIPTDIR}/.venv/bin/python3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You named these PYTHON and SCRIPT but use PINCE_PYTHON and PINCE_PATH in the sudo case which will probably fail.

I'd recommend using PINCE_PYTHON and PINCE_PATH here as well. Maybe replace PINCE_PATH with PINCE_PY just to make it clear that we're targeting a .py file.

SCRIPT="${SCRIPTDIR}/PINCE.py"

export PYTHONDONTWRITEBYTECODE=1

if type pkexec &> /dev/null; then
# Preserve env vars to keep settings like theme preferences.
# Pkexec does not support passing all of env via a flag like `-E` so we need to
# rebuild the env and then pass it through.
ENV=()
while IFS='=' read -r key value; do
[ -z "$key" ] && continue
value="${value//\\/\\\\}"
value="${value//\"/\\\"}"
ENV+=("$key=$value")
done < <(env)

pkexec env "${ENV[@]}" "$PYTHON" "$SCRIPT"
elif type sudo &> /dev/null; then
# Debian/Ubuntu does not preserve PATH through sudo even with -E for security reasons
# so we need to force PATH preservation with venv activated user's PATH.
sudo -E --preserve-env=PATH,PYTHONDONTWRITEBYTECODE "$PINCE_PYTHON" "$PINCE_PATH"
else
echo "No supported privilege escalation utility found; please rerun this script as root."
fi
32 changes: 27 additions & 5 deletions ci/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,35 @@ touch AppDir/usr/share/icons/hicolor/scalable/apps/PINCE.svg
# Create main running script
cat > AppRun.sh <<\EOF
#!/bin/bash

if [ "$(id -u)" != "0" ]; then
echo "Please run this AppImage using 'sudo -E'!"
exit 1
if type pkexec &> /dev/null; then
# Preserve env vars to keep settings like theme preferences.
# Pkexec does not support passing all of env via a flag like `-E` so we need to
# rebuild the env and then pass it through.
ENV=()
while IFS='=' read -r key value; do
[ -z "$key" ] && continue
value="${value//\\/\\\\}"
value="${value//\"/\\\"}"
ENV+=("$key=$value")
done < <(env)

pkexec env "${ENV[@]}" "$APPIMAGE"
elif type sudo &> /dev/null; then
# Debian/Ubuntu does not preserve PATH through sudo even with -E for security reasons
# so we need to force PATH preservation with venv activated user's PATH.
sudo -E --preserve-env=PATH,PYTHONDONTWRITEBYTECODE "$APPIMAGE"
else
echo "No supported privilege escalation utility found. Please run this AppImage as root manually."
exit 1
fi
else
export APPDIR="$(dirname "$0")"
export PYTHONHOME="$APPDIR/usr/conda"

"$APPDIR/usr/bin/python3" "$APPDIR/opt/PINCE/PINCE.py"
fi
export APPDIR="$(dirname "$0")"
export PYTHONHOME=$APPDIR/usr/conda
$APPDIR/usr/bin/python3 $APPDIR/opt/PINCE/PINCE.py
EOF
chmod +x AppRun.sh

Expand Down