1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
# section no34:*/
# section no12:*/
#
# Program: ctan_chk.gawk
#
# Author: Dave Bone
#
# License:
# This Source Code Form is subject to the terms of the GNU General Public License (version 3).
# If a copy of the MPL was not distributed with this file,
# You can obtain one at: "https://gnu.org/licenses/gpl.html".
#
# Purpose: Implementation of some suggested CTAN guidelines that an upload project should respect.
# Correction functions help u cleanup the droppings.
# See www.ctan.org website for "upload guideline" document
# Read ctan_chk.pdf document describing the program with various run scenarios.
#
#
# section no:12*/
# section no14:*/
function is_file_a_directory(filename,filetype)
{
x= "file \"%s\"";
y= sprintf(x,filename);
y|getline a;
close(y);
split(a,parts);
filetype[1]= parts[2];
xx= parts[2];
str= "^directory$";
if(xx~str){
return 1;
}
return 0;
}
# section no:14*/
# section no15:*/
function is_file_an_executable(filename,filetype)
{
x= "file %s";
y= sprintf(x,filename);
y|getline a;
close(y);
split(a,parts);
filetype[1]= parts[2];
xx= parts[2];
str= "(executable|POSIX|Mach-O|ELF)$";
if(xx~str){
return 1;
}
return 0;
}
# section no:15*/
# section no17:*/
function chk_auxiliary_files(filename)
{
if(is_file_a_directory(filename)==1)
return 0;
str= "\\.(ps|gitignore|git|aux|log|bbl|bcf|blg|brf|ilg|ind|idx|glo|loa|lof|lot|nav|out|snm|vrb|toc|dvi|glg|gls|tmp|o|bak|mpx|scn|toc)$";
if(filename~str){
a= "\"%s\" 'Auxilary file to be deleted'";
b= sprintf(a,filename);
print b;
#delete_file(filename);
return 1;
}
return 0;
}
# section no:17*/
# section no25:*/
function remove_file_s_extended_attributes(filename,message)
{
x= "echo %s\";xattr -c %s";
y= sprintf(x,message,filename);
print y;
#y|getline a;
#close(y);
}
# section no:25*/
# section no21:*/
function chk_file_permissions(filename)
{
filetype[1]= "";
if(is_file_a_directory(filename,filetype)==1)
return 0;
if(is_file_an_executable(filename,filetype)==1)
return 0;
x= "ls -al \"%s\"";
y= sprintf(x,filename);
y|getline a;
close(y);
number_fields= split(a,parts);
str= "x";
if(parts[1]~str){
a= "\"%s\" 'Write permissions %s to possibly delete file type: %s'";
b= sprintf(a,filename,parts[1],filetype[1]);
print b;
return 1;
}
return 0;
}
# section no:21*/
# section no18:*/
function chk_extended_file_attributes(filename)
{
x= "ls -al \"%s\"";
y= sprintf(x,filename);
y|getline a;
close(y);
number_of_fields= split(a,parts);
if(number_of_fields<9)
return 0;
xx= parts[1];
str= "(@|+)$";
if(xx!~str){
return 0;
}
a= "\"%s\" 'Extended attributes %s'";
b= sprintf(a,filename,parts[1]);
print b;
#remove_file_s_extended_attributes(filename,b);
return 1;
}
# section no:18*/
# section no19:*/
function chk_empty_files(filename)
{
if(is_file_a_directory(filename)==1)
return 0;
x= "ls -al \"%s\"";
y= sprintf(x,filename);
y|getline a;
close(y);
number_of_fields= split(a,parts);
if(number_of_fields<9)
{
print"ERROR ===> ls -al should be 9 fields and it isn't: "a" no fields: "number_of_fields;
return 0;
}
i= strtonum(parts[5]);
if(i> 0){
return 0;
}
a= "\"%s\" 'Empty file to be deleted'";
b= sprintf(a,filename);
print b;
#delete_file(filename);
return 1;
}
# section no:19*/
# section no20:*/
function chk_empty_directory(filename)
{
if(is_file_a_directory(filename)==0)
return 0;
x= "du -sk \"%s\"";
y= sprintf(x,filename);
y|getline a;
close(y);
number_of_fields= split(a,parts);
i= strtonum(parts[1]);
if(i> 0)
return 0;
a= "\"%s\" 'Empty directory to be deleted or needs to add info.txt file inside it'";
b= sprintf(a,filename);
print b;
return 1;
}
# section no:20*/
# section no26:*/
function delete_file(filename)
{
x= "rm -i \"%s\"";
y= sprintf(x,filename);
y|getline a;
close(y);
}
# section no:26*/
# section no22:*/
function chk_file_to_bypass_in_zip(filename)
{
str= ".(DS_Store|.nbattrs)$";
if(filename~str){
a= "\"%s\" 'Bypass file in zip'";
b= sprintf(a,filename);
print b;
return 1;
}
return 0;
}
# section no:22*/
# section no28:*/
function pass1_guidelines_verify(filename)
{
chk_auxiliary_files(filename);
chk_extended_file_attributes(filename);
chk_empty_files(filename);
chk_empty_directory(filename);
chk_file_permissions(filename);
chk_file_to_bypass_in_zip(filename);
}
# section no:28*/
# section no29:*/
function pass2_correct(filename,message)
{
#remove_file_s_execute_attribute(filename,message);
#remove_file_s_extended_attributes(filename,message);
#delete_file(filename);
}
# section no:29*/
# section no31:*/
BEGIN{
rec_cnt= 0;
}
# section no:31*/
# section no32:*/
{
pass1_guidelines_verify($1);
#pass2_correct($1,$2);
}
# section no:32*/
# section no33:*/
END{
#print "no records read: " NR;
}
# section no:33*/
# section no:34*/
|