Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 May 2002 20:05:53 +0100
From:      Aleksandar Simic <asimic@dsl.pipex.com>
To:        freebsd-ports@FreeBSD.org
Subject:   New pkg_vrfy tool
Message-ID:  <20020514200553.A26176@myname.my.domain>

next in thread | raw e-mail | index | archive | help

--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,

the ports collection is great, but it isn't perfect, thats why I wrote
this little tool pkg_vrfy.

When you run it, it reports which ports have some, if not all, of
their components missing.

Thanks,

--Alex

P.S. the tool isn't perfect, so if you can improve it, please do so.



--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=pkg_vrfy

#!/bin/sh

# NAME
#   pkg_vrfy - a utility for verifying the components of a installed
#   package
#
# SYNOPSIS
#   pkg_vrfy [-a] [-h] [-t] package-name
#
# DESCRIPTION
#   The pkg_vrfy command checks the package database for all the files
#   listed as installed and prints out any that aren't.
#
# OPTIONS
#
#        -a    summary of all the installed packages
#              with missing files printed 
#
#        -h    help
#
#        -t    total number of packages installed
#
# EXAMPLES
#   pkg_vrfy emacs-21.1  - to list all the files installed by 
#                          emacs-21.1 package
# 
#
# EXIT STATUS
#   0  On success
#   1  On failure
#
# FILES
#   /var/db/pkg/<pkg>/+CONTENTS
# 
# RESTRICTIONS / BUGS
#   For now the utility just checks the /var/db/pkg database in order
#   to determine the installed components. A better version should be
#   able to check for installed components when invoked in directory
#   of a port (eg. /usr/ports/editors/emacs/) without using package's
#   name in the database, but that would involve guessing the name
#   of the package under which it was registered in /var/db/pkg .
#
# SEE ALSO
#   pkg_add(1), pkg_create(1), pkg_delete(1), pkg_info(1),
#   pkg_version(1)
#
# AUTHOR
#   Aleksandar Simic <alex@dsl.pipex.com>
#     
# DDMMYY   Name        Version
# =======  ====        ======
# 270102   pkg_vrfy    Initial version.
# 020202   pkg_vrfy    1.0
# 050202   pkg_vrfy    1.3
# 030302   pkg_vrfy    1.4
# 140302   pkg_vrfy    1.5
# 140502   pkg_vrfy    1.6

CUT=/usr/bin/cut
GREP=/usr/bin/grep
HEAD=/usr/bin/head
LS=/bin/ls
SED=/usr/bin/sed
BASENAME=/usr/bin/basename
PWD=/bin/pwd

PKGDB=/var/db/pkg
CONTENTS=./+CONTENTS

list () {
    # gets the name of the directory the package resides in
    DIR=`$GREP @cwd $CONTENTS| $HEAD -n 1 | $CUT -d ' ' -f2`

    if [ $DIR != / ]; then
	DIR=$DIR/ ;
    fi

    # for i in `$grep -v "@" $contents`
    for i in `$SED -e 's/^@.*//g' -e 's/^+.*//g' $CONTENTS`
      do
      if [ ! -e `printf "$DIR$i\n"` ];
	  then printf "Not found: $DIR$i\n" 2>&1 ;
      fi
    done
}

total () {
    # this only works provided that directories no other
    # than those of packages are in $PKGDB
    printf "Total number of packages installed:\
 `cd $PKGDB && $LS -l | $HEAD -n 1 | $CUT -d ' ' -f2`\n" ;
}

usage () {
    printf "usage: `$BASENAME $0`  [-a] [-h] [-t]\n" 1>&2 ;
    printf "       `$BASENAME $0` package-name\n" 1>&2 ;
}

if [ $# -lt 1 ] ; then
    usage ;
    exit 1 ;
fi

case "$1" in
    -a) # echo "Option broken"; exit 1
	shift ;
	cd $PKGDB ;
	
	for i in `$LS -A`; do
	    if [ -d $i ]; then
		printf "====> $i\n"
		cd $PKGDB/$i;
		if [ ! -e $CONTENTS ] ; then
		    printf " has missing '+CONTENTS' file\n" 1>&2 ;
		    cd .. ;
		else
		    list && cd .. ;
		fi
	    fi
	done
	;;
    -h) usage
	break
	;;
    -t) total
	;;
    -?) printf "`$BASENAME $0`: illegal option\n" 1>&2 ;
	usage
	break
	;;
    "") usage
	break
	;;
    *) if [ -d $PKGDB/$1 ]; then
	cd $PKGDB/$1
	
          if [ ! -e $CONTENTS ] ; then
	      printf "`$BASENAME $1` has missing '+CONTENTS' file\n" 1>&2 ;
	      printf "can't proceed, exiting\n" 1>&2 ;
	      exit 1 ;
	  else
	      list ;
	  fi;
	
        else printf "`$BASENAME $0`: package not found\n" 1>&2;
	 usage ;
       fi
	;;
esac


--cWoXeonUoKmBZSoM--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020514200553.A26176>