Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / scripts / binpkg-scan
blob7b4fc4d41bf8b7cd17e7978b74213166e551008c
1 #!/usr/bin/awk -f
2 # $NetBSD: binpkg-scan,v 1.3 2006/12/15 13:15:06 martti Exp $
4 # Copyright (c) 2006 The NetBSD Foundation, Inc.
5 # All rights reserved.
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Dan McMahill.
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # 3. All advertising materials mentioning features or use of this software
19 # must display the following acknowledgement:
20 # This product includes software developed by the NetBSD
21 # Foundation, Inc. and its contributors.
22 # 4. Neither the name of The NetBSD Foundation nor the names of its
23 # contributors may be used to endorse or promote products derived
24 # from this software without specific prior written permission.
26 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 # POSSIBILITY OF SUCH DAMAGE.
39 # Scans for packages with NO_BIN_ON_FTP set. This script makes use of the
40 # cache files generated as part of the README.html generation. This makes
41 # this scan run quite fast when you have a very large binary packages collection.
43 # Usage:
45 # binpkg-scan PACKAGES=/usr/pkgsrc/packages /dev/null
48 # Global variables
49 #-----------------
51 # notify - if set to 1, something will be set in the output script to make it
52 # easy to detect and an automatic email can be sent to notify a person
53 # that some cleanup is required.
57 BEGIN {
58 printf("#!/bin/sh\n#\n\n");
59 printf("# Starting scan for NO_BIN_ON_FTP packages\n\n");
60 notify = 0;
64 END {
66 # printf("Making sure binary package cache file is up to date...\n");
67 # cmd = sprintf("%s AWK=%s CMP=%s FIND=%s GREP=%s PKG_INFO=\"%s\" PKG_SUFX=%s SED=%s SORT=%s %s/mk/scripts/binpkg-cache --packages %s",
68 # SETENV, AWK, CMP, FIND, GREP, PKG_INFO, PKG_SUFX, SED, SORT, PKGSRCDIR, PACKAGES);
69 # if (debug) printf("\nExecute: %s\n",cmd);
70 # rc = system(cmd);
71 rc = 0;
73 if (rc != 0 && rc != 2) {
74 printf("\n**** WARNING ****\n") > "/dev/stderr";
75 printf("Command: %s\nfailed.", cmd) > "/dev/stderr";
76 printf("**** ------- ****\n") > "/dev/stderr";
77 exit(1);
80 if (rc == 2) {
81 printf("\n**** WARNING ****\n") > "/dev/stderr";
82 printf("* No binary packages directory found\n") > "/dev/stderr";
83 printf("* List of binary packages will not be generated\n") > "/dev/stderr";
84 printf("**** ------- ****\n") > "/dev/stderr";
85 exit(0);
88 printf("# Loading binary package cache file...\n\n");
89 load_cache_file( PACKAGES "/.pkgcache" );
90 printf("\n");
92 for(pkg in noftp_list) {
93 printf("# NO_BIN_ON_FTP (%s) = %s\nrm %s/%s\n\n",
94 pkgpath_list[pkg], noftp_list[pkg], PACKAGES, pkg);
97 if( notify ) {
98 printf("\n# NOTIFY a person that this script should be run\n\n");
102 function fatal_check_file(file, cmd){
103 cmd="test -f " file ;
104 if (debug) printf("Execute: %s\n",cmd);
105 if (system(cmd) != 0) {
106 printf("**** FATAL ****\nRequired file %s does not exist\n",
107 file) > "/dev/stderr";
108 printf("**** ------- ****\n") > "/dev/stderr";
109 close("/dev/stderr");
110 exit(1);
115 function load_cache_file( file, pkgfile, noftp, pkgpath, wk, rx ) {
116 printf("# * %s\n", file);
117 fatal_check_file( file );
119 # read the cache file
120 while( getline < file ) {
122 # if this line points to another cache file, then recursively
123 # load it
124 if( $0 ~ /^pkgcache_cachefile/ ) {
125 if( debug ) printf("# Found pkgcache_cachefile line.\n");
126 load_cache_file( $2 );
127 } else if( $0 ~/^pkgcache_begin /) {
128 pkgfile = $2;
129 if( debug ) printf("# Starting %s\n", pkgfile);
130 pkgpath = "unknown";
131 noftp = "unknown";
132 } else if( $0 ~/^PKGPATH=/ ) {
133 pkgpath = $0;
134 gsub(/PKGPATH=[ \t]*/, "", pkgpath);
135 } else if( $0 ~/^NO_BIN_ON_FTP=/ ) {
136 noftp = $0;
137 gsub(/NO_BIN_ON_FTP=[ \t]*/, "", noftp);
138 } else if( $0 ~/^pkgcache_end /) {
139 if( debug ) printf("# %s, NO_BIN_ON_FTP=%s, PKGPATH=%s\n",
140 pkgfile, noftp, pkpath);
142 if(noftp == "") {
143 if( debug ) printf("# %s, NOT restricted\n", pkgfile);
144 } else if( noftp == "unknown" ) {
145 printf("# UNKNOWN value for NO_BIN_ON_FTP: %s/%s\n", PACKAGES, pkgfile);
146 notify = 1;
147 } else {
148 noftp_list[pkgfile] = noftp;
149 pkgpath_list[pkgfile] = pkgpath;
150 notify = 1;
154 } else {
155 # skip this line
159 # close the cache file
160 close( file );