Advertisement
roracle

AppRun-bombono

Feb 4th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.27 KB | None | 0 0
  1. #!/bin/bash
  2. # Provide options for loading environment variables in AppRun.conf rather than loading them all by default
  3. # Created by simonizor
  4.  
  5. # Create AppRun variable defaults in case config file is not present
  6. APPRUN_SET_PATH="TRUE"
  7. APPRUN_SET_LD_LIBRARY_PATH="TRUE"
  8. APPRUN_SET_PYTHONPATH="TRUE"
  9. APPRUN_SET_PYTHONHOME="TRUE"
  10. APPRUN_SET_PYTHONDONTWRITEBYTECODE="TRUE"
  11. APPRUN_SET_XDG_DATA_DIRS="TRUE"
  12. APPRUN_SET_PERLLIB="TRUE"
  13. APPRUN_SET_GSETTINGS_SCHEMA_DIR="TRUE"
  14. APPRUN_SET_QT_PLUGIN_PATH="TRUE"
  15.  
  16. # Get AppRun running directory
  17. REALPATH="$(readlink -f $0)"
  18. RUNNING_DIR="$(dirname "$REALPATH")"
  19.  
  20. # Load config file if present
  21. [ -f "$RUNNING_DIR/AppRun.conf" ] && . "$RUNNING_DIR/AppRun.conf"
  22.  
  23. # Set AppRun environment variables based on config settings
  24. [ "$APPRUN_SET_PATH" = "TRUE" ] && export PATH="$RUNNING_DIR"/usr/bin/:"$RUNNING_DIR"/usr/sbin/:"$RUNNING_DIR"/usr/games/:"$RUNNING_DIR"/bin/:"$RUNNING_DIR"/sbin/:"$PATH"
  25. [ "$APPRUN_SET_LD_LIBRARY_PATH" = "TRUE" ] && export LD_LIBRARY_PATH="$RUNNING_DIR"/usr/lib/:"$RUNNING_DIR"/usr/lib/i386-linux-gnu/:"$RUNNING_DIR"/usr/lib/x86_64-linux-gnu/:"$RUNNING_DIR"/usr/lib32/:"$RUNNING_DIR"/usr/lib64/:"$RUNNING_DIR"/lib/:"$RUNNING_DIR"/lib/i386-linux-gnu/:"$RUNNING_DIR"/lib/x86_64-linux-gnu/:"$RUNNING_DIR"/lib32/:"$RUNNING_DIR"/lib64/:"${LD_LIBRARY_PATH}"
  26. [ "$APPRUN_SET_PYTHONPATH" = "TRUE" ] && export PYTHONPATH="$RUNNING_DIR"/usr/share/pyshared/:"$PYTHONPATH"
  27. [ "$APPRUN_SET_PYTHONHOME" = "TRUE" ] && export PYTHONHOME="$RUNNING_DIR"/usr/:"$PYTHONHOME"
  28. [ "$APPRUN_SET_PYTHONDONTWRITEBYTECODE" = "TRUE" ] && export PYTHONDONTWRITEBYTECODE=1
  29. [ "$APPRUN_SET_XDG_DATA_DIRS" = "TRUE" ] && export XDG_DATA_DIRS="$RUNNING_DIR"/usr/share/:"$XDG_DATA_DIRS"
  30. [ "$APPRUN_SET_PERLLIB" = "TRUE" ] && export PERLLIB="$RUNNING_DIR"/usr/share/perl5/:"$RUNNING_DIR"/usr/lib/perl5/:"$PERLLIB"
  31. [ "$APPRUN_SET_GSETTINGS_SCHEMA_DIR" = "TRUE" ] && export GSETTINGS_SCHEMA_DIR="$RUNNING_DIR"/usr/share/glib-2.0/schemas/:"$GSETTINGS_SCHEMA_DIR"
  32. [ "$APPRUN_SET_QT_PLUGIN_PATH" = "TRUE" ] && export QT_PLUGIN_PATH="$RUNNING_DIR"/usr/lib/qt4/plugins/:"$RUNNING_DIR"/usr/lib/i386-linux-gnu/qt4/plugins/:"$RUNNING_DIR"/usr/lib/x86_64-linux-gnu/qt4/plugins/:"$RUNNING_DIR"/usr/lib32/qt4/plugins/:"$RUNNING_DIR"/usr/lib64/qt4/plugins/:"$RUNNING_DIR"/usr/lib/qt5/plugins/:"$RUNNING_DIR"/usr/lib/i386-linux-gnu/qt5/plugins/:"$RUNNING_DIR"/usr/lib/x86_64-linux-gnu/qt5/plugins/:"$RUNNING_DIR"/usr/lib32/qt5/plugins/:"$RUNNING_DIR"/usr/lib64/qt5/plugins/:"$QT_PLUGIN_PATH"
  33.  
  34. # Use APPRUN_EXEC variable if it is set otherwise attempt to find .desktop file and Exec line from .desktop file in RUNNING_DIR
  35. if [ -z "$APPRUN_EXEC" ]; then
  36.     DESKTOP_FILE="$(dir -C -w 1 "$RUNNING_DIR/" | grep -m1 '.desktop')"
  37.     if [ ! -z "$DESKTOP_FILE" ]; then
  38.         APPRUN_EXEC="$(grep -m1 'Exec=.*' "$RUNNING_DIR"/"$DESKTOP_FILE" | cut -f2 -d"=" | cut -f1 -d" ")"
  39.         if [ -z "$APPRUN_EXEC" ]; then
  40.             echo "Failed to find Exec line in $DESKTOP_FILE and APPRUN_EXEC variable is not set; exiting..."
  41.             exit 1
  42.         fi
  43.     else
  44.         echo "Failed to find .desktop file in $RUNNING_DIR and APPRUN_EXEC variable is not set; exiting..."
  45.         exit 1
  46.     fi
  47. fi
  48. case "$APPRUN_EXEC" in
  49.     /*) exec "$RUNNING_DIR""$APPRUN_EXEC" "$@";;
  50.     *) exec "$APPRUN_EXEC" "$@";;
  51. esac
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement