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
357 lines (287 sloc) 8.78 KB
#!/bin/bash
#
# bee-check - check consistency of installed bee-pkgs
#
# 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/>.
#
BEESEP=@BINDIR@/beesep
###############################################################################
###############################################################################
###############################################################################
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@}
function bee-list() {
${BEE_LIBEXECDIR}/bee/bee.d/bee-list "${@}"
}
###############################################################################
##
##
function pkg_check_all() {
if [ ! "${1}" ] ; then
pkg_check
return
fi
for pkg in "${@}" ; do
pkg_check "${pkg}"
done
}
###############################################################################
##
##
function pkg_check_deps() {
installed=$(bee-list --installed --by-pkgfullname ${1})
if [ ! "${installed}" -a $OPT_F -gt 0 ] ; then
installed=$(bee-list --installed "${1}")
fi
if [ "${installed}" ] ; then
for pkg in ${installed} ; do
do_check_deps "${pkg}"
done
fi
exit 0
}
###############################################################################
##
##
function pkg_check() {
installed=$(bee-list --installed --by-pkgfullname ${1})
if [ ! "${installed}" -a $OPT_F -gt 0 ] ; then
installed=$(bee-list --installed "${1}")
fi
if [ "${installed}" ] ; then
for pkg in ${installed} ; do
do_check "${pkg}"
done
return 0
fi
installed=$(bee-list --installed "${1}")
if [ "${installed}" ] ; then
echo "packages matching '${1}':"
for i in ${installed} ; do
echo " [*] ${i}"
done
fi
}
function do_check_deps_of_file() {
local file=${1}
local type="OTHER"
local filetype=$(file ${file})
case "${filetype}" in
*"ar archive"*)
type="AR"
;;
*"ELF 64-bit LSB executable, x86-64"*)
type="ELF64EXE"
;;
*"ELF 64-bit LSB shared object, x86-64"*)
type="ELF64SO"
;;
*"ELF 32-bit LSB executable"*)
type="ELF32EXE"
;;
*"ELF 32-bit LSB shared object"*)
type="ELF32SO"
;;
*"script text executable"*)
type="SCRIPT"
;;
*"directory"*)
type="DIRECTORY"
;;
*"symbolic link"*)
type="SYMLINK"
;;
*)
#echo >&2 "WARNING: unknown file type '${filetype#*: }'"
esac
echo " type = ${type^^}"
# self provide basename seems not to be a good idea without
# defining
# echo " provides = ${file##*/}"
if [ "${type:0:3}" = "ELF" ] ; then
readelf -d ${file} 2>/dev/null \
| egrep "(NEEDED|SONAME)" \
| sed -e 's,.*Shared library: \[\(.*\)\].*, needs = \1,' \
-e 's,.*Library soname: \[\(.*\)\].*, provides = \1,'
if [ "${type:5:2}" = "SO" ] ; then
echo " provides = ${file##*/}"
fi
fi
if [ "${type}" = "SCRIPT" ] ; then
subtype=$(grep '#!' "${file}")
subtype=( ${subtype:2} )
for i in "${subtype[@]}" ; do
if [ "${i:0:1}" = "/" ] ; then
echo " needs = $i"
break
fi
done
fi
}
###############################################################################
##
##
function do_check_deps() {
local pkg=${1}
local filesfile=${BEE_METADIR}/${pkg}/CONTENT
echo -e "[${pkg}]"
eval $(@BINDIR@/beeversion "${pkg}")
echo " type = PACKAGE"
echo " provides = ${PKGNAME}"
echo " provides = ${PKGFULLPKG}"
while read line; do
eval $(${BEESEP} "${line}")
echo " provides = ${file%%//*}"
done < "${filesfile}"
while read line; do
eval $(${BEESEP} "${line}")
# save and strip possible symbolic link destination..
symlink=${file#*//}
file=${file%%//*}
echo -e "\n[${file}]"
echo " mode = ${mode}"
echo " nlink = ${nlink}"
echo " uid = ${uid}"
echo " gid = ${gid}"
echo " size = ${size}"
echo " mtime = ${mtime}"
if [ "${type}" = "symlink" ] ; then
echo " symlink = ${symlink}"
elif [ "${type}" = "regular" -o "${type}" = "hardlink" ] ; then
echo " md5 = ${md5}"
fi
do_check_deps_of_file "${file}"
done < "${filesfile}"
}
###############################################################################
##
##
function do_check() {
local pkg=${1}
local stat
local full
local filesfile=${BEE_METADIR}/${pkg}/CONTENT
echo "checking ${pkg} .."
while read line ; do
eval $(${BEESEP} "${line}")
# save and strip possible symbolic link destination..
symlink=${file#*//}
file=${file%%//*}
if [ ! -e "${file}" ] && [ ! -h "${file}" ]; then
if [ "${type}" = "directory" ] ; then
md5="${type}"
fi
echo " [missing] <${md5}> ${file}"
continue
fi
if [ "${type}" = "symlink" ] ; then
if [ ! -h "${file}" ] ; then
echo " [changed] <was symlink to ${symlink}> ${file}"
else
sdest=$(readlink "${file}")
if [ "${sdest}" != "${symlink}" ] ; then
echo " [changed] <symlink destination '${symlink}' != '${sdest}'> ${file}"
fi
#echo " [ DEBUG ] <OK> ${file} -> ${symlink}"
fi
continue
fi
if [ "${type}" = "directory" ] ; then
if [ ! -d "${file}" ] ; then
echo " [changed] <was directory> ${file}"
continue
fi
else
# regular file - check md5sum..
md5now=$(md5sum "${file}" | sed -e 's,^\([a-z0-9]*\).*$,\1,')
if [ "${md5}" != "${md5now}" ] ; then
echo " [changed] <md5 ${md5} != ${md5now}> ${file}"
fi
fi
# check mode, uid and gid of directory/file
stat=( $(stat "${file}" --printf "%f %u %g %U %G") )
full=$(printf "0%o" 0x${stat[0]})
if [ "${mode}" != "${full}" ] ; then
echo " [changed] <mode ${mode} != ${full}> ${file}"
fi
if [ "${uid}" != "${stat[1]}" ] ; then
echo " [changed] <uid ${uid} (${user}) != ${stat[1]} (${stat[3]})> ${file}"
fi
if [ "${gid}" != "${stat[2]}" ] ; then
echo " [changed] <gid ${gid} (${group}) != ${stat[2]} (${stat[4])})> ${file}"
fi
done < "${filesfile}"
}
##### usage ###################################################################
function usage() {
cat <<-EOF
bee-check v${VERSION} 2009-2016
by Marius Tolzmann <m@rius.berlin> and Tobias Dreyer <dreyer@molgen.mpg.de>
Usage: bee check [options] [action] <package>
Actions:
-d, --deps,
--dependencies print dependencies of the package
-h, --help display this help
Options:
-f, --force can be used to force check come what may
EOF
}
###############################################################################
##
##
options=$(${BEE_BINDIR}/beegetopt --name bee-check \
--option force/f \
--option help/h \
--option dependencies/deps/d \
-- "$@")
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "${options}"
declare -i OPT_F=0
while true ; do
case "$1" in
--force)
shift;
OPT_F=$OPT_F+1
;;
--dependencies)
shift 2;
pkg_check_deps "${@}"
exit 0
;;
--help)
usage
exit 0
;;
*)
shift
pkg_check_all "${@}"
exit 0;
;;
esac
done