Skip to content

Commit

Permalink
Merge branch 'fixes' of https://github.com/ruester/bee
Browse files Browse the repository at this point in the history
* 'fixes' of https://github.com/ruester/bee:
  bee-query: declare bash functions with keyword 'function'
  bee-check: declare bash functions with keyword 'function'
  beegetopt: free memory before exiting
  bee-query: fix reading the CONTENT file and the filename handling
  bee-check: fix reading the CONTENT file and the filename handling
  beecut: exit if getopt_long_only returns an error
  • Loading branch information
mariux committed Feb 26, 2013
2 parents 698d0e7 + 7ea346c commit 726ce24
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
26 changes: 13 additions & 13 deletions src/bee-check.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ VERSION=${BEE_VERSION}
###############################################################################
##
##
pkg_check_all() {
function pkg_check_all() {

if [ ! "${1}" ] ; then
pkg_check
Expand All @@ -57,7 +57,7 @@ pkg_check_all() {
###############################################################################
##
##
pkg_check_deps() {
function pkg_check_deps() {
installed=$(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed --by-pkgfullname ${1})

if [ ! "${installed}" -a $OPT_F -gt 0 ] ; then
Expand All @@ -75,7 +75,7 @@ pkg_check_deps() {
###############################################################################
##
##
pkg_check() {
function pkg_check() {
installed=$(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed --by-pkgfullname ${1})

if [ ! "${installed}" -a $OPT_F -gt 0 ] ; then
Expand All @@ -101,7 +101,7 @@ pkg_check() {

}

do_check_deps_of_file() {
function do_check_deps_of_file() {
local file=${1}
local type="OTHER"

Expand Down Expand Up @@ -175,7 +175,7 @@ do_check_deps_of_file() {
###############################################################################
##
##
do_check_deps() {
function do_check_deps() {
local pkg=${1}
local filesfile=${BEE_METADIR}/${pkg}/CONTENT

Expand Down Expand Up @@ -222,16 +222,16 @@ do_check_deps() {
###############################################################################
##
##
do_check() {
function do_check() {
local pkg=${1}
local stat
local full
local filesfile=${BEE_METADIR}/${pkg}/CONTENT

echo "checking ${pkg} .."

for line in $(cat ${filesfile}) ; do
eval $(${BEESEP} ${line})
while read line ; do
eval $(${BEESEP} "${line}")

# save and strip possible symbolic link destination..
symlink=${file#*//}
Expand All @@ -246,7 +246,7 @@ do_check() {
if [ ! -h "${file}" ] ; then
echo " [changed] <was symlink to ${symlink}> ${file}"
else
sdest=$(readlink ${file})
sdest=$(readlink "${file}")
if [ "${sdest}" != "${symlink}" ] ; then
echo " [changed] <symlink destination '${symlink}' != '${sdest}'> ${file}"
fi
Expand All @@ -262,7 +262,7 @@ do_check() {
fi
else
# regular file - check md5sum..
md5now=$(md5sum ${file} | sed -e 's,^\([a-z0-9]*\).*$,\1,')
md5now=$(md5sum "${file}" | sed -e 's,^\([a-z0-9]*\).*$,\1,')

if [ "${md5}" != "${md5now}" ] ; then
echo " [changed] <md5 ${md5} != ${md5now}> ${file}"
Expand All @@ -271,7 +271,7 @@ do_check() {

# check mode, uid and gid of directory/file

stat=( $(stat ${file} --printf "%f %u %g %U %G") )
stat=( $(stat "${file}" --printf "%f %u %g %U %G") )

full=$(printf "0%o" 0x${stat[0]})

Expand All @@ -286,12 +286,12 @@ do_check() {
if [ "${gid}" != "${stat[2]}" ] ; then
echo " [changed] <gid ${gid} (${group}) != ${stat[2]} (${stat[4])})> ${file}"
fi
done
done < "${filesfile}"

}

##### usage ###################################################################
usage() {
function usage() {
cat <<-EOF
bee-check v${VERSION} 2009-2012
by Marius Tolzmann and Tobias Dreyer <{tolzmann,dreyer}@molgen.mpg.de>
Expand Down
22 changes: 11 additions & 11 deletions src/bee-query.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ usage() {
EOF
}

query() {
function query() {
list=$@

for f in "${list[@]}" ; do
Expand All @@ -57,36 +57,36 @@ query() {
eval $(${BEE_BINDIR}/beeversion $base)
get_files "${PKGALLPKG}"
else
get_pkgs ${f}
get_pkgs "${f}"
fi
done
}

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

for s in "" "${BEE_METADIR}" ; do
ff="${s}/${pkg}/CONTENT"
if [ -e "${ff}" ] ; then
for line in $(cat ${ff}) ; do
eval $(${BEESEP} ${line})
while read line ; do
eval $(${BEESEP} "${line}")
echo ${file}
done
done < "${ff}"
fi
done
}

get_pkgs() {
function get_pkgs() {
f=$1

for pkg in $(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed) ; do

if egrep -q "file=.*${f}" ${BEE_METADIR}/${pkg}/CONTENT ; then
if egrep -q "file=.*${f}" "${BEE_METADIR}/${pkg}/CONTENT" ; then
echo ${pkg}
for line in $(egrep "file=.*${f}" ${BEE_METADIR}/${pkg}/CONTENT) ; do
eval $(${BEESEP} ${line})
while read line ; do
eval $(${BEESEP} "${line}")
echo " ${file}"
done
done < <(egrep "file=.*${f}" "${BEE_METADIR}/${pkg}/CONTENT")
fi
done
}
Expand Down
3 changes: 3 additions & 0 deletions src/beecut.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ int main(int argc, char *argv[])
case OPT_VERSION:
print_version();
exit(EXIT_SUCCESS);

case '?':
exit(EXIT_FAILURE);
}
} /* end while getopt_long_only */

Expand Down
2 changes: 2 additions & 0 deletions src/beegetopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ int main(int argc, char *argv[])

while((opt=bee_getopt(&optctl, &i)) != BEE_GETOPT_END) {
if (opt == BEE_GETOPT_ERROR) {
free(beeopts);
free(beeoptptr);
exit(1);
}

Expand Down

0 comments on commit 726ce24

Please sign in to comment.