summaryrefslogtreecommitdiff
path: root/prtverify.in
blob: 9ecd7e26c6ab82a6e4e14360f771b1d719f9ffaa (plain)
    1 #!/bin/bash
    2 #
    3 # prtverify 
    4 # Version 0.4.4 - 2014-11-23
    5 # Juergen Daubert <jue at jue dot li>
    6 
    7 
    8 MODDIR=@@LIBDIR@@/prtverify
    9 WHITELIST=$(ls -1 --color=none $MODDIR/*.wl)
   10 PORTFILES='Pkgfile .footprint .signature'
   11 LOGLEVEL=15
   12 TESTS=$MODDIR/[023]*.awk
   13 
   14 
   15 ### Functions
   16 
   17 checkargs() {
   18     if [ $1 -lt 1 ]; then
   19         usage
   20     fi
   21 }
   22 
   23 perror() {
   24     echo "=====  Error: $1" >&2
   25     exit -1
   26 }
   27 
   28 usage() {
   29     echo "Usage: ${0##*/} [options] port ...
   30 options:
   31  -l loglevel
   32  -m clean-repo
   33  -m missing-deps  -c path_to_collection [-c path_to_collection ...]
   34  -m file-conflict -c path_to_collection [-c path_to_collection ...]
   35 See prtverify(1) for a detailed description of all options."
   36     exit 0
   37 }
   38 
   39 checkcollections() {
   40     local dir
   41     if [ -z "$COLLECTIONS" ]; then
   42         perror "Need one or more collection. Use -c option to set."
   43     fi
   44 
   45     for dir in $COLLECTIONS; do
   46         if [ ! -d $dir ]; then
   47             perror "$dir is not a directory"
   48             continue
   49         fi
   50         if [ -z "$(eval echo "$dir/*/Pkgfile")" ]; then
   51             perror "$dir is not a CRUX port-collection directory"
   52         fi
   53     done
   54 }
   55 
   56 cleanup() {
   57     rm -f $FPDB
   58     exit 0
   59 }
   60 
   61 checkmode() {
   62     case $1 in
   63     clean-repo)
   64         TESTS=$MODDIR/[0123]*.awk
   65         ;;
   66     file-conflict)
   67         MODE_FC=1
   68         ;;
   69     missing-deps)
   70         MODE_MD=1
   71         ;;
   72     *)  usage
   73         ;;
   74     esac
   75 }
   76 
   77 getoptions() {
   78     local option
   79     while getopts :l:m:c: option
   80     do
   81         case  $option in
   82         l)  LOGLEVEL="$OPTARG"
   83             ;;
   84         m)  checkmode "$OPTARG"
   85             ;;
   86         c)  COLLECTIONS="$COLLECTIONS $OPTARG"
   87             ;;
   88         *)  usage
   89             ;;
   90         esac
   91     done
   92     shift $(($OPTIND - 1))
   93 
   94     PORTS=$@
   95 }
   96 
   97 findmodules() {
   98     local mod
   99     for mod in $TESTS; do
  100         MODULES="$MODULES -f $mod"
  101     done
  102 }
  103 
  104 mkfootprintdb() {
  105     local dir files
  106     FPDB=$(mktemp -p ${TMPDIR:-/tmp} prtverify.XXXXXXXX)
  107 
  108     for dir in $COLLECTIONS; do
  109         files="$files $dir/*/.footprint"
  110     done
  111 
  112     gawk \
  113         -v FOOTPRINTDB="$FPDB" \
  114         -f $MODDIR/00_prtverify_lib.awk \
  115         -f $MODDIR/90_mk_footprint_db.awk \
  116         $files
  117 }
  118 
  119 mkportslist() {
  120     local dir
  121     for dir in $COLLECTIONS; do
  122         DEPPORTS="$DEPPORTS `ls -1 --color=none $dir`"
  123     done
  124 }
  125 
  126 runtests() {
  127     local dir
  128     checkargs $#
  129 
  130     for dir in $@; do
  131         gawk \
  132             -v LOG_LEVEL=$LOGLEVEL \
  133             -v FOOTPRINTDB="$FPDB" \
  134             -v PORT_FILES="$PORTFILES" \
  135             -v WHITE_LIST="$WHITELIST" \
  136             -v DEP_PORTS="$DEPPORTS" \
  137             $MODULES $dir
  138     done
  139 }
  140 
  141 main() {
  142     checkargs $#
  143     getoptions $@
  144 
  145     if [ $MODE_FC ] || [ $MODE_MD ]; then
  146         checkcollections
  147         if [ $MODE_FC ]; then 
  148             mkfootprintdb
  149         fi
  150         if [ $MODE_MD ]; then 
  151             mkportslist
  152         fi
  153     fi
  154 
  155     findmodules
  156     runtests $PORTS
  157     cleanup
  158 }
  159 
  160 ### Main
  161 
  162 export LC_ALL=C
  163 shopt -s nullglob
  164 trap "cleanup" HUP INT QUIT TERM
  165 
  166 main "$@"
  167 
  168 # End of file

Generated by cgit