[BACK]Return to license-check CVS log [TXT][DIR] Up to [local] / ports

Annotation of ports/license-check, Revision 1.4

1.1       marc        1: #! /bin/sh
                      2: #
1.4     ! marc        3: # $OpenBSD: license-check,v 1.3 1998/09/24 04:27:04 marc Exp $
1.1       marc        4: #
                      5: # This script verifies that all files in a given directory are
                      6: # mentioned in the ports LICENSE file as Distribution allowed.
                      7: # Output is three lists:
                      8: #
                      9: #  Missing files:      files that should be in the directory (if the
                     10: #                      intent is to obtain all files that can be
                     11: #                      re-distributed) but are not.
                     12: #
                     13: #  Bad files:          files that must NOT be in a distribution
                     14: #                      directory.  These are listed in the form
1.3       marc       15: #                      of a shell `mv -f xxx ../licensed' command so
                     16: #                      they can be fed to the shell (after manual
                     17: #                      verification) to move them into a directory
                     18: #                      that will not be copied to any CD-ROM.
                     19: #
                     20: #  Unknown files:      files that are noted in the LICENSE file but
                     21: #                      do not have a distribution flag of either Y or N.
1.1       marc       22: #
                     23: #  Extra files:                Files that are in the given directory that are
                     24: #                      not mentioned in the ports LICENSE file.
                     25: #
                     26:
                     27: # The ports base directory.  Note: this may be supplied from the environment
1.3       marc       28: # using the standard bsd.port.mk name of PORTSDIR
1.1       marc       29: #
                     30: LICENCE=${PORTSDIR:-/usr/ports}/LICENSE
                     31:
                     32: # Our name and a function to spit out the usage.  Exit.
                     33: #
                     34: prog=`basename $0`
                     35: usage () {
                     36:     if [ ! -z "$1" ]; then
                     37:        echo "$prog: $1"
                     38:     fi
                     39:     echo "usage: $prog distribution-directory"
                     40:     exit 1
                     41: }
                     42:
                     43: # Verify we have one param and that it is the name of a directory.
                     44: # If not spit out our usage and exit
                     45: #
                     46: if [ $# -eq 1 ]; then
                     47:     if [ -d $1 ]; then
                     48:        DIST=$1
                     49:     else
                     50:        usage "$1 is not a directory"
                     51:     fi
                     52: else
                     53:     usage
                     54: fi
                     55:
1.3       marc       56: # This awk script matches the license file agains an `ls' of of the given
1.1       marc       57: # distribution directory and spits instructions out to stdout.
                     58: #
                     59: /bin/ls $DIST |
                     60: awk -v L=$LICENCE '
                     61: BEGIN {
                     62:     # Process license file
                     63:     #
                     64:     while ( getline <L ) {
                     65:        if ( NF == 4 ) {
                     66:            if ( $1 == "Y" ) {
                     67:                good_files[ $3 ] = 0
                     68:            } else if ( $1 == "N" ) {
                     69:                bad_files[ $3 ] = 0
1.3       marc       70:            } else {
                     71:                unk_files[ $3 ] = 0
1.1       marc       72:            }
                     73:        }
                     74:     }
1.3       marc       75:     extra_count = 0
1.1       marc       76: }
                     77:
                     78: $1 in good_files {
                     79:     good_files[ $1 ] = 1
                     80:     next
                     81: }
                     82: $1 in bad_files {
                     83:     bad_files[ $1 ] = 1
                     84:     next
                     85: }
1.3       marc       86: $1 in unk_files {
                     87:     unk_files[ $1 ] = 1
                     88:     next
                     89: }
1.1       marc       90: {
1.3       marc       91:     extra_files[ extra_count++ ] = $1
1.1       marc       92: }
                     93:
                     94: END {
                     95:     header = 0
                     96:     for ( f in good_files ) {
                     97:        if ( good_files[ f ] == 0 ) {
1.4     ! marc       98:            if ( ! header ) {
        !            99:                print "You are missing the following files:"
        !           100:                print
        !           101:                header = 1
        !           102:            }
        !           103:            print f
        !           104:        }
        !           105:     }
        !           106:     for ( f in unk_files ) {
        !           107:        if ( unk_files[ f ] == 0 ) {
1.1       marc      108:            if ( ! header ) {
                    109:                print "You are missing the following files:"
                    110:                print
                    111:                header = 1
                    112:            }
                    113:            print f
                    114:        }
                    115:     }
                    116:     if ( header ) {
                    117:        print
                    118:        header = 0
                    119:     }
                    120:     for ( f in bad_files ) {
                    121:        if ( bad_files[ f ] == 1 ) {
                    122:            if ( ! header ) {
1.3       marc      123:                print "You MUST move the following files/directories:"
1.1       marc      124:                print
                    125:                header = 1
                    126:            }
1.3       marc      127:            print "/bin/mv -f", f, "../licensed"
1.1       marc      128:        }
                    129:     }
                    130:     if ( header ) {
                    131:        print
                    132:        header = 0
                    133:     }
1.3       marc      134:     for ( f in unk_files ) {
                    135:        if ( unk_files[ f ] == 1 ) {
                    136:            if ( ! header ) {
                    137:                print "The status of the following files is unknown:"
                    138:                print
                    139:                header = 1
                    140:            }
                    141:            print f
                    142:        }
                    143:     }
                    144:     if ( header ) {
                    145:        print
                    146:        header = 0
                    147:     }
                    148:
                    149:     if ( extra_count > 0 ) {
1.2       marc      150:        print "The following files/dirs are extra and " \
                    151:              "should probably be removed:"
1.1       marc      152:        print
1.3       marc      153:        for ( i = 0; i < extra_count; i += 1 ) {
                    154:            print "/bin/rm -rf", extra_files[ i ]
1.1       marc      155:        }
                    156:        print
                    157:     }
                    158: }
                    159: '
                    160: exit 0