Skip to content

Commit

Permalink
Merge branch 'bee-remove'
Browse files Browse the repository at this point in the history
* bee-remove:
  bee-remove: Remove --noop option..
  bee-remove: Use BEE_VERSION in usage
  bee-remove: Add bee-query wrapper function
  bee-remove: Cleanup: move bee-cache wrapper function to the top
  bee-remove: Add bee-list wrapper function
  bee-remove: Define BEE_LIBEXECDIR if not set
  bee-remove: Use function keyword for functions
  • Loading branch information
mariux committed Jul 30, 2012
2 parents 994a04a + c236e29 commit 3bf01a7
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/bee-remove.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,28 @@ if [ -z "${BEE_VERSION}" ] ; then
exit 1
fi

VERSION=${BEE_VERSION}

: ${BEE_BINDIR:=@BINDIR@}
: ${BEE_LIBEXECDIR:=@LIBEXECDIR@}

function bee-cache() {
${BEE_LIBEXECDIR}/bee/bee.d/bee-cache "${@}"
}

function bee-list() {
${BEE_LIBEXECDIR}/bee/bee.d/bee-list "${@}"
}

pkg_remove_all() {
function bee-query() {
${BEE_LIBEXECDIR}/bee/bee.d/bee-query "${@}"
}

function pkg_remove_all() {
for pkg in "${@}" ; do
pkg_remove "${pkg}"
done
}

pkg_remove() {
function pkg_remove() {
search=$1

# pattern is a pkg in BEE_METADIR
Expand All @@ -50,14 +61,10 @@ pkg_remove() {
# pattern is no installed pkg
# show all pkgs that match pattern
echo "${search} matches following packages .."
${BEE_LIBEXECDIR}/bee/bee.d/bee-list -i "${search}"
bee-list -i "${search}"
}

function bee-cache() {
${BEE_LIBEXECDIR}/bee/bee.d/bee-cache "${@}"
}

do_remove() {
function do_remove() {
pkg=${1}

mv ${BEE_METADIR}/${pkg}/CONTENT{,.bee-remove} 2>/dev/null
Expand All @@ -71,22 +78,20 @@ do_remove() {
exit 1
fi

[ "${NOOP}" != "yes" ] && \
run_hooks pre-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove
run_hooks pre-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove

FILES=( $(bee-cache --tmpinstall "${pkg}" print-uniq-files "${pkg}") )

# removing files
for f in "${FILES[@]}" ; do
if [ -d "${f}" -a ! -h "$f" ] ; then
${NOOP:+echo} rmdir ${OPT_VERBOSE:+-v} ${f}
rmdir ${OPT_VERBOSE:+-v} ${f}
else
${NOOP:+echo} rm -f ${OPT_VERBOSE:+-v} ${f}
rm -f ${OPT_VERBOSE:+-v} ${f}
fi
done

[ "${NOOP}" != "yes" ] && \
run_hooks post-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove
run_hooks post-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove

if [ -r "${BEE_METADIR}/${pkg}/META" ] ; then
. "${BEE_METADIR}/${pkg}/META"
Expand Down Expand Up @@ -121,14 +126,14 @@ do_remove() {
# this may be fixed automatically once bee query doesn't scan the
# filesystem anymore and we have an index db 8)
# using bee dep here is currently to slow 8(
if [ -z "$(${BEE_LIBEXECDIR}/bee/bee.d/bee-query ${dir} | head -1)" ] ; then
${NOOP:+echo} rmdir ${OPT_VERBOSE:+-v} ${dir}
if [ -z "$(bee-query ${dir} | head -1)" ] ; then
rmdir ${OPT_VERBOSE:+-v} ${dir}
fi
done
fi

#cleanup meta directory
${NOOP:+echo} rm -fr ${OPT_VERBOSE:+-v} ${BEE_METADIR}/${pkg}
rm -fr ${OPT_VERBOSE:+-v} ${BEE_METADIR}/${pkg}
bee-cache update ${pkg}
}

Expand All @@ -143,24 +148,22 @@ function run_hooks() {
done
}

usage() {
function usage() {
cat <<-EOF
bee-remove v${VERSION} 2009-2012
bee-remove v${BEE_VERSION} 2009-2012
by Marius Tolzmann and Tobias Dreyer <{tolzmann,dreyer}@molgen.mpg.de>
Max Planck Institute for Molecular Genetics Berlin Dahlem
Usage: bee remove [options] <package>
Options:
-h, --help display this help
-n, --noop do not actually remove; just print
-v, --verbose print removed files and directories
EOF
}

options=$(${BEE_BINDIR}/beegetopt --name bee-remove \
--option noop/n \
--option verbose/v \
--option help/h \
-- "$@")
Expand All @@ -173,10 +176,6 @@ eval set -- "${options}"

while true ; do
case "$1" in
--noop)
shift
NOOP="yes"
;;
--help)
usage
exit
Expand Down

0 comments on commit 3bf01a7

Please sign in to comment.