summaryrefslogtreecommitdiff
path: root/community/freeorion/freeorion.sh
blob: 9f35e7032514e28daed02093d853f4d82e1ad626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
#
# written by Markus Sinner, http://psitronic.de
#
# Nightly builds on.
# http://freeorion.psitronic.de/download/nightly/
#
# This is a wrapper-script for starting FreeOrion on
# ix86 (and maybe x64) Linux Systems.
# This script will CD into application and set some
# enviroment variables.

# ---- commandline PARAMETERS and ENVIROMENT variables -----
# This script supports parameters, that will be evaluated
# BEFORE freeorion binary is called and will be removed, 
# because the binary won't support them.
# Currently only one parameter at a time is supported!
# Parameters other than these will be appended as command
# line parameters to the call of the freeorion binary.
#
# --strace
#   This starts freeorion using the "strace" utility. 
#   Generates a strace logifle /tmp/freeorion.trace.
#   Make sure it is installed on your system!
# --gdb
#   Runs freeorion in a gdb instance, passes the original
#   parameters through the --args parameter of gdb
#
#
# ENVIROMENT variables
# This script supports some enviroment variables. To set them
# either use the followin command BEFORE you execute this script.
#    export XXXX="value"
# This permanently set the variable in you current shell script.
# Or you prepend the options when running this script, like this:
#    PARAM1="hello" PARAM2="yo man" /usr/bin/freeorion.elf
#
# Supportet are:
#   FO_TRACE=
#      Use this to prepend something to calling freorion.
#      This variables also is used internally, when --gdb or --trace
#      appear on the command line.
#   FO_GDB_ARGS=
#      If you use --gbd, you should uses this env to add GDB parameters.
#      Make sure you end this list of parameters with --args, otherwise
#      gdb won't start. Example: FO_GDB_ARGS="-q -s fo.symbols --args"
#   LD_LIBRARY_PATH=
#      This is a well known env and will be honored by this script.
#


# ---------- STARTS HERE ---------------
# Change into application directory
# If this is a symlink, then we
# need to change into the dir of symlink-target.
if [ -h $0 ]; then
  #echo "I am Symlink. Following into my targets basedir"
  ME=`readlink $0`
else
  #echo "Following into my basedir"
  ME=$0
fi

# This is important! Script won't work outside its installation dir
ROOT=/usr/share/freeorion
cd ${ROOT}
#echo -n "CWD: "
pwd



# Check for python. If freeorionca binary is missing it, use
# the shipped version.
if ldd /usr/bin/freeorionca | grep "libpython.*not found"; then
    #echo "python2.5 missing. Using shipped version."
    PYTHON_USE_SHIPPED=1
else 
    #echo "python2.5 found. Using it."
    PYTHON_USE_SHIPPED=0
fi

# Set Python library home for loading modules
# If no python 2.5 is detected, use shipped python 2.5
if [ "$PYTHON_USE_SHIPPED" = "1" ]; then
    export PYTHONHOME=/usr/lib/freeorion/python2.5
    export PYTHONPATH=${PYTHONHOME}
    export PYTHONDEBUG=1
    export PYTHONVERBOSE=1
    #echo "PYTHONHOME=${PYTHONHOME}"
    
    export LD_LIBRARY_PATH=${PYTHONHOME}:${LD_LIBRARY_PATH}
    export LD_PRELOAD=${PYTHONHOME}/libutil.so.1:${PYTHONHOME}/libpython2.5.so
fi


# Command line Parameter --gdb forces running in gdb
# Setting FO_TRACE to gdb results in other settings, see
# below
if [ "$1" = "--gdb" ]; then
    FO_TRACE="gdb"

    # Don't forget to remove the param
    shift
fi

if [ "$1" = "--strace" ]; then
    TRACEFILE=/tmp/freeorion.trace
    echo
    echo "Tracing to ${TRACEFILE}"
    echo
    FO_TRACE="strace -f -o ${TRACEFILE}"

    # Don't forget to remove the param
    shift
fi



# Add a parameter FO_GDB_ARGS to support gdb
# Or warn the user, if he changed FO_GDB_ARGS and has
# forgotten to end it with --args
if [ "$FO_TRACE" = "gdb" ]; then
    if [ "$FO_GDB_ARGS" = "" ]; then
	FO_GDB_ARGS="--args"
    else
	echo "****************************************************"
	echo "** NOTE         NOTE         NOTE         NOTE    **"
	echo "Running FO in gdb"
	echo "If you use FO_GDB_ARGS on your command line, make"
	echo "sure that you END this variabble with --args."
	echo "Otherwise gdb will not start."
	echo
	echo "Type 'start' when the gdb instance has loaded!"
	echo	
    fi
fi


# Support loading libs from application/lib
export LD_LIBRARY_PATH=./lib:${LD_LIBRARY_PATH}

# Call with settings-dir to avoid conflicting installations
${FO_TRACE} ${FO_GDB_ARGS} /usr/bin/freeorion.elf  --resource-dir ./default $@