Skip to content
Permalink
e77f32591d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
187 lines (152 sloc) 3.7 KB
#!/bin/bash
#
# bee - wrapper script for the various bee-tools
#
# Copyright (C) 2009-2016
# Marius Tolzmann <m@rius.berlin>
# Matthias Ruester <matthias.ruester@gmail.com>
# Tobias Dreyer <dreyer@molgen.mpg.de>
# and other bee developers
#
# This file is part of bee.
#
# bee is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
BEE_VERSION="@BEE_VERSION@"
: ${BEE_SYSCONFDIR:=@SYSCONFDIR@}
: ${BEE_DEFCONFDIR:=@DEFCONFDIR@}
: ${BEE_DATADIR:=@DATADIR@}
: ${BEE_LIBDIR:=@LIBDIR@}
: ${BEE_LIBEXECDIR:=@LIBEXECDIR@}
: ${BEE_BINDIR:=@BINDIR@}
# load libs
. ${BEE_LIBEXECDIR}/bee/beelib.config.sh
function usage() {
cat <<-EOF
bee v${BEE_VERSION} 2009-2016
by Marius Tolzmann <m@rius.berlin>
Matthias Ruester <matthias.ruester@gmail.com>
Tobias Dreyer <dreyer@molgen.mpg.de>
EOF
print_usage
echo
echo " available tools: (use bee <tool> --help for further information)"
echo
for i in ${BEE_LIBEXECDIR}/bee/bee.d/bee-* ; do
echo " bee ${i##*/bee-}"
done
echo
}
function print_usage() {
cat <<-EOF
bee [options] <tool> [tool-options] [tool-arguments]
bee --print-config
bee --help
bee --version
bee --destdir=/path/to/destdir
EOF
}
function search_tool_cmd {
local IFS=":${IFS}"
local tool=${1}
if [ -z "${tool}" ] ; then
return
fi
CMD=
for dir in ${XDG_CONFIG_HOME} ${XDG_CONFIG_DIRS} ${BEE_LIBEXECDIR} ; do
cmd="${dir}/bee/bee.d/bee-${tool}"
if [ -x "${cmd}" ] ; then
CMD=${cmd}
return
fi
done
}
options=$(${BEE_BINDIR}/beegetopt --name=bee \
--keep-option-end \
--option=destdir= \
-- "${@}")
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- ${options}
while true ; do
case "${1}" in
--destdir)
BEE_BEEDESTDIR=${2}
shift 2
;;
--)
shift
break
esac
done
options=$(${BEE_BINDIR}/beegetopt --name=bee \
--stop-on-no-option \
--no-skip-unknown-option \
--keep-option-end \
--option=print-config \
--option=help/h \
--option=version/V \
-- "${@}")
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "${options}"
declare -i OPT_PRINTCONFIG=0
while true ; do
case "$1" in
--print-config)
shift
OPT_PRINTCONFIG=1
;;
--help)
usage
exit 0
;;
--version)
echo "${BEE_VERSION}"
exit 0
;;
--)
shift
break
;;
esac
done
TOOL=${1}
config_init_colors
config_init
config_export
if [ "${TOOL}" = "init" ] ; then
expand_prefix_variables_defaults
config_export_prefix_variables
fi
BEE_METADIR=${BEE_BEEDESTDIR}${BEE_METADIR}
BEE_CACHEDIR=${BEE_BEEDESTDIR}${BEE_CACHEDIR}
if [ "${OPT_PRINTCONFIG}" = "1" ] ; then
config_print
exit 0
fi
search_tool_cmd ${TOOL}
if [ ! -z "${CMD}" ] ; then
shift
# remove this for >= 2.0 ?? since this is compat mode for pre 1.0
${BEE_LIBEXECDIR}/bee/compat-fixmetadir ${BEE_METADIR}
exec ${CMD} "${@}"
exit 1
fi
usage
exit 1