#!/bin/bash # # prtverify # Version 0.4.4 - 2014-11-23 # Juergen Daubert MODDIR=@@LIBDIR@@/prtverify WHITELIST=$(ls -1 --color=none $MODDIR/*.wl) PORTFILES='Pkgfile .footprint .signature' LOGLEVEL=15 TESTS=$MODDIR/[023]*.awk ### Functions checkargs() { if [ $1 -lt 1 ]; then usage fi } perror() { echo "===== Error: $1" >&2 exit -1 } usage() { echo "Usage: ${0##*/} [options] port ... options: -l loglevel -m clean-repo -m missing-deps -c path_to_collection [-c path_to_collection ...] -m file-conflict -c path_to_collection [-c path_to_collection ...] See prtverify(1) for a detailed description of all options." exit 0 } checkcollections() { local dir if [ -z "$COLLECTIONS" ]; then perror "Need one or more collection. Use -c option to set." fi for dir in $COLLECTIONS; do if [ ! -d $dir ]; then perror "$dir is not a directory" continue fi if [ -z "$(eval echo "$dir/*/Pkgfile")" ]; then perror "$dir is not a CRUX port-collection directory" fi done } cleanup() { rm -f $FPDB exit 0 } checkmode() { case $1 in clean-repo) TESTS=$MODDIR/[0123]*.awk ;; file-conflict) MODE_FC=1 ;; missing-deps) MODE_MD=1 ;; *) usage ;; esac } getoptions() { local option while getopts :l:m:c: option do case $option in l) LOGLEVEL="$OPTARG" ;; m) checkmode "$OPTARG" ;; c) COLLECTIONS="$COLLECTIONS $OPTARG" ;; *) usage ;; esac done shift $(($OPTIND - 1)) PORTS=$@ } findmodules() { local mod for mod in $TESTS; do MODULES="$MODULES -f $mod" done } mkfootprintdb() { local dir files FPDB=$(mktemp -p ${TMPDIR:-/tmp} prtverify.XXXXXXXX) for dir in $COLLECTIONS; do files="$files $dir/*/.footprint" done gawk \ -v FOOTPRINTDB="$FPDB" \ -f $MODDIR/00_prtverify_lib.awk \ -f $MODDIR/90_mk_footprint_db.awk \ $files } mkportslist() { local dir for dir in $COLLECTIONS; do DEPPORTS="$DEPPORTS `ls -1 --color=none $dir`" done } runtests() { local dir checkargs $# for dir in $@; do gawk \ -v LOG_LEVEL=$LOGLEVEL \ -v FOOTPRINTDB="$FPDB" \ -v PORT_FILES="$PORTFILES" \ -v WHITE_LIST="$WHITELIST" \ -v DEP_PORTS="$DEPPORTS" \ $MODULES $dir done } main() { checkargs $# getoptions $@ if [ $MODE_FC ] || [ $MODE_MD ]; then checkcollections if [ $MODE_FC ]; then mkfootprintdb fi if [ $MODE_MD ]; then mkportslist fi fi findmodules runtests $PORTS cleanup } ### Main export LC_ALL=C shopt -s nullglob trap "cleanup" HUP INT QUIT TERM main "$@" # End of file