Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.79 KB | None | 0 0
  1. #!/bin/bash
  2. APP_ROOT="$(dirname "$0")"
  3. for ((i=0; i<2; i++)); do APP_ROOT="$(dirname "$APP_ROOT")"; done
  4. APP_ROOT="${APP_ROOT/\/\/}"
  5.  
  6. # Bundle directories
  7. CONTENTS_DIR="$APP_ROOT/Contents"
  8. RES_DIR="$CONTENTS_DIR/Resources"
  9. ETC_DIR="$RES_DIR/etc"
  10. LIB_DIR="$RES_DIR/lib"
  11. BIN_DIR="$RES_DIR/bin"
  12. DATA_DIR="$RES_DIR/share"
  13.  
  14. # Shell environment
  15. export PATH="/bin:/usr/bin:$BIN_DIR"
  16. export BUNDLE_BIN_DIR="$BIN_DIR"
  17. export BUNDLE_LIB_DIR="$LIB_DIR"
  18.  
  19. # XDG environment
  20. export XDG_CONFIG_DIRS="$ETC_DIR/xdg"
  21. export XDG_DATA_DIRS="$DATA_DIR"
  22. export XDG_CONFIG_HOME="$HOME/.config"
  23.  
  24. # GTK environment
  25. export GTK_PATH="$RES_DIR"
  26. export GTK_EXE_PREFIX="$RES_DIR"
  27. export GTK_DATA_PREFIX="$RES_DIR"
  28. export GTK2_RC_FILES="$ETC_DIR/gtk-2.0/gtkrc"
  29. export GTK_IM_MODULE_FILE="$ETC_DIR/gtk-2.0/gtk.immodules"
  30. export GDK_PIXBUF_MODULE_FILE="$ETC_DIR/gtk-2.0/gdk-pixbuf.loaders"
  31. export PANGO_RC_FILE="$ETC_DIR/pango/pangorc"
  32.  
  33. # Banshee/Mono/GStreamer environment
  34. export MONO_FRAMEWORK_PATH="$LIB_DIR"
  35. export DYLD_FALLBACK_LIBRARY_PATH="/usr/lib:/usr/local/lib:$LIB_DIR:$LIB_DIR/banshee:$LIB_DIR/banshee/Extensions"
  36. export GST_PLUGIN_SYSTEM_PATH="$LIB_DIR/gstreamer-0.10"
  37. export BANSHEE_CONFIG_DIR="$XDG_CONFIG_HOME/banshee-1"
  38. BANSHEE_OPTIONS=""
  39. BANSHEE_EXEC_NAME=Banshee
  40. MONO_BIN="$BIN_DIR/mono"
  41. MONO_EXE="$LIB_DIR/banshee/Nereid.exe"
  42. MONO_OPTIONS=""
  43.  
  44. # We are testing the SGen compacting GC
  45. export MONO_ENV_OPTIONS="--gc=sgen"
  46.  
  47. for arg in $*; do
  48.     if [ "$arg" = --debug ]; then
  49.         MONO_OPTIONS="$MONO_OPTIONS --debug"
  50.         BANSHEE_OPTIONS="$BANSHEE_OPTIONS --debug"
  51.     fi
  52. done
  53.  
  54. # FIXME
  55. # pango.modules sucks - it doesn't like paths with spaces,
  56. # so even though everything else works fine, we still
  57. # will explode, so instead I'm just showing this lame dialog.
  58. if [[ "$APP_ROOT" =~ [[:space:]] ]]; then
  59.     osascript &>/dev/null <<EOF
  60.     tell application "System Events"
  61.         activate
  62.         display dialog "A space was detected in the path to Banshee. Currently this is unsupported.\n\nRename or move Banshee.app to a path without spaces.\n\nPath: $APP_ROOT" with title "Error" with icon caution buttons { "OK" } default button 1
  63.     end tell
  64. EOF
  65.     exit 1
  66. fi
  67.  
  68. mkdir -p "$BANSHEE_CONFIG_DIR"
  69. if [ -f "$RES_DIR/first-run" ]; then
  70.     echo "Appears to be first run of this application bundle."
  71.     rm -f -- "$RES_DIR/first-run"
  72.     PREVIOUS_APP_ROOT=""
  73. else
  74.     PREVIOUS_APP_ROOT="$(cat "$BANSHEE_CONFIG_DIR/app-bundle-location" 2>/dev/null)"
  75. fi
  76.  
  77. if [ ! "$APP_ROOT" = "$PREVIOUS_APP_ROOT" ]; then
  78.     echo "Application bundle has moved. Adjusting bundle..."
  79.  
  80.     # Mono Addins doesn't like being relocated - its cache contains
  81.     # references to the previous location of this bundle
  82.     find "$BANSHEE_CONFIG_DIR" -name addin-db-\* \
  83.         -exec rm -rf -- {} \; &>/dev/null
  84.  
  85.     # Adjust config files that need absolute paths to things
  86.     # in the bundle (e.g. pango, GDK pixbuf loaders...)
  87.     # TODO This only supports moving the bundle once;
  88.     # after that, there will be no ${APP_RESOURCES} to change to the value of ${RES_DIR}
  89.     IFS=$'\n'
  90.     for file in $(find "$ETC_DIR" | grep -E '.in$|.loaders$|.modules$|.immodules$'); do
  91.         echo "adjusting paths in $file";
  92.         sed -i -E "s|\${APP_RESOURCES}|${RES_DIR}|g" ${file};
  93.         sed -i -E "s|\${RES_DIR}|${RES_DIR}|g" ${file};
  94.     done
  95.     unset IFS
  96.  
  97.     # Store the new location of the bundle
  98.     echo "$APP_ROOT" > "$BANSHEE_CONFIG_DIR/app-bundle-location"
  99. fi
  100.  
  101. # set and handle debug parameters
  102. [ -n "$BANSHEE_DEBUG" -o -f "${BANSHEE_CONFIG_DIR}/always-debug" ] && BANSHEE_DEBUG="--debug"
  103. [ -n "$BANSHEE_TRACE" ] && BANSHEE_TRACE="--trace=$BANSHEE_TRACE"
  104. [ -n "$BANSHEE_PROFILE" ] && BANSHEE_PROFILE="--profile=$BANSHEE_PROFILE"
  105.  
  106. for arg in $*; do
  107.     case "x--debug" in ("x$arg")
  108.         BANSHEE_DEBUG=$arg
  109.     esac
  110.  
  111.     case "x--trace=" in ("x${arg:0:8}")
  112.         BANSHEE_TRACE=$arg
  113.     esac
  114.  
  115.     case "x--profile=" in ("x${arg:0:10}")
  116.         BANSHEE_PROFILE=$arg
  117.     esac
  118.  
  119.     case "x--redirect-log" in ("x$arg")
  120.         # OS X has no "pidof" so get its execution name
  121.         BANSHEE_PID=`ps wwax | egrep -i "[B]anshee" | awk '{ print $1 }'`;
  122.         [ -z "$BANSHEE_PID" ] && BANSHEE_REDIRECT_LOG="${BANSHEE_CONFIG_DIR}/log"
  123.     esac
  124.  
  125.     case "x--client=" in ("x${arg:0:9}")
  126.         BANSHEE_CLIENT="${arg:9}"
  127.     esac
  128. done
  129.  
  130. if [ ! -z "$BANSHEE_CLIENT" ]; then
  131.     BANSHEE_CLIENT="--client=${BANSHEE_CLIENT}"
  132. fi
  133.  
  134. if [ -n "$BANSHEE_DEBUG" -o -n "$BANSHEE_TRACE" -o -n "$BANSHEE_PROFILE" ]; then
  135.     MONO_OPTIONS="$BANSHEE_DEBUG $BANSHEE_TRACE $BANSHEE_PROFILE"
  136.     echo "** Running Mono with $MONO_OPTIONS **"
  137. fi
  138.  
  139. # Finally - environment is set up, time to run our beloved
  140. exec_args="-a $BANSHEE_EXEC_NAME $MONO_BIN $MONO_OPTIONS $MONO_EXE $BANSHEE_DEBUG $BANSHEE_CLIENT $BANSHEE_OPTIONS"
  141.  
  142. if [ -z "$BANSHEE_REDIRECT_LOG" ]; then
  143.     exec $exec_args "$@"
  144. else
  145.     mkdir -p `dirname "$BANSHEE_REDIRECT_LOG"`
  146.     (echo "exec $exec_args " "$@"; echo; exec $exec_args "$@") &> $BANSHEE_REDIRECT_LOG
  147. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement