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

Annotation of ports/license-check, Revision 1.1

1.1     ! marc        1: #! /bin/sh
        !             2: #
        !             3: # $OpenBSD$
        !             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
        !            15: #                      of a shell `rm -f xxx' command so they can
        !            16: #                      be fed to the shell after manual verification.
        !            17: #
        !            18: #  Extra files:                Files that are in the given directory that are
        !            19: #                      not mentioned in the ports LICENSE file.
        !            20: #
        !            21:
        !            22: # The ports base directory.  Note: this may be supplied from the environment
        !            23: # using the standard bsd.port.mkl name of PORTSDIR
        !            24: #
        !            25: LICENCE=${PORTSDIR:-/usr/ports}/LICENSE
        !            26:
        !            27: # Our name and a function to spit out the usage.  Exit.
        !            28: #
        !            29: prog=`basename $0`
        !            30: usage () {
        !            31:     if [ ! -z "$1" ]; then
        !            32:        echo "$prog: $1"
        !            33:     fi
        !            34:     echo "usage: $prog distribution-directory"
        !            35:     exit 1
        !            36: }
        !            37:
        !            38: # Verify we have one param and that it is the name of a directory.
        !            39: # If not spit out our usage and exit
        !            40: #
        !            41: if [ $# -eq 1 ]; then
        !            42:     if [ -d $1 ]; then
        !            43:        DIST=$1
        !            44:     else
        !            45:        usage "$1 is not a directory"
        !            46:     fi
        !            47: else
        !            48:     usage
        !            49: fi
        !            50:
        !            51: # This awk script matches the licence file agains an `ls' of of the given
        !            52: # distribution directory and spits instructions out to stdout.
        !            53: #
        !            54: /bin/ls $DIST |
        !            55: awk -v L=$LICENCE '
        !            56: BEGIN {
        !            57:     # Process license file
        !            58:     #
        !            59:     while ( getline <L ) {
        !            60:        if ( NF == 4 ) {
        !            61:            if ( $1 == "Y" ) {
        !            62:                good_files[ $3 ] = 0
        !            63:            } else if ( $1 == "N" ) {
        !            64:                bad_files[ $3 ] = 0
        !            65:            }
        !            66:        }
        !            67:     }
        !            68:     unk_count = 0
        !            69: }
        !            70:
        !            71: $1 in good_files {
        !            72:     good_files[ $1 ] = 1
        !            73:     next
        !            74: }
        !            75: $1 in bad_files {
        !            76:     bad_files[ $1 ] = 1
        !            77:     next
        !            78: }
        !            79: {
        !            80:     unk_files[ unk_count++ ] = $1
        !            81: }
        !            82:
        !            83: END {
        !            84:     header = 0
        !            85:     for ( f in good_files ) {
        !            86:        if ( good_files[ f ] == 0 ) {
        !            87:            if ( ! header ) {
        !            88:                print "You are missing the following files:"
        !            89:                print
        !            90:                header = 1
        !            91:            }
        !            92:            print f
        !            93:        }
        !            94:     }
        !            95:     if ( header ) {
        !            96:        print
        !            97:        header = 0
        !            98:     }
        !            99:     for ( f in bad_files ) {
        !           100:        if ( bad_files[ f ] == 1 ) {
        !           101:            if ( ! header ) {
        !           102:                print "You MUST remove the following files:"
        !           103:                print
        !           104:                header = 1
        !           105:            }
        !           106:            print "rm -f", f
        !           107:        }
        !           108:     }
        !           109:     if ( header ) {
        !           110:        print
        !           111:        header = 0
        !           112:     }
        !           113:     if ( unk_count > 0 ) {
        !           114:        print "The following files are extra and should probably be removed:"
        !           115:        print
        !           116:        for ( i = 0; i < unk_count; i += 1 ) {
        !           117:            print "rm -f", unk_files[ i ]
        !           118:        }
        !           119:        print
        !           120:     }
        !           121: }
        !           122: '
        !           123: exit 0