Skip to content

Commit

Permalink
Optimize the LD_LIBRARY_PATH environment variable that cannot be obta…
Browse files Browse the repository at this point in the history
…ined when using the sudo command to run the script.
  • Loading branch information
dailingx committed May 11, 2023
1 parent feb6728 commit 2d5ccb4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gui.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

# If it is run with the sudo command, get the complete LD_LIBRARY_PATH environment variable of the system and assign it to the current environment,
# because it will be used later.
if [ -n "$SUDO_USER" ] || [ -n "$SUDO_COMMAND" ] ; then
echo "The sudo command resets the non-essential environment variables, we keep the LD_LIBRARY_PATH variable."
export LD_LIBRARY_PATH=$(sudo -i printenv LD_LIBRARY_PATH)
fi

# This gets the directory the script is run from so pathing can work relative to the script where needed.
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)

Expand Down

0 comments on commit 2d5ccb4

Please sign in to comment.