3 # Lightweight script for running test instances of Tracker. Less effort
4 # than running a full instance of gnome-session from jhbuild. Primary
5 # goal is to avoid messing with your actual data.
8 echo "tracker-sandbox:"
9 echo " Creates a lightweight test environment for Tracker, to avoid"
10 echo " messing with your real data. The safest mechanism is to run"
11 echo " the sandbox as a different user, but also supports running in"
12 echo " your real user account but with a database in /tmp/tracker-test"
14 echo " Multiple instances of tracker-sandbox will share a session."
15 echo " Currently the first instance owns the session and those started"
16 echo " later will stop working once the first instance has exited."
18 echo "Recommended usage:"
19 echo " su <dummy user account>"
20 echo " tracker-sandbox --user"
22 echo "Alternative usage:"
23 echo " tracker-sandbox"
26 echo " --help Show this information"
27 echo " -p, --prefix DIR Set up environment to use Tracker installed"
28 echo " in DIR (similar to 'jhbuild shell')"
32 SEPARATE_USER_MODE=false
34 while [ $# -gt 0 ]; do
43 echo "Error: --prefix option requires an argument"
49 SEPARATE_USER_MODE=true
52 echo "Error: unknown option $1"
53 echo "Run '$0 --help' for help."
64 if [ "$SEPARATE_USER_MODE" != "true" ]; then
65 export DCONF_PROFILE=trackertest
67 TEMP_DIR=/tmp/tracker-test
69 export XDG_CACHE_HOME=$TEMP_DIR
70 export XDG_CONFIG_HOME=$TEMP_DIR
71 export XDG_DATA_HOME=$TEMP_DIR
73 export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-$TEMP_DIR}
75 if [ ! -O "$XDG_RUNTIME_DIR" ]; then
76 echo "Error: $XDG_RUNTIME_DIR is not writable by current user ($(whoami))."
77 echo "Use the '--user' option if you have switched to a dummy user account."
81 # We can't create a 'real' runtime dir without root, but for testing
82 # the security implications are irrelevant.
83 XDG_RUNTIME_DIR=/tmp/tracker-test-$(whoami)
84 mkdir -p $XDG_RUNTIME_DIR
85 export XDG_RUNTIME_DIR
88 if [ -n "$PREFIX" ]; then
89 if [ ! -d "$PREFIX" ]; then
90 echo "Error: unable to find prefix '$PREFIX'"
94 # Interestingly, 'jhbuild run' *doesn't* alter PATH - I wonder why?
95 export PATH="$PREFIX/bin:$PATH"
96 export LD_LIBRARY_PATH="$PREFIX/lib:$PATH"
97 export XDG_DATA_DIRS="$PREFIX/share:$XDG_DATA_DIRS"
99 export TRACKER_DB_ONTOLOGIES_DIR="$PREFIX/share/tracker/ontologies"
100 export TRACKER_EXTRACTOR_RULES_DIR="$PREFIX/share/tracker/extract-rules"
101 export TRACKER_LANGUAGE_STOPWORDS_DIR="$PREFIX/share/tracker/languages"
106 if [ "$SEPARATE_USER_MODE" != "true" ]; then
107 echo -n "Running as $(whoami) with data in $TEMP_DIR"
108 [ -e "$TEMP_DIR/tracker/meta.db" ] && echo -n " (previously used)"; echo
110 echo "Running as $(whoami) using real Tracker store"
113 if [ -n "$PREFIX" ]; then
114 echo "Using Tracker from $PREFIX"
117 SESSION_FILE="$XDG_RUNTIME_DIR/tracker-sandbox"
119 # Slight race condition here if you start two instances simultaneously .. so don't
120 if [ ! -e "$SESSION_FILE" ]; then
121 eval $(dbus-launch --sh-syntax | tee $SESSION_FILE)
123 trap "rm \"$SESSION_FILE\"; /bin/kill $DBUS_SESSION_BUS_PID; exit" INT TERM EXIT
125 echo "[$DBUS_SESSION_BUS_PID] Launched new session at $DBUS_SESSION_BUS_ADDRESS"
127 eval $(cat $SESSION_FILE)
129 echo "Using existing session at $DBUS_SESSION_BUS_ADDRESS"
134 # Cleanup handled by 'trap' handler above.
136 # It would be nice if we could ref-count the session instead of pulling the rug
137 # out from under any other tracker-sandbox processes that are still running.