Skip to content

Commit

Permalink
Merge pull request #229 from vincentbernat/fix/simplify-starter-scripts
Browse files Browse the repository at this point in the history
bin/exabgp: simplify starter script
  • Loading branch information
thomas-mangin committed Feb 25, 2015
2 parents 72b873a + 41672c0 commit a443f59
Showing 1 changed file with 14 additions and 43 deletions.
57 changes: 14 additions & 43 deletions sbin/exabgp
Original file line number Diff line number Diff line change
@@ -1,51 +1,22 @@
#!/bin/sh

dirname=`dirname $0`
dirname="$(dirname $0)"

case $dirname in
/*)
cd $dirname/.. > /dev/null
path=`pwd`
cd - > /dev/null
;;
*)
cd `pwd`/$dirname/.. > /dev/null
path=`pwd`
cd - > /dev/null
;;
esac
path="$(readlink -f $dirname/..)"

export PYTHONPATH=$path/lib:/usr/share/exabgp/lib/3.4.4
export PYTHONPATH="$path"/lib:/usr/share/exabgp/lib/3.4.4

PYPY=`which pypy 2>/dev/null`
PYTHON27=`which python2.7 2>/dev/null`
PYTHON26=`which python2.6 2>/dev/null`
PYTHON2=`which python2 2>/dev/null`
PYTHON=`which python 2>/dev/null`
for INTERPRETER in "$INTERPRETER" pypy python2.7 python2.6 python2 python; do
INTERPRETER="$(command -v "$INTERPRETER")" && break
done

if [ "$INTERPRETER" != "" ]
then
INTERPRETER=`which $INTERPRETER`
elif [ -f "$PYPY" ]
then
INTERPRETER=$PYPY
elif [ -f "$PYTHON27" ]
then
INTERPRETER=$PYTHON27
elif [ -f "$PYTHON26" ]
then
INTERPRETER=$PYTHON26
elif [ -f "$PYTHON2" ]
then
INTERPRETER=$PYTHON2
elif [ -f "$PYTHON" ]
then
INTERPRETER=$PYTHON
else
INTERPRETER=python
fi
APPLICATION="$("$INTERPRETER" -c "
import sys
import os
APPLICATIONS=`$INTERPRETER -c "import sys,os; print ' '.join(os.path.join(_,'exabgp','application','bgp.py') for _ in sys.path if os.path.isfile('/'.join((_,'exabgp','application','bgp.py'))))"`
APPLICATION=`echo $APPLICATIONS | awk '{ print $1; }'`
print [os.path.join(_, 'exabgp', 'application', 'bgp.py')
for _ in sys.path
if os.path.isfile('/'.join((_, 'exabgp', 'application', 'bgp.py')))][0]
")"

exec $INTERPRETER $APPLICATION --folder $path/etc/exabgp "$@"
exec "$INTERPRETER" "$APPLICATION" --folder "$path"/etc/exabgp "$@"

0 comments on commit a443f59

Please sign in to comment.