#!/bin/sh
set -e

BUNDLE_GEMFILE="${BUNDLE_GEMFILE:-/usr/share/beef-xss/Gemfile}"
export BUNDLE_GEMFILE

# Bootstrap bundler
if ! echo "$GEM_PATH" | egrep -q "/usr/share/beef-xss/vendor/bundle" ; then
    for dir in /usr/share/beef-xss/vendor/bundle/ruby/*; do
        if [ -d $dir ]; then
            GEM_PATH="${GEM_PATH:+"$GEM_PATH:"}$dir"
        fi
    done
fi

# Add rubygems-integration in GEM_PATH. Since bundler version 1.17.3-3,
# the gem is no longer installed in /usr/lib/ruby/vendor_ruby but in
# /usr/share/rubygems-integration/all (see issue 5359)
GEM_PATH="${GEM_PATH:+"$GEM_PATH:"}"/usr/share/rubygems-integration/all""

export GEM_PATH

cd /usr/share/beef-xss/

exec ./beef "$@"

