| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Reads an old reqmap (mapping file for patched ifcico) and an old |
| 4 |
# noreq (list of files in pubdir, which should not inserted to reqmap) |
| 5 |
# and generates a new reqmap.new and noreq.new and an additional |
| 6 |
# reqmap.add, which keeps all new files and a first try of a 8+3-conversion. |
| 7 |
# The admin should merge reqmap.add to reqmap.new. |
| 8 |
# |
| 9 |
# $Id: genreqmap,v 1.3 1996/09/27 02:14:18 roland Exp $ |
| 10 |
# |
| 11 |
# Copyright (C) 1996 Roland Rosenfeld <[email protected]> 2:2450/42 |
| 12 |
# |
| 13 |
# This program is free software; you can redistribute it and/or modify it |
| 14 |
# under the terms of the GNU General Public License as published by the |
| 15 |
# Free Software Foundation; either version 2, or (at your option) any |
| 16 |
# later version. |
| 17 |
# |
| 18 |
# This program is distributed in the hope that it will be useful, but |
| 19 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 |
# General Public License for more details. |
| 22 |
# |
| 23 |
# Some small parts of this script are stolen from FidoGate 4.0beta1 |
| 24 |
# the famous gatewaysoftware written by Martin Junius <[email protected]> |
| 25 |
# |
| 26 |
############################################################################# |
| 27 |
|
| 28 |
$fnet = "/usr/lib/ifmail"; |
| 29 |
$reqmap = "$fnet/reqmap"; |
| 30 |
$noreq = "$fnet/noreq"; |
| 31 |
$newreqmap = "$reqmap.new"; |
| 32 |
$newnoreq = "$noreq.new"; |
| 33 |
$reqmapadd = "$reqmap.add"; |
| 34 |
$oldreqmap = "$reqmap.old"; |
| 35 |
$oldnoreq = "$noreq.old"; |
| 36 |
$pubdir = "/home/ftp/pub/"; |
| 37 |
$files = "$pubdir/2450-42.lst"; |
| 38 |
$filesnew = "$files.new"; |
| 39 |
$filesold = "$files.old"; |
| 40 |
$fileszip = "$pubdir/2450-42.zip"; |
| 41 |
$fileshead = "$fnet/filelist.head"; |
| 42 |
$filesbbs = "files.bbs"; |
| 43 |
$admin = "news"; |
| 44 |
$report = "| /bin/mail -s 'New Fido-Requestmap and generated!' $admin"; |
| 45 |
$zip = "/usr/bin/zip -kjq"; |
| 46 |
|
| 47 |
############################################################################# |
| 48 |
|
| 49 |
require "ctime.pl"; |
| 50 |
|
| 51 |
############################################################################# |
| 52 |
|
| 53 |
# |
| 54 |
# Generating report: |
| 55 |
# |
| 56 |
open (REPORT, $report) || die "Can't generate $report: $!\n"; |
| 57 |
print REPORT "==============================================================="; |
| 58 |
print REPORT "\nNote the following inconsistencies:\n\n"; |
| 59 |
|
| 60 |
# |
| 61 |
# Read old reqmap and store it into %longtoshort |
| 62 |
# |
| 63 |
open (REQMAP, $reqmap) || die "Can't open $reqmap: $!\n"; |
| 64 |
while (<REQMAP>) { |
| 65 |
chop; |
| 66 |
($shortname,$longname) = split (/\s+/, $_, 2); |
| 67 |
$longname =~ s/$pubdir//; |
| 68 |
$longtoshort{$longname} .= "$shortname "; |
| 69 |
} |
| 70 |
close (REQMAP); |
| 71 |
|
| 72 |
# |
| 73 |
# Read old noreq and store it into %longtoshort as "-" |
| 74 |
# |
| 75 |
open (NOREQ, $noreq) || die "Can't open $noreq: $!\n"; |
| 76 |
while (<NOREQ>) { |
| 77 |
chop; |
| 78 |
s/$pubdir//; |
| 79 |
if (!$longtoshort{$_}) { |
| 80 |
$longtoshort{$_} = "-"; |
| 81 |
} else { |
| 82 |
print REPORT "File defined in reqmap and noreq: $_\n"; |
| 83 |
} |
| 84 |
} |
| 85 |
close (NOREQ); |
| 86 |
|
| 87 |
open (FIND, "find $pubdir -type f -print|") || die "Can't open find to pipe\n"; |
| 88 |
open (NEWREQMAP, ">$newreqmap") || die "Can't open $newreqmap for writing\n"; |
| 89 |
open (NEWNOREQ, ">$newnoreq") || die "Can't open $newnoreq for writing\n"; |
| 90 |
open (REQMAPADD, ">$reqmapadd") || die "Can't open $reqmapadd for writing\n"; |
| 91 |
open (FILESNEW, ">$filesnew") || die "Can't open $filesnew for writing\n"; |
| 92 |
|
| 93 |
# |
| 94 |
# Generate Filelist-Header |
| 95 |
# |
| 96 |
open (FILESHEAD, "$fileshead") || die "Can't open $fileshead for reading\n"; |
| 97 |
while (<FILESHEAD>) { |
| 98 |
print FILESNEW $_; |
| 99 |
} |
| 100 |
close (FILESHEAD); |
| 101 |
print FILESNEW "\nGenerated: "; |
| 102 |
print FILESNEW &ctime(time),"\n\n"; |
| 103 |
|
| 104 |
# |
| 105 |
# Find out, which files really exist |
| 106 |
# (Files in $pubdir first!) |
| 107 |
# |
| 108 |
while (<FIND>) { |
| 109 |
chop; |
| 110 |
if ( /\/files.bbs$/ ) { |
| 111 |
next; |
| 112 |
} |
| 113 |
s/$pubdir//; |
| 114 |
$longname = $_; |
| 115 |
if (!$longtoshort{$longname}) { |
| 116 |
print REQMAPADD &translate($longname) . "\t$longname\n"; |
| 117 |
} else { |
| 118 |
if ($longtoshort{$longname} eq "-") { |
| 119 |
print NEWNOREQ "$longname\n"; |
| 120 |
} else { |
| 121 |
foreach $oneshort (split (/ /, $longtoshort{$longname})) { |
| 122 |
print NEWREQMAP "$oneshort\t$longname\n"; |
| 123 |
$shorttolong{$oneshort} .= "$longname "; |
| 124 |
($x,$x,$x,$x,$x,$x,$x,$size,$x,$time,$x,$x,$x) |
| 125 |
= stat("$pubdir/$longname"); |
| 126 |
printf(FILESNEW "%-12s %s %s ~/%s\r\n", |
| 127 |
&toupper($oneshort), &ascdate($time), &ksize($size), |
| 128 |
$longname); |
| 129 |
} |
| 130 |
} |
| 131 |
delete $longtoshort{$longname}; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
# |
| 136 |
# Now test the other files: |
| 137 |
# |
| 138 |
foreach $longname (sort keys(%longtoshort)) { |
| 139 |
if ( -f $longname ) { |
| 140 |
if ($longtoshort{$longname} =~ /^-$/) { |
| 141 |
print REPORT "removing $longname from noreq-Liste\n"; |
| 142 |
} else { |
| 143 |
foreach $oneshort (split (/ /, $longtoshort{$longname})) { |
| 144 |
print NEWREQMAP "$oneshort\t$longname\n"; |
| 145 |
$shorttolong{$oneshort} .= "$longname "; |
| 146 |
($x,$x,$x,$x,$x,$x,$x,$size,$x,$time,$x,$x,$x) |
| 147 |
= stat("$longname"); |
| 148 |
printf(FILESNEW "%-12s %s %s %s\r\n", |
| 149 |
&toupper($oneshort), &ascdate($time), &ksize($size), |
| 150 |
$longname); |
| 151 |
} |
| 152 |
} |
| 153 |
} else { |
| 154 |
print REPORT "$longname no longer exists\n"; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
close NEWREQMAP; |
| 159 |
close NEWNOREQ; |
| 160 |
close REQMAPADD; |
| 161 |
|
| 162 |
print FILESNEW "\n\nFilelist generated by"; |
| 163 |
print FILESNEW ' $RCSfile: genreqmap,v $ $Revision: 1.3 $'; |
| 164 |
print FILESNEW "\nwritten by Roland Rosenfeld <roland\@spinnaker.rhein.de "; |
| 165 |
print FILESNEW "2:2450/42\n\n"; |
| 166 |
|
| 167 |
close FILESNEW; |
| 168 |
|
| 169 |
print REPORT "\n\n\n"; |
| 170 |
print REPORT "==============================================================="; |
| 171 |
|
| 172 |
print REPORT "\n\nThere may be some duplicate names in the (old) mapfile:\n\n"; |
| 173 |
|
| 174 |
foreach $short (sort keys(%shorttolong)) { |
| 175 |
if ($shorttolong{$short} =~ / .* /) { |
| 176 |
@longlist = split (/ /, $shorttolong{$short}); |
| 177 |
foreach $long (@longlist) { |
| 178 |
print REPORT "$short\t$long\n"; |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
print REPORT "\n\n\n"; |
| 184 |
print REPORT "==============================================================="; |
| 185 |
|
| 186 |
print REPORT "\n\nGenerated $newreqmap and $newnoreq\n"; |
| 187 |
print REPORT "from $reqmap and $noreq.\n\n"; |
| 188 |
|
| 189 |
print REPORT "The following files seem to be new in your archive, please add"; |
| 190 |
print REPORT "\nthem to your reqmap.\n\n"; |
| 191 |
|
| 192 |
open (REQMAPADD, $reqmapadd) || die "Can't open $reqmapadd for reading\n"; |
| 193 |
while (<REQMAPADD>) { |
| 194 |
print REPORT $_; |
| 195 |
} |
| 196 |
close (REQMAPADD); |
| 197 |
|
| 198 |
close REPORT; |
| 199 |
|
| 200 |
rename ($reqmap, $oldreqmap); |
| 201 |
rename ($newreqmap, $reqmap); |
| 202 |
rename ($noreq, $oldnoreq); |
| 203 |
rename ($newnoreq, $noreq); |
| 204 |
rename ($files, $oldfiles); |
| 205 |
rename ($filesnew, $files); |
| 206 |
|
| 207 |
system ("$zip $fileszip $files"); |
| 208 |
|
| 209 |
exit(0); |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
############################################################################# |
| 214 |
|
| 215 |
sub translate { |
| 216 |
local($long) = @_; |
| 217 |
local($name,$ext); |
| 218 |
|
| 219 |
$long =~ s/^.*\///; |
| 220 |
|
| 221 |
$long =~ s/\.tar.gz/.tgz/; |
| 222 |
$long =~ s/\.tar.z/.tgz/; |
| 223 |
$long =~ s/\.tar.Z/.taz/; |
| 224 |
$long =~ s/\.ps.gz/.pgz/; |
| 225 |
$long =~ s/\.doc.gz/.dgz/; |
| 226 |
|
| 227 |
$name = $long; |
| 228 |
$ext = ""; |
| 229 |
if( $long =~ /^(.*)\.([^.]*)$/ ) { |
| 230 |
$name = $1; |
| 231 |
$ext = $2; |
| 232 |
} |
| 233 |
|
| 234 |
$name =~ tr/A-Z/a-z/; |
| 235 |
$ext =~ tr/A-Z/a-z/; |
| 236 |
|
| 237 |
$name =~ s/\.//g; |
| 238 |
if (length($name)>8) { |
| 239 |
$name =~ s/[^a-z0-9]//g; |
| 240 |
} |
| 241 |
if (length($ext)>3) { |
| 242 |
$ext =~ s/[^a-z0-9]//g; |
| 243 |
} |
| 244 |
|
| 245 |
$ext =~ s/^(...).*$/$1/; |
| 246 |
|
| 247 |
while ( (length($name)>8) && ($name =~ /[a-z]/) ) { |
| 248 |
$name =~ s/[a-z]([0-9]*)$/$1/; # remove last character |
| 249 |
} |
| 250 |
|
| 251 |
$name =~ s/^(.{8}).*$/$1/; |
| 252 |
|
| 253 |
return ($ext ? "$name.$ext" : $name); |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
sub ascdate { |
| 258 |
local($time) = @_; |
| 259 |
|
| 260 |
if($time eq "") { |
| 261 |
return " "; |
| 262 |
} else { |
| 263 |
local($yr, $mn, $dy, $h, $m, $s, $xx); |
| 264 |
($s,$m,$h,$dy,$mn,$yr,$xx,$xx,$xx) = localtime($time); |
| 265 |
|
| 266 |
return sprintf("%02d.%02d.%02d", $dy,$mn+1,$yr, $h,$m); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
sub ksize{ |
| 272 |
local($size) = @_; |
| 273 |
local($k); |
| 274 |
|
| 275 |
if($size eq "") { |
| 276 |
return " N/A"; |
| 277 |
} |
| 278 |
else { |
| 279 |
if($size == 0) { |
| 280 |
$k = 0; |
| 281 |
} |
| 282 |
elsif($size <= 1024) { |
| 283 |
$k = 1; |
| 284 |
} |
| 285 |
else { |
| 286 |
$k = $size / 1024; |
| 287 |
} |
| 288 |
return sprintf("%4dK", $k); |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
sub toupper{ |
| 294 |
local($name) = @_; |
| 295 |
$name =~ tr/a-z/A-Z/; |
| 296 |
return $name; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
############################################################################# |
| 301 |
# |
| 302 |
# ToDo: |
| 303 |
# |
| 304 |
# - use files.bbs to add comments to filelist |
| 305 |
# - remove duplicates from files.bbs |
| 306 |
# - find new files and announce them via news or mail |
| 307 |
# |