Skip to content
Permalink
47686bf1f3
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
842 lines (658 sloc) 21.5 KB
#!/bin/bash
#
# beesh - bee-file interpreter - the main brain
#
# Copyright (C) 2009-2011
# Marius Tolzmann <tolzmann@molgen.mpg.de>
# 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
#architecture
ARCH=$(uname -m)
# Version
BEE_VERSION="@BEE_VERSION@"
VERSION=${BEE_VERSION}
: ${BEE_SYSCONFDIR:=@SYSCONFDIR@}
: ${BEE_DEFCONFDIR:=@DEFCONFDIR@}
: ${BEE_DATADIR:=@DATADIR@}
: ${BEE_LIBDIR:=@LIBDIR@}
: ${BEE_LIBEXECDIR:=@LIBEXECDIR@}
: ${BEE_BINDIR:=@BINDIR@}
: ${BEEFIND:=${BEE_BINDIR}/beefind}
# load libs
. ${BEE_LIBEXECDIR}/bee/beelib.config.sh
###############################################################################
###############################################################################
###############################################################################
function log_enter() {
print_info "=> entering ${@} .."
}
function log_leave() {
print_info "<= leaving ${@} .."
}
function start_cmd() {
print_info "${COLOR_CYAN}${@}"
"${@}"
}
###############################################################################
###############################################################################
###############################################################################
#### create_meta() ############################################################
function create_meta() {
echo >>${D}/META "BEEMETAFORMAT=2"
echo >>${D}/META "BEEPKG='${PKGALLPKG}'"
for var in prefix eprefix bindir sbindir libexecdir sysconfdir \
sharedstatedir localstatedir libdir includedir \
datarootdir datadir infodir localedir mandir docdir ; do
eval eval echo PKG_${var^^}=\${${var^^}} >>${D}/META
done
}
#### show_help() ##############################################################
function show_help() {
cat <<-EOF
beesh v${VERSION} 2009-2011
by Marius Tolzmann and Tobias Dreyer <{tolzmann,dreyer}@molgen.mpg.de>
Max Planck Institute for Molecular Genetics Berlin Dahlem
Usage: beesh [options] <pkg>.bee
Options:
-c, --cleanup may be used to clean up <pkg>-related
directory tree before build process is started
-i, --install after build process is successful and <pkg> is
built, <pkg>.tgz is installed by bee_install
-f, --force-install same as -i; bee_install is invoked with --force
-h, --help display this help
--no-archive-build do not archive the build directory
--check run mee_check, mee_check_pre and mee_check_post
EOF
}
function disable_autoexclusion() {
unset BEE_AUTO_EXCLUDE
}
function require_version() {
if ${BEE_BINDIR}/beeversion "${VERSION}" -lt "${1}" ; then
print_error "this bee-file requires at least bee v${1} .."
exit 1;
fi
}
function check_repositories() {
r=0
print_info "==> checking repositories .."
mkdir -pv ${BEE_BEEDIR}
mkdir -pv ${BEE_PKGDIR}
mkdir -pv ${BEE_BUILDARCHIVEDIR}
if [ ! -w "${BEE_BEEDIR}" ] ; then
print_error " !! ${BEE_BEEDIR} not writable"
r=1
fi
if [ ! -w "${BEE_PKGDIR}" ] ; then
print_error " !! ${BEE_PKGDIR} not writable"
r=1
fi
if [ ! -w "${BEE_BUILDARCHIVEDIR}" ] ; then
print_error " !! ${BEE_BUILDARCHIVEDIR} not writable"
r=1
fi
if [ "$r" != "0" ] ; then
exit 1
fi
}
function build_in_sourcedir() {
B=${S}
}
#### bee_init_builddir() ######################################################
function bee_init_builddir() {
print_info "==> initializing build environment .."
if [ -d "${W}" ] ; then
if [ "${OPT_CLEANUP}" = "yes" ] ; then
print_info " -> cleaning work dir ${W} .."
rm -fr ${W}
else
print_error "error initializing build-dir ${W}"
print_error "please use -c to force a cleanup."
exit 1
fi
fi
print_info " -> creating source dir ${S}"
mkdir -p ${S}
if [ "${B}" == "${S}" ] ; then
link=${BEEWORKDIR}/build
print_info " -> B=S linking build dir ${link} to source dir"
ln -s source ${link}
else
print_info " -> creating build dir ${B}"
mkdir -p ${B}
fi
print_info " -> creating image dir ${D}"
mkdir -p ${D}
}
#### bee_getsources() #########################################################
# fetch_one_file <url> [filename]
function fetch_one_file() {
url=$1
file=${2:-${url##*/}}
if [ "${url:0:8}" = "file:///" ] ; then
url=${url:7}
fi
if [ "${url:0:1}" = "/" ] ; then
print_info "copying file ${url}"
cp -v "${url}" "${F}/${file}"
else
if [ "${url:0:5}" == "https" ] ; then
nocheck="--no-check-certificate"
else
nocheck=""
fi
if [ ! -s "${F}/${file}" ] ; then
rm -vf ${F}/${file}
fi
trap "rm -f ${F}/${file}" EXIT
print_info "fetching $url"
wget \
${nocheck} \
--output-document="${F}/${file}" \
--no-clobber \
"${url}" || true
trap - EXIT
ls -ld "${F}/${file}"
fi
bee_FETCHED_FILE="${F}/${file}"
bee_FETCHED_FILES=( ${bee_FETCHED_FILES[@]} "${F}/${file}" )
}
function fetch_one_archive() {
fetch_one_file $@
bee_SOURCEFILES=( ${bee_SOURCEFILES[@]} ${bee_FETCHED_FILE} )
}
function fetch_one_patch() {
fetch_one_file $@
if [ "${bee_FETCHED_FILE: -3:3}" = ".gz" ] ; then
if gunzip "${bee_FETCHED_FILE}" -c >"${bee_FETCHED_FILE%.gz}" ; then
bee_FETCHED_FILE=${bee_FETCHED_FILE%.gz}
fi
elif [ "${bee_FETCHED_FILE: -4:4}" = ".bz2" ] ; then
if bunzip2 "${bee_FETCHED_FILE}" -c >"${bee_FETCHED_FILE%.bz2}" ; then
bee_FETCHED_FILE=${bee_FETCHED_FILE%.bz2}
fi
fi
bee_PATCHFILES=( ${bee_PATCHFILES[@]} ${bee_FETCHED_FILE} )
}
function bee_getsrcurl() {
local -a archives=( "${@}" )
for a in "${archives[@]}" ; do
fetch_one_archive ${a}
done
}
function bee_getpatchurl() {
local -a patches=( "${@}" )
for p in "${patches[@]}" ; do
fetch_one_patch ${p}
done
}
# bee_getsources
# SRCURL[] = "<url> [filename]"
# e.g.:
# SRCURL=("<url> [filename]" "<url> [filename]")
# SRCURL="<url> [filename]"
# SRCURL[0]="<url> [filename]"
# SRCURL[1]="<url> [filename]"
function bee_getsources() {
mkdir -p "${F}"
if [ -z "${SRCURL}" ] ; then
unset SRCURL
fi
bee_getsrcurl "${SRCURL[@]}"
if [ -z "${PATCHURL}" ] ; then
unset PATCHURL
fi
if [ -z "{PATCHES}" ] ; then
unset PATCHES
fi
if [ -z "${PATCHURL}" ] && [ -n "${PATCHES}" ] ; then
print_error 'warning .. you are using deprecated variable ${PATCHES} .. please use ${PATCHURL} instead'
PATCHURL=( "${PATCHES[@]}" )
fi
bee_getpatchurl "${PATCHURL[@]}"
}
#### bee_extract() #############################################################
function bee_extract() {
local bee_S
bee_S=( "$@" )
: ${BEE_EXTRACT_STRIP:=1}
if is_func mee_unpack ; then
print_error "#BEE-WARNING# function 'mee_unpack()' is deprecated .. use 'mee_extract()' instead .." >&2
mee_unpack "${@}"
return
fi
if [ -z "${bee_S[0]}" ] ; then
return
fi
s=${bee_S[0]}
print_info " -> extracting main source ${s} .."
tar xof ${s} --strip-components ${BEE_EXTRACT_STRIP} -C ${S}
unset bee_S[0]
for s in ${bee_S[@]} ; do
print_info " -> extracting additional source ${s} .."
tar xof ${s} -C ${S}
done
print_info " -> all sources extracted to: ${S} .."
}
#### bee_patch() ##############################################################
function bee_patch() {
local bee_P
bee_P=( "$@" )
if [ "${#bee_P[@]}" == "0" ] ; then
bee_P=( ${bee_PATCHFILES[@]} )
fi
for p in ${bee_P[@]} ; do
striplevel=1
for i in 1 0 2 3 4 5 6 7 8 9 ; do
if patch --dry-run -N -p$i -i "${p}" >/dev/null 2>&1 ; then
striplevel=$i
print_info "bee_patch(): ${p##*/}: guessed patch striplevel of ${striplevel} .."
break
fi
done
start_cmd patch -N -p${striplevel} -i "${p}"
done
}
#### bee_configure() ##########################################################
function bee_configure() {
print_info "action 'configure' not defined: skipping.."
}
#### bee_build() ##############################################################
function bee_build() {
print_info "action 'build' not defined: skipping.."
}
#### bee_install() ############################################################
function bee_install() {
print_info "action 'install' not defined: skipping.."
}
#### bee_crosscheck() #########################################################
function bee_crosscheck() {
directories=( $(find ${D} -type d -printf "/%P\n") )
for d in ${directories[@]} ; do
if [ ! -e "${d}" -o -d "${d}" -a ! -L "${d}" ] ; then
# its ok
continue
fi
print_warning "WARNING: system and image files named '${d}' differ"
print_warning " image : $(file -b ${D}${d})"
print_warning " system: $(file -b ${d})"
done
links=( $(find ${D} -type l -printf "%p\n") )
for imagefilename in ${links[@]} ; do
target="$(readlink ${imagefilename})"
if [ "${target#${D}}" != "${target}" ] ; then
print_warning "WARNING: image: target of ${imagefilename#${D}} contains path to image directory"
imagetarget="${target}"
elif [ "${target:0:1}" = "/" ] ; then
imagetarget="${D}${target}"
else
imagetarget="${imagefilename%/*}/${target}"
fi
if [ ! -d "${imagetarget}" ] ; then
# dont care
continue
fi
systemfilename="${imagefilename#${D}}"
if [ ! -e "${systemfilename}" ] ; then
# its ok
continue
fi
if [ -L "${systemfilename}" ] ; then
target="$(readlink ${systemfilename})"
if [ "${target:0:1}" = "/" ] ; then
systemtarget=${target}
else
systemtarget="${systemfilename%/*}/${target}"
fi
if [ -d "${systemtarget}" -a "${imagetarget#${D}}" = "${systemtarget}" ] ; then
#its ok
continue
fi
fi
print_warning "WARNING: system and image files named '${systemfilename}' differ"
print_warning " image : $(file -b ${imagefilename})"
print_warning " system: $(file -b ${systemfilename})"
done
}
#### bee_pkg_pack() ###########################################################
# $EXCLUDE is read from .bee file
# $BEE_SKIPLIST is found in $BEEFAULTS
function bee_pkg_pack() {
${BEEFIND} --exclude='^/CONTENT$' \
--exclude-list=<(
if [ -n "${BEE_SKIPLIST}" ] ; then
cat ${BEE_SKIPLIST}
fi
for pattern in "${EXCLUDE[@]}" "${BEE_AUTO_EXCLUDE[@]}" ; do
echo "${pattern}"
done ) \
--cutroot \
${D} | \
${BEE_LIBEXECDIR}/bee/filelist2content --root ${D} > ${D}/CONTENT
DUMP=${BEE_TMP_TMPDIR}/bee.$$.dump
${BEE_LIBEXECDIR}/bee/content2filelist ${D}/CONTENT | sed -e "s,^,${D}," - > ${DUMP}
if [ ! -s "${D}/CONTENT" ]; then
print_error "ERROR: empty image directory"
exit 1
fi
cp ${BEE} ${D}/BUILD
create_meta
if [ -n "${bee_PATCHFILES[0]}" ] ; then
mkdir -pv ${D}/PATCHES
fi
for p in ${bee_PATCHFILES[@]} ; do
cp ${p} ${D}/PATCHES
done
if [ ! -d "${BEE_PKGDIR}" ] ; then
mkdir -pv ${BEE_PKGDIR}
fi
pkgname=${PKGALLPKG}.bee.tar.bz2
pkgfile=${BEE_PKGDIR}/${pkgname}
print_info " -> creating package ${pkgname} .."
print_info "${COLOR_CYAN}${pkgfile}"
tar cjvvf ${pkgfile} \
-T ${DUMP} \
--transform="s,${D},," \
--show-transformed-names \
--sparse \
--absolute-names \
--no-recursion \
--transform="s,^/CONTENT$,CONTENT," \
--transform="s,^/BUILD$,BUILD," \
--transform="s,^/META$,META," \
--transform="s,^/PATCHES,PATCHES," \
${D}/{CONTENT,BUILD,META} \
${bee_PATCHFILES:+${D}/PATCHES} \
${bee_PATCHFILES:+${D}/PATCHES/*}
rm ${DUMP}
beefilename=${BEE##*/}
beefiledest=${BEE_BEEDIR}/${beefilename}
print_info "-> saving bee-file ${beefilename} .."
print_info "${COLOR_CYAN}${beefiledest}"
if [ ! -d "${BEE_BEEDIR}" ] ; then
mkdir -pv ${BEE_BEEDIR}
fi
cp -v ${BEE} ${BEE_BEEDIR}
}
function bee_archivebuild() {
[ "${OPT_ARCHIVE_BUILD}" != "yes" ] && return
if [ ! -d "${BEE_BUILDARCHIVEDIR}" ] ; then
mkdir -pv ${BEE_BUILDARCHIVEDIR}
fi
archive="${BEE_BUILDARCHIVEDIR}/${PKGALLPKG}.beebuild.tar.bz2"
print_info " -> saving build environment.."
print_info "${COLOR_CYAN}${archive}"
if [ "${B}" = "${S}" ] ; then
B=${BEEWORKDIR}/build
fi
tar -cjf ${archive} \
--show-transformed-names \
--sparse \
--absolute-names \
${S} ${B} \
${bee_FETCHED_FILES[@]} \
${BEE_BEEDIR}/${BEE##*/} \
--transform="s,^${BEEWORKDIR},${PKGALLPKG}," \
--transform="s,^${F},${PKGALLPKG}/files," \
--transform="s,^${BEE_BEEDIR},${PKGALLPKG}/files,"
}
function load_buildmagic() {
local oIFS=${IFS}
local IFS=":${IFS}"
local magic=$1
if [ ! -z "${BEE_BUILDTYPE}" ] ; then
return
fi
for dir in ${XDG_CONFIG_HOME} ${XDG_CONFIG_DIRS} ${BEE_LIBEXECDIR} ; do
local IFS=${oIFS}
xdgmagic="${dir}/bee/beesh.d/${magic}.sh"
if [ -r "${xdgmagic}" ] ; then
. ${xdgmagic}
if [ ! -z "${BEE_BUILDTYPE}" ] ; then
break
fi
fi
done
if [ ! -z "${BEE_BUILDTYPE}" ] ; then
print_info "using magic buildtype '${BEE_BUILDTYPE}' from '${xdgmagic}' .."
fi
}
###############################################################################
###############################################################################
###############################################################################
function dump_variables() {
for i in P{,N{,F,E},F,V{,E,F,R},S,R} ${!PKG*} ${!BEE*} ${!DEF*} ${!OPT*} ${!DOT*} R F W S B D ; do
eval echo "${i}=\${${i}}"
done
}
function is_func() {
[ "$(type -t ${1})" == "function" ]
return $?
}
function bee_run() {
action=${1}
shift
if is_func "mee_${action}_pre" ; then
log_enter "mee_${action}_pre()"
mee_${action}_pre "${@}"
log_leave "mee_${action}_pre()"
fi
if is_func "mee_${action}" ; then
log_enter "mee_${action}()"
mee_${action} "${@}"
log_leave "mee_${action}()"
elif is_func "bee_${action}" ; then
log_enter "bee_${action}()"
bee_${action} "${@}"
log_leave "bee_${action}()"
else
print_error "don't know how to run '${action}'"
exit
fi
if is_func "mee_${action}_post" ; then
log_enter "mee_${action}_post()"
mee_${action}_post "${@}"
log_leave "mee_${action}_post()"
fi
}
###############################################################################
OPTIONS=$(${BEE_BINDIR}/beegetopt --name beesh \
--option help/h \
--option install/i \
--option force-install/f \
--option cleanup/c \
--option debug= \
--option archive-build \
--option no-archive-build \
--option check \
-- "$@")
if [ $? != 0 ] ; then
print_info "Terminating..." >&2
exit 1
fi
eval set -- "${OPTIONS}"
: ${OPT_INSTALL:="no"}
: ${OPT_CLEANUP:="no"}
: ${OPT_CHECK:="no"}
: ${OPT_ARCHIVE_BUILD:="yes"}
while true ; do
case "$1" in
--help)
show_help
exit 0
;;
--install)
OPT_INSTALL="yes"
shift
;;
--force-install)
OPT_INSTALL="yes"
OPT_FORCE="yes"
shift
;;
--update)
OPT_INSTALL="yes"
OPT_UPDATE="yes"
shift
;;
--cleanup)
OPT_CLEANUP="yes"
shift
;;
--no-archive-build)
OPT_ARCHIVE_BUILD="no"
shift
;;
--archive-build)
OPT_ARCHIVE_BUILD="yes"
shift
;;
--check)
OPT_CHECK="yes"
shift
;;
--debug)
DEBUG=$2
shift 2
;;
--)
shift
break
;;
*)
print_error "Internal error!"
exit 1
;;
esac
done
config_init_colors
echo -e "${COLOR_CYAN}BEE v${BEE_VERSION} 2009-2011"
echo -e " by Marius Tolzmann and Tobias Dreyer <{tolzmann,dreyer}@molgen.mpg.de>"
echo -e " Max Planck Institute for Molecular Genetics Berlin Dahlem"
echo -e "${COLOR_NORMAL}"
config_init
config_set_skiplist
print_info " BEE_SKIPLIST ${BEE_SKIPLIST}"
print_info " BEE_REPOSITORY_PREFIX ${BEE_REPOSITORY_PREFIX}"
print_info " BEE_METADIR ${BEE_METADIR}"
print_info " BEE_TMP_TMPDIR ${BEE_TMP_TMPDIR}"
print_info " BEE_TMP_BUILDROOT ${BEE_TMP_BUILDROOT}"
###############################################################################
###############################################################################
###############################################################################
BEE=$1
if [ "${BEE:0:1}" != "/" ] ; then
BEE=${PWD}/$BEE
fi
if [ ! -f "${BEE}" ] ; then
print_error "${BEE}: No such file."
exit 1
fi
### define pkg variables
PKGNAME=
PKGVERSION=
PKGREVISION=
eval $(${BEE_BINDIR}/beeversion ${BEE})
if [ -z "${PKGNAME}" -o -z "${PKGVERSION}" -o -z "${PKGREVISION}" ] ; then
print_error "${BEE}: please use the proper package versioning (e.g. package-1.0-0)"
exit 1
fi
PN=${PKGNAME}
PV=( ${PKGVERSION[@]} )
PS=${PKGEXTRAVERSION}
PR=${PKGREVISION}
P=${PKGFULLNAME}-${PKGFULLVERSION}
BEEPKGROOT="${BEE_TMP_BUILDROOT}/${PKGNAME}"
BEEWORKDIR="${BEEPKGROOT}/${PKGFULLPKG}"
R=${BEEPKGROOT}
W=${BEEWORKDIR}
F=${BEEPKGROOT}/files
S=${BEEWORKDIR}/source
B=${BEEWORKDIR}/build
D=${BEEWORKDIR}/image
###############################################################################
# clear PKGALLPKG since we can't trust PKGARCH in this state
PKGALLPKG=
# source file.bee
. ${BEE}
# now set PKGARCH if set or changed by user via ARCH=.. and not given via file.arch.bee
: ${PKGARCH:=${ARCH}}
# since PKGARCH is now known reconstruct PKGALLPKG
: ${PKGALLPKG:=${PKGFULLPKG}.${PKGARCH}}
config_handle_deprecated_beefile
expand_prefix_variables
###############################################################################
print_info "current working directory: ${PWD}"
bee_init_builddir
check_repositories
print_info "==> building ${PKGALLPKG} .."
bee_run getsources
bee_run extract ${bee_SOURCEFILES[@]}
print_info "changing to source directory: ${S}"
cd ${S}
bee_run patch ${bee_PATCHFILES[@]}
bee_buildmagic=$(${BEE_BINDIR}/beeuniq ${BEE_BUILDTYPE[@]} \
cmake \
configure \
autogen \
perl-module \
perl-module-makemaker \
make \
python-module)
BEE_BUILDTYPE=""
for t in ${bee_buildmagic[@]} ; do
load_buildmagic ${t}
if [ -n "${BEE_BUILDTYPE}" ] ; then
break
fi
done
print_info "changing to build directory: ${B}"
cd ${B}
bee_run configure
bee_run build
if [ "${OPT_CHECK}" != "no" ] ; then
bee_run check
fi
bee_run install
print_info "changing to image directory: ${D}"
cd ${D}
bee_crosscheck
bee_pkg_pack
cd ${BEEWORKDIR}
bee_archivebuild
echo
print_info "==================================================================="
print_info "build summary:"
print_info ""
print_info "download directory \${F}: ${COLOR_NORMAL}${F}"
print_info " source directory \${S}: ${COLOR_NORMAL}${S}"
print_info " build directory \${B}: ${COLOR_NORMAL}${B}"
print_info " image directory \${D}: ${COLOR_NORMAL}${D}"
print_info ""
print_info " bee-file: ${COLOR_NORMAL}${beefiledest}"
print_info " pkg-file: ${COLOR_NORMAL}${pkgfile}"
print_info "build-archive: ${COLOR_NORMAL}${archive}"
print_info "==================================================================="
echo
if [ "${OPT_INSTALL}" = "yes" ] ; then
config_export
print_info "installing ${PKGALLPKG} .."
${BEE_LIBEXECDIR}/bee/bee.d/bee-install ${OPT_FORCE:+-f} ${OPT_UPDATE:+-u} ${BEE_PKGDIR}/${PKGALLPKG}.bee.tar.bz2
fi