Annotation of ports/license-check, Revision 1.3
1.1 marc 1: #! /bin/sh
2: #
1.3 ! marc 3: # $OpenBSD: license-check,v 1.2 1998/04/13 05:16:02 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 ) {
98: if ( ! header ) {
99: print "You are missing the following files:"
100: print
101: header = 1
102: }
103: print f
104: }
105: }
106: if ( header ) {
107: print
108: header = 0
109: }
110: for ( f in bad_files ) {
111: if ( bad_files[ f ] == 1 ) {
112: if ( ! header ) {
1.3 ! marc 113: print "You MUST move the following files/directories:"
1.1 marc 114: print
115: header = 1
116: }
1.3 ! marc 117: print "/bin/mv -f", f, "../licensed"
1.1 marc 118: }
119: }
120: if ( header ) {
121: print
122: header = 0
123: }
1.3 ! marc 124: for ( f in unk_files ) {
! 125: if ( unk_files[ f ] == 1 ) {
! 126: if ( ! header ) {
! 127: print "The status of the following files is unknown:"
! 128: print
! 129: header = 1
! 130: }
! 131: print f
! 132: }
! 133: }
! 134: if ( header ) {
! 135: print
! 136: header = 0
! 137: }
! 138:
! 139: if ( extra_count > 0 ) {
1.2 marc 140: print "The following files/dirs are extra and " \
141: "should probably be removed:"
1.1 marc 142: print
1.3 ! marc 143: for ( i = 0; i < extra_count; i += 1 ) {
! 144: print "/bin/rm -rf", extra_files[ i ]
1.1 marc 145: }
146: print
147: }
148: }
149: '
150: exit 0