Skip to content

Commit

Permalink
Merge branch 'beecontent' of https://github.com/tewdreyer/bee
Browse files Browse the repository at this point in the history
* 'beecontent' of https://github.com/tewdreyer/bee:
  beesh: integrate new beefind
  beefind: rename option '--skiplist' to '--exclude-list' to easily integrate the new beefind
  beefind: bugfix: cutting rootdir before excluding files
  beefind: some KISSing
  content2filelist: new utility to extract files from a CONTENT file
  filelist2content: new utility to convert a filelist to new CONTENT file output
  • Loading branch information
mariux committed May 22, 2012
2 parents 6a6c1cb + 5742224 commit e1d1905
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PROGRAMS_PERL=beefind.pl
HELPER_BEE_SHELL=bee-init bee-check bee-remove bee-install bee-list bee-query bee-download bee-update
HELPER_BEE_C=bee-dep

HELPER_SHELL=compat-filesfile2contentfile
HELPER_SHELL=compat-filesfile2contentfile filelist2content content2filelist

LIBRARY_SHELL=beelib.config.sh

Expand Down
183 changes: 35 additions & 148 deletions src/beefind.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# beefind - scan directory and print files and metadata
# beefind - scan directory and print files
#
# Copyright (C) 2009-2012
# Tobias Dreyer <dreyer@molgen.mpg.de>
Expand Down Expand Up @@ -31,79 +31,33 @@ BEE_VERSION="@BEE_VERSION@"

: ${BEEVERSION:=${BEE_BINDIR}/beeversion}
: ${BEESEP=${BEE_BINDIR}/beesep}
: ${BEEGETOPT:=${BEE_BINDIR}/beegetopt}

function usage() {
cat <<-EOF
beefind v${BEE_VERSION} 2009-2012
by Tobias Dreyer and Marius Tolzmann <{dreyer,tolzmann}@molgen.mpg.de>
Max Planck Institute for Molecular Genetics Berlin Dahlem
Usage: beefind [options] <files>
Usage: beefind [options] <directory>
Options:
-c | --cutroot <path> strip <path> from displayed files
-e | --exclude <pattern> ignore files matching <pattern>
-s | --skiplist <file> ignore files matching pattern described in <file>
-c, --cutroot <path> strip <path> from printed files
-e, --exclude <pattern> ignore files matching <pattern>
-s, --exclude-list <file> ignore files matching pattern described in <file>
-o | --output <file> output is redirected into <file> instead of <stdout>
-d | --dump-files <file> read <file> and just display files; <file> must contain
beefind output
-o, --output <file> output is redirected into <file> instead of <stdout>
-h | --help display this help
-h, --help display this help
EOF
}

function dump_files() {
local infile=${1}

if [ ! -r "${infile}" ] ; then
print_warning "cannot read file '${infile}'"
exit 1
fi

for line in $(cat ${infile}) ; do
eval $(${BEESEP} ${line})

echo ${file%//*}
done
}

function get_md5() {
local file=${1}

if [ -L "${file}" ] ; then
md5='link'
elif [ -d "${file}" ] ; then
md5='directory'
elif [ -f "${file}" ] ; then
md5=$(md5sum ${file})
md5=${md5%% *}
if [ "$?" != 0 -o -z "${md5}" ] ; then
print_warning "failed to create md5 sum for ${file}"
md5='#MD5ERROR#'
fi
elif [ -p "${file}" ] ; then
md5='pipe'
elif [ -S "${file}" ] ; then
md5='socket'
elif [ -b "${file}" ] ; then
md5='block'
elif [ -c "${file}" ] ; then
md5='char'
elif [ -S "${file}" ] ; then
md5='socket'
else
md5='#MD5UNKNOWN#'
fi

echo ${md5}
}

function bee_find() {
local options=$(${BEE_BINDIR}/beegetopt --name beefind \
function do_beefind() {
local options=$(${BEEGETOPT} --name beefind \
--option cutroot/c \
--option exclude/e= \
--option skiplist/s= \
--option exclude-list/E= \
-- "${@}")

if [ $? != 0 ] ; then
Expand All @@ -113,17 +67,22 @@ function bee_find() {

eval set -- "${options}"

declare find_format="%p\n"
declare -a OPT_EXCLUDE
declare -a OPT_SKIPLSIT
declare -a OPT_EXCLUDELIST

while true ; do
case "${1}" in
--cutroot)
find_format="/%P\n"
shift 1
;;
--exclude)
OPT_EXCLUDE=( ${OPT_EXCLUDE:+${OPT_EXCLUDE[@]}} "${2}" )
OPT_EXCLUDE=( "${OPT_EXCLUDE[@]}" "${2}" )
shift 2
;;
--skiplist)
OPT_SKIPLIST=( ${OPT_SKIPLIST:+${OPT_SKIPLIST[@]}} "${2}" )
--exclude-list)
OPT_EXCLUDELIST=( "${OPT_EXCLUDELIST[@]}" "${2}" )
shift 2
;;
--)
Expand All @@ -133,88 +92,31 @@ function bee_find() {
esac
done

if [ -z "${1}" ] ; then
print_warning "no directory to scan specified"
exit 1
fi

find ${1} -mindepth 1 | \
grep \
--extended-regexp \
--invert-match \
--file=<(if [ "${#OPT_SKIPLIST[@]}" -gt 0 ] ; then
grep --invert-match --regexp="^ *$" ${OPT_SKIPLIST[@]}
fi) \
--file=<(for p in ${OPT_EXCLUDE[@]} ; do
echo ${p}
done)
}

function do_beefind() {
local options=$(${BEE_BINDIR}/beegetopt --name beefind \
--option cutroot/c= \
-- "${@}")

if [ $? != 0 ] ; then
if [ -z "${@}" ] ; then
usage
exit 1
fi

eval set -- "${options}"

declare OPT_CUTROOT=

while true ; do
case "${1}" in
--cutroot)
OPT_CUTROOT="${2}"
shift 2
;;
--)
shift
break
;;
esac
done

for f in $(cat <(bee_find ${@})) ; do
md5=$(get_md5 ${f})

data=( $(stat -c "%05a %h %u %g %s %Y" ${f}) )
if [ "$?" != 0 -o -z "${data}" ] ; then
print_warning "can't stat ${f}"
exit 1
fi

echo -n "md5=${md5}:"
echo -n "omode=${data[0]}:"
echo -n "nlink=${data[1]}:"
echo -n "uid=${data[2]}:"
echo -n "gid=${data[3]}:"
echo -n "size=${data[4]}:"
echo -n "mtime=${data[5]}:"

filename=${f}
if [ -n "${OPT_CUTROOT}" ] ; then
filename=${f#${OPT_CUTROOT}}
fi
echo -n "file=${filename}"

if [ "${md5}" = "link" ] ; then
echo -n "//$(readlink ${f})"
fi

echo ""
done
dirs=( "${@}" )

grep \
--extended-regexp \
--invert-match \
--file=<(if [ "${#OPT_EXCLUDELIST[@]}" -gt 0 ] ; then
grep --invert-match --regexp="^ *$" ${OPT_EXCLUDELIST[@]}
fi) \
--file=<(for p in ${OPT_EXCLUDE[@]} ; do
echo ${p}
done) \
<(find ${dirs[@]} -mindepth 1 -xdev -printf ${find_format})
}

###############################################################################
###############################################################################
###############################################################################

options=$(${BEE_BINDIR}/beegetopt --name beefind \
options=$(${BEEGETOPT} --name beefind \
--option output/o= \
--option dump-files/d= \
--option help/h \
-- "${@}")

Expand All @@ -226,18 +128,13 @@ fi
eval set -- "${options}"

declare OPT_OUTPUT=
declare OPT_DUMPFILES=

while true ; do
case "${1}" in
--output)
OPT_OUTPUT="${2}"
shift 2
;;
--dump-files)
OPT_DUMPFILES="${2}"
shift 2
;;
--help)
usage
exit 0
Expand All @@ -256,14 +153,4 @@ if [ -n "${OPT_OUTPUT}" ] ; then
fi
fi

if [ -n "${OPT_DUMPFILES}" ] ; then
if [ ! -r "${OPT_DUMPFILES}" ] ; then
print_warning "cannot read file '${OPT_DUMPFILES}'"
exit 1
fi

dump_files ${OPT_DUMPFILES}
exit 0
fi

do_beefind ${@}
18 changes: 11 additions & 7 deletions src/beesh.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ VERSION=${BEE_VERSION}
: ${BEE_LIBEXECDIR:=@LIBEXECDIR@}
: ${BEE_BINDIR:=@BINDIR@}

: ${BEEFIND:=${BEE_BINDIR}/beefind}

# load libs
. ${BEE_LIBEXECDIR}/bee/beelib.config.sh

Expand Down Expand Up @@ -433,21 +435,23 @@ function bee_crosscheck() {
# $EXCLUDE is read from .bee file
# $BEE_SKIPLIST is found in $BEEFAULTS
function bee_pkg_pack() {
beefind.pl --exclude='^/FILES$' \
--excludelist=<(
${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} ${D} > ${D}/FILES 2>/dev/null
--cutroot \
${D} | \
${BEE_LIBEXECDIR}/bee/filelist2content --root ${D} > ${D}/CONTENT

DUMP=${BEE_TMP_TMPDIR}/bee.$$.dump

beefind.pl --dump ${D}/FILES | sed -e "s,^,${D}," - > ${DUMP}
${BEE_LIBEXECDIR}/bee/content2filelist ${D}/CONTENT | sed -e "s,^,${D}," - > ${DUMP}

if [ ! -s "${D}/FILES" ]; then
if [ ! -s "${D}/CONTENT" ]; then
print_error "ERROR: empty image directory"
exit 1
fi
Expand Down Expand Up @@ -480,11 +484,11 @@ function bee_pkg_pack() {
--sparse \
--absolute-names \
--no-recursion \
--transform="s,^/FILES$,FILES," \
--transform="s,^/CONTENT$,CONTENT," \
--transform="s,^/BUILD$,BUILD," \
--transform="s,^/META$,META," \
--transform="s,^/PATCHES,PATCHES," \
${D}/{FILES,BUILD,META} \
${D}/{CONTENT,BUILD,META} \
${bee_PATCHFILES:+${D}/PATCHES} \
${bee_PATCHFILES:+${D}/PATCHES/*}

Expand Down
44 changes: 44 additions & 0 deletions src/content2filelist.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
#
# content2filelist - extract files from content file
#
# Copyright (C) 2009-2012
# Tobias Dreyer <dreyer@molgen.mpg.de>
# Marius Tolzmann <tolzmann@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/>.

: ${BEESEP=@BINDIR@/beesep}

while read line ; do
unset type
data=$(${BEESEP} ${line})

if [ "$?" -gt 0 ] ; then
echo >&2 "**ERROR** INVALID CONTENT: ${line}"
exit 1
fi

eval ${data}

if [ "$?" -gt 0 -o -z "${type}" ] ; then
echo >&2 "**ERROR** UNPARSABLE CONTENT: ${line}"
exit 1
fi

echo ${file%//*}
done < <(cat ${@})
Loading

0 comments on commit e1d1905

Please sign in to comment.