Permalink
Cannot retrieve contributors at this time
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?
bee/src/bee-init.sh.in
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
514 lines (422 sloc)
14.4 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# bee-init - initialize bee-files from source-urls | |
# | |
# Copyright (C) 2009-2016 | |
# Marius Tolzmann <m@rius.berlin> | |
# 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/>. | |
# | |
set -e | |
if [ -z "${BEE_VERSION}" ] ; then | |
echo >&2 "BEE-ERROR: please call $0 from bee .." | |
exit 1 | |
fi | |
VERSION=${BEE_VERSION} | |
: ${BEE_BINDIR:=@BINDIR@} | |
function usage() { | |
cat <<-EOF | |
bee-init v${VERSION} 2009-2016 | |
by Marius Tolzmann <m@rius.berlin> and Tobias Dreyer <dreyer@molgen.mpg.de> | |
bee [bee-options] init [options] <url> | |
Options: | |
--configure=MODE set configure mode: | |
'compat': disable --datarootdir option to be | |
compatible with older ./configure scripts. | |
'none': disable configure at all. | |
--disable-versionify do not replace versionnumbers with variables | |
in the bee-file | |
--buildtype=TYPE force buildtype: configure, cmake, make, autogen, | |
perl-module, perl-module-makemaker, python-module | |
-f --force force overwrite of bee-file. | |
-h --help this little help. | |
-V --version print version number. | |
-D --define=A=B define ENV variables within the bee-file. | |
(extra (over)quoting may be needed if B contains spaces.) | |
-o --output=bee-file name of new bee-file | |
-e --execute execute bee-file after creation | |
-i --install execute bee-file and install software | |
Naming bee-files: | |
--pkgextraname=NAME add pkgextraname '_NAME' to bee-file-name | |
--pkgprefix=NAME prefix bee-file with 'NAME-' | |
Installation directories: | |
--prefix=PREFIX install architecture-independent files in PREFIX | |
[${PREFIX}] | |
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX | |
[${EPREFIX}] | |
Fine tuning of the installation directories: | |
--bindir=DIR user executables [${BINDIR}] | |
--sbindir=DIR system admin executables [${SBINDIR}] | |
--libexecdir=DIR program executables [${LIBEXECDIR}] | |
--sysconfdir=DIR read-only single-machine data [${SYSCONFDIR}] | |
--sharedstatedir=DIR modifiable architecture-independent data [${SHAREDSTATEDIR}] | |
--localstatedir=DIR modifiable single-machine data [${LOCALSTATEDIR}] | |
--libdir=DIR object code libraries [${LIBDIR}] | |
--includedir=DIR C header files [${INCLUDEDIR}] | |
--datarootdir=DIR read-only arch.-independent data root [${DATAROOTDIR}] | |
--datadir=DIR read-only architecture-independent data [${DATADIR}] | |
--infodir=DIR info documentation [${INFODIR}] | |
--localedir=DIR locale-dependent data [${LOCALEDIR}] | |
--mandir=DIR man documentation [${MANDIR}] | |
--docdir=DIR documentation root [${DOCDIR}] | |
Descriptions taken from ./configure script - may vary depending on buildtype. | |
Current values in [] (command line options are not evaluated). | |
for [bee-options] see 'bee --help'. | |
EOF | |
} | |
function print_msg() { | |
echo >&2 -e "${COLOR_BRACKET}[${COLOR_BRCONTENT}BEE${COLOR_BRACKET}] ${@}" | |
} | |
function print_info() { | |
print_msg "${COLOR_INFO}${@}${COLOR_NORMAL}" | |
} | |
function print_error() { | |
print_msg "${COLOR_ERROR}${@}${COLOR_NORMAL}" | |
} | |
function bee_versionify() { | |
local -i i | |
beefile=$1 | |
if [ "${OPT_VERSIONIFY}" != "yes" ] ; then | |
return | |
fi | |
eval $(@BINDIR@/beeversion ${beefile} 2>/dev/null) | |
if [ -z "${PKGREVISION}" ] ; then | |
return | |
fi | |
i=${#PKGVERSION[@]}-2 | |
rules="-e 's,${PKGVERSION//\./\\.},\${PKGVERSION},g'" | |
while [ $i -gt 1 ] ; do | |
rules="${rules} -e 's,${PKGVERSION[$i]//\./\\.},\${PKGVERSION[$i]},g'" | |
i=i-1 | |
done | |
eval sed -i ${rules} ${beefile} | |
} | |
function create_beefile_from_template { | |
beefile=$1 | |
templates=( $2 default fallback ) | |
local IFS=":${IFS}" | |
for tmpl in ${templates[@]} ; do | |
for dir in ${XDG_CONFIG_HOME} ${XDG_CONFIG_DIRS} ; do | |
xdgtemplate="${dir}/bee/templates/${tmpl}" | |
if [ -r "${xdgtemplate}" ] ; then | |
: ${BEE_TEMPLATE=${xdgtemplate}} | |
fi | |
done | |
done | |
if [ ! -r "${BEE_TEMPLATE}" ] ; then | |
print_error "no valid template found .." | |
exit 1 | |
fi | |
echo "creating ${beefile} from template '${BEE_TEMPLATE}'" | |
cp ${BEE_TEMPLATE} ${beefile} | |
} | |
function initialize() { | |
surl=${1} | |
[ ! -z "${surl}" ] && shift | |
pname=${OPT_OUTPUT} | |
DEFAULT_CONFIGURE_OPTIONS="${@}" | |
if [ -z "${pname}" ] ; then | |
# start auto packagename generation with surl basename | |
pname=${surl##*/} | |
# fix sourceforge urls for automatic pkgname generation | |
if [[ $surl = *://sourceforge.net/*/files/*/download ]] ; then | |
# strip /files directory | |
surl=${surl/\/files\///} | |
# rename directory /projects to /project | |
surl=${surl/\/projects\///project/} | |
# replace hostname sourceforge.net -> downloads.sourceforge.net | |
surl=${surl/\/\/sourceforge.net\////downloads.sourceforge.net/} | |
# strip /download basename | |
surl=${surl%/download} | |
pname=${surl##*/} | |
fi | |
if [[ "${surl}" = https://github.com/*/*/zipball/* ]] ; then | |
surl=${surl/\/zipball\//\/tarball\/} | |
fi | |
if [[ "${surl}" = https://github.com/*/*/tarball/* ]] ; then | |
local github_url | |
local github_tag | |
local github_pkg | |
github_url=${surl} | |
github_tag=${github_url##*/} | |
github_pkg=${github_url%/*/*} | |
github_pkg=${github_pkg##*/} | |
# see bee-download for description of the following | |
github_tag=$( sed \ | |
-e 's,^[vV]\([0-9]\+[-_\.]\),\1,' \ | |
-e 's,.*[-_][vV]\([0-9]\+[-_\.]\),\1,' \ | |
-e 's,^\(\([A-Za-z]\+[0-9]*\)\+[-_]\)\+,,' \ | |
-e 's,^[vV]\([0-9]\+\)$,\1,' \ | |
-e 's,-,_,g' \ | |
-e 's,_\([0-9]\),.\1,g' \ | |
-e 's,\([A-Z]\+\),\L\1,g' <<< "${github_tag}" ) | |
pname="${github_pkg}-${github_tag}" | |
surl="${surl} ${pname}.tar.gz" | |
fi | |
if [[ $surl =~ ^https://github\.molgen\.mpg\.de/([^/]+)/([^/]+)/archive/(.+)\.tar\.gz$ ]] ; then | |
pname="${BASH_REMATCH[2]}-${BASH_REMATCH[3]#v}" | |
fi | |
if [[ "${OPT_BUILDTYPE}" = "r-package" || "${surl}" = http://cran.r-project.org/src/contrib/* ]] ; then | |
local cran_pname | |
local cran_version | |
local cran_revision | |
local cran_suffix | |
# set suffix | |
cran_suffix=.tar${pname#*.tar} | |
# remove suffix | |
cran_pname=${pname%.tar*} | |
# extract version and revision | |
cran_version=${cran_pname##*_} | |
# set pname | |
cran_pname=${cran_pname%_*} | |
if [[ "${cran_version}" = *-* ]] ; then | |
# set revision | |
cran_revision=${cran_version#*-} | |
fi | |
# set version | |
cran_version=${cran_version%%-*} | |
if [[ "${cran_revision}" = *-* ]] ; then | |
break; | |
fi | |
pname="${cran_pname}" | |
pname+="-${cran_version}" | |
pname+="${cran_revision+_${cran_revision}}" | |
surl="${surl%/*}/${cran_pname}" | |
surl+='_${PKGVERSION}${PKGEXTRAVERSION_DASH}' | |
surl+="${cran_suffix}" | |
if [ -z "${OPT_BUILDTYPE}" ] ; then | |
OPT_BUILDTYPE=r-package | |
fi | |
fi | |
# and remove all HTTP-GET variables.. | |
pname=${pname%%\?*} | |
# remove anchors | |
pname=${pname%%\#*} | |
# strip some known and some special suffixes | |
pname=${pname%.gz} | |
pname=${pname%.bz2} | |
pname=${pname%.xz} | |
pname=${pname%.zip} | |
pname=${pname%.tgz} | |
pname=${pname%.tbz2} | |
pname=${pname%.tar} | |
pname=${pname%.src} | |
pname=${pname%-src} | |
pname=${pname%.source} | |
pname=${pname%-source} | |
if [ "${pname}" = "${surl}" ] ; then | |
surl="" | |
else | |
pname=${pname}-0 | |
fi | |
fi | |
eval $(${BEE_BINDIR}/beeversion ${pname}) | |
beefile="${OPT_pkgprefix}${PKGFULLNAME}${OPT_pkgextraname}-${PKGFULLVERSION:=0}-${PKGREVISION:=0}.bee" | |
if [ -e "${beefile}" ] && [ "$OPT_FORCE" != "yes" ] ; then | |
echo "${beefile} already exists .. use option -f to overwrite .." | |
exit 1 | |
fi | |
create_beefile_from_template ${beefile} ${TEMPLATE} | |
sed -e "s,@SRCURL@,SRCURL[0]=\"${surl}\"," \ | |
-i ${beefile} | |
if [ -z "${DEFAULT_CONFIGURE_OPTIONS}" ] ; then | |
DEFAULT_CONFIGURE_OPTIONS_NOTSET="#" | |
else | |
DEFAULT_CONFIGURE_OPTIONS_NOTSET="" | |
fi | |
sed -e "s,@DEFAULT_CONFIGURE_OPTIONS@,${DEFAULT_CONFIGURE_OPTIONS}," \ | |
-e "s,@DEFAULT_CONFIGURE_OPTIONS_NOTSET@,${DEFAULT_CONFIGURE_OPTIONS_NOTSET}," \ | |
-e 's/\s$//' \ | |
-i ${beefile} | |
for i in prefix eprefix bindir sbindir libexecdir sysconfdir \ | |
localstatedir sharedstatedir libdir includedir datarootdir \ | |
datadir infodir mandir docdirlocaledir ; do | |
I=$(tr a-z A-Z <<<"${i}") | |
eval dir=\$OPT_${i} | |
DEFAULT_PREFIX_VARS="${DEFAULT_PREFIX_VARS:+${DEFAULT_PREFIX_VARS}}${dir:+${DEFAULT_PREFIX_VARS:+\n}}${dir:+${I}=${dir}}" | |
unset dir | |
done | |
if [ -n "${DEFAULT_PREFIX_VARS}" ] ; then | |
sed -e "s,@DEFAULT_PREFIX_VARS@,${DEFAULT_PREFIX_VARS}," \ | |
-i ${beefile} | |
else | |
sed -e "/@DEFAULT_PREFIX_VARS@/d" \ | |
-i ${beefile} | |
fi | |
if [ -n "${OPT_DEFINE}" ] ; then | |
sed -e "s,@BEE_DEFINES@,${OPT_DEFINE}\n," \ | |
-i ${beefile} | |
else | |
sed -e "/@BEE_DEFINES@/d" \ | |
-i ${beefile} | |
fi | |
if [ -n "${CONFIGURE_BEEHAVIOR}" ] ; then | |
sed -e "s,@BEE_CONFIGURE@,BEE_CONFIGURE=${CONFIGURE_BEEHAVIOR}\n," \ | |
-i ${beefile} | |
else | |
sed -e "/@BEE_CONFIGURE@/d" \ | |
-i ${beefile} | |
fi | |
if [ -n "${OPT_BUILDTYPE}" ] ; then | |
sed -e "s,@BEE_BUILDTYPE@,BEE_BUILDTYPE=\"${OPT_BUILDTYPE}\"\n," \ | |
-i ${beefile} | |
else | |
sed -e "/@BEE_BUILDTYPE@/d" \ | |
-i ${beefile} | |
fi | |
bee_versionify ${beefile} | |
chmod 755 ${beefile} | |
if [ "${OPT_EXEC}" = "yes" ] ; then | |
${BEE_BINDIR}/beesh ${beefile} ${OPT_INSTALL} | |
fi | |
} | |
options=$(${BEE_BINDIR}/beegetopt --name bee-init \ | |
--option disable-versionify \ | |
--option help/h \ | |
--option version/V \ | |
--option output/o= \ | |
--option define/D= \ | |
--option template/t= \ | |
--option force/f \ | |
--option execute/e \ | |
--option install/i \ | |
--option configure= \ | |
--option prefix= \ | |
--option eprefix= \ | |
--option bindir= \ | |
--option sbindir= \ | |
--option libexecdir= \ | |
--option sysconfdir= \ | |
--option localstatedir= \ | |
--option sharedstatedir= \ | |
--option libdir= \ | |
--option includedir= \ | |
--option datarootdir= \ | |
--option datadir= \ | |
--option infodir= \ | |
--option mandir= \ | |
--option docdir= \ | |
--option localedir= \ | |
--option buildtype= \ | |
--option pkgextraname= \ | |
--option pkgprefix= \ | |
-- "$@") | |
if [ $? != 0 ] ; then | |
usage | |
exit 1 | |
fi | |
OPT_VERSIONIFY="yes" | |
OPT_OUTPUT= | |
OPT_EXEC="no" | |
OPT_INSTALL= | |
OPT_pkgextraname="" | |
OPT_pkgprefix="" | |
eval set -- "${options}" | |
while true ; do | |
case "$1" in | |
--help) | |
usage | |
exit 0 | |
;; | |
--version) | |
echo ${VERSION} | |
exit 0 | |
;; | |
--template) | |
TEMPLATE=${2} | |
shift 2 | |
;; | |
--force) | |
shift | |
OPT_FORCE="yes" | |
;; | |
--disable-versionify) | |
shift | |
OPT_VERSIONIFY="no" | |
;; | |
--configure) | |
case "${2}" in | |
compat|none) | |
CONFIGURE_BEEHAVIOR=${2} | |
;; | |
*) | |
unset CONFIGURE_BEEHAVIOR | |
;; | |
esac | |
shift 2 | |
;; | |
--prefix|\ | |
--eprefix|\ | |
--bindir|\ | |
--sbindir|\ | |
--libexecdir|\ | |
--sysconfdir|\ | |
--localstatedir|\ | |
--sharedstatedir|\ | |
--libdir|\ | |
--includedir|\ | |
--datarootdir|\ | |
--datadir|\ | |
--infodir|\ | |
--mandir|\ | |
--docdir|\ | |
--localedir) | |
eval OPT_${1:2}="${2}" | |
shift 2 | |
;; | |
--pkgextraname) | |
eval OPT_${1:2}="_${2}" | |
shift 2 | |
;; | |
--pkgprefix) | |
eval OPT_${1:2}="${2}-" | |
shift 2 | |
;; | |
--output) | |
OPT_OUTPUT=${2} | |
shift 2 | |
;; | |
--define) | |
OPT_DEFINE="${OPT_DEFINE}\nexport ${2}" | |
shift 2 | |
;; | |
--buildtype) | |
OPT_BUILDTYPE="${2}" | |
shift 2 | |
;; | |
--execute) | |
OPT_EXEC="yes" | |
shift | |
;; | |
--install) | |
OPT_EXEC="yes" | |
OPT_INSTALL="--install" | |
shift | |
;; | |
*) | |
shift | |
if [ -z "${1}" -a -z "${OPT_OUTPUT}" ] ; then | |
usage | |
exit 1 | |
fi | |
: ${TEMPLATE:=default} | |
initialize "${@}" | |
exit 0; | |
;; | |
esac | |
done |