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
352 lines (301 sloc) 8.53 KB
#!/bin/bash
#
# bee-list - list bee packages
#
# 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/>.
#
#
# bee list -i - list installed
# bee list -a - list available
# bee list -u - list updatable
# bee list -U - list uninstalled
# bee list -s - list status (installed, uninstalled, updatable, available)
# --sorted - pipe through beesort
# --max - only list highest versions
# --format "" - print formated
#
if [ -z "${BEE_VERSION}" ] ; then
echo >&2 "BEE-ERROR: please call $0 from bee .."
exit 1
fi
VERSION=${BEE_VERSION}
: ${BEE_BINDIR:=@BINDIR@}
: ${BEE_LIBEXECDIR:=@LIBEXECDIR@}
: ${BEESORT:=${BEE_BINDIR}/beesort}
function bee-list() {
${BEE_LIBEXECDIR}/bee/bee.d/bee-list "${@}"
}
#
# BUGS TO FIX/FEATURES TO ADD:
# - check for grep -P support and use it..
ARCH=$(uname -m)
#
# print usage information
#
function usage() {
cat <<-EOF
bee-list v${VERSION} 2009-2016
by Marius Tolzmann <m@rius.berlin> and Tobias Dreyer <dreyer@molgen.mpg.de>
Usage: bee list <action> [pattern list]
Actions:
-i, --installed (default) list installed packages
-a, --available list available packages
-u, --updatable list packages which can be updated
-U, --uninstalled list uninstalled packages
--exact, --by-pkgfullname exact match
--display-pathname print pathname
-h, --help display this help
EOF
}
function config_init_colors() {
: ${BEE_COLOR:="yes"}
if [ ! -t 1 ] ; then
BEE_COLOR="no"
fi
if [ "${BEE_COLOR}" != "no" ] ; then
COLOR_NORMAL="\\033[0;39m\\033[0;22m"
COLOR_GREEN="\\033[0;32m"
COLOR_YELLOW="\\033[0;33m"
COLOR_RED="\\033[0;31m"
COLOR_CYAN="\\033[0;36m"
COLOR_BLUE="\\033[0;34m"
COLOR_PURPLE="\\033[0;35m"
COLOR_BRACKET=${COLOR_PURPLE}
COLOR_BRCONTENT=${COLOR_YELLOW}
COLOR_INFO=${COLOR_GREEN}
COLOR_ERROR=${COLOR_RED}
COLOR_WARN=${COLOR_YELLOW}
COLOR_INSTALLABLE="${COLOR_YELLOW}installable${COLOR_NORMAL} "
COLOR_UPDATABLE=" ${COLOR_GREEN}updatable${COLOR_NORMAL} "
else
COLOR_NORMAL=""
COLOR_GREEN=""
COLOR_YELLOW=""
COLOR_RED=""
COLOR_CYAN=""
COLOR_BLUE=""
COLOR_PURPLE=""
COLOR_BRACKET=""
COLOR_BRCONTENT=""
COLOR_INFO=""
COLOR_ERROR=""
COLOR_WARN=""
COLOR_INSTALLABLE="installable "
COLOR_UPDATABLE=" updatable "
fi
}
function print_warning() {
echo >&2 -e "WARNING: ${@}"
}
function list_installed_packages() {
if [ ! -r "${BEE_METADIR}" ] ; then
return
fi
find ${BEE_METADIR} \
-mindepth 2 \
-maxdepth 2 \
-type f \
-name CONTENT \
-printf "%P\n" \
| sed -e 's,/CONTENT$,,'
}
function list_available_packages() {
: ${BEE_PKGPATH:=${BEE_PKGDIR}}
path=${BEE_PKGPATH//:/ }
search=""
for p in ${path} ; do
if [ -r "${p}" ] ; then
search="${search} ${p}"
else
print_warning "can't read BEE_PKGPATH element '${p}' .. skipping."
fi
done
if [ -z "${search}" ] ; then
return
fi
if [ "${OPT_PATHNAME}" == "yes" ] ; then
find ${search} -mindepth 1 -maxdepth 1 -printf "%p\n"
else
find ${search} -mindepth 1 -maxdepth 1 -printf "%f\n" \
| sed -e "s@\.iee\.tar\..*\$@@" \
-e "s@\.bee\.tar\..*\$@@"
fi
}
function list_installed() {
list_installed_packages | ${BEESORT}
}
function list_available() {
list_available_packages | ${BEESORT}
}
function bee_list_packages() {
local lister="list_beepackages"
local filter=$1
shift
if [ "${OPT_EXACT}" = "yes" ] ; then
lister="bee_list_exact"
fi
if [ ! ${#@} -gt 0 ] ; then
${lister} "${filter}"
fi
for p in "${@}" ; do
${lister} "${filter}" ${p}
done
}
#
# list bee packages
# ARGUMENTS are $mode (installed|available) and a list of $patterns
# RETURNS a list of $mode packages matching all given $patterns
#
function list_beepackages() {
mode=${1}
shift
# if more than one pattern is given all patterns have to match (AND)
thegrep=""
for p in "${@}" ; do
thegrep="${thegrep} | grep -i -F -e '${p}' "
done
if [ "${mode}" = "available" ] ; then
list_cmd="list_available"
else
list_cmd="list_installed"
fi
# execute the search and display results..
eval ${list_cmd} ${thegrep}
}
function bee_list_exact() {
filter=${1}
shift
if [ ! -z ${2} ] ; then
echo >&2 "argument error: --by-pkgfullname only takes one package at a time .."
exit 1
fi
for p in $(list_beepackages "${filter}" ${1}) ; do
pall=$(@BINDIR@/beeversion --pkgallpkg "${p}")
if [ "${1}" = "${pall}" ] ; then
echo "${p}"
continue
fi
pname=$(@BINDIR@/beeversion --pkgfullname "${p}")
if [ "${1}" = "${pname}" ] ; then
echo "${p}"
continue
fi
pfull=$(@BINDIR@/beeversion --pkgfullpkg "${p}")
if [ "${1}" = "${pfull}" ] ; then
echo "${p}"
fi
done
}
function list_updatable() {
local search=${1}
pkgs=$(bee_list_packages "available" ${search})
if [ -z "${pkgs}" ] ; then
return
fi
pkgs=$(${BEE_BINDIR}/beeversion --max ${pkgs})
for a in ${pkgs} ; do
pname=$(${BEE_BINDIR}/beeversion --pkgfullname "${a}")
installed=$(bee-list --exact "${pname}")
if [ -z "${installed}" ] ; then
if [ "${OPT_UNINSTALLED}" = "yes" ] ; then
echo -e "${COLOR_INSTALLABLE}${a}${COLOR_NORMAL}"
fi
continue
fi
maxinstalled=$(${BEE_BINDIR}/beeversion --max ${installed})
maxall=$(${BEE_BINDIR}/beeversion --max ${maxinstalled} ${a})
if [ "${maxall}" != "${maxinstalled}" ] ; then
if [ "${OPT_UPDATABLE}" = "yes" ] ; then
echo -e "${COLOR_UPDATABLE}${a}${COLOR_NORMAL}"
fi
fi
done
}
################################################################################
################################################################################
################################################################################
options=$(${BEE_BINDIR}/beegetopt --name bee-list \
--option available/a \
--option installed/i \
--option updatable/u \
--option uninstalled/U \
--option display-pathname \
--option exact/by-pkgfullname \
--option help/h \
-- "$@")
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "${options}"
filter=""
OPT_EXACT="no"
OPT_PATHNAME="no"
OPT_UPDATABLE="no"
OPT_UNINSTALLED="no"
while true ; do
case "$1" in
--help)
usage
exit 0
;;
--available)
shift
filter="available"
;;
--installed)
shift
filter="installed"
;;
--updatable)
shift;
OPT_UPDATABLE="yes"
;;
--uninstalled)
shift;
OPT_UNINSTALLED="yes"
;;
--exact)
shift
OPT_EXACT="yes"
;;
--display-pathname)
shift
OPT_PATHNAME="yes"
;;
--)
shift
break
;;
esac
done
config_init_colors
if [ "${OPT_UPDATABLE}" = "yes" -o "${OPT_UNINSTALLED}" = "yes" ] ; then
if [ ! ${#@} -gt 0 ] ; then
list_updatable
fi
for p in "${@}" ; do
list_updatable ${p}
done
exit 0
fi
# mach et einfach.. (just do it)
bee_list_packages "${filter}" "${@}"