1case $CONFIG in 2'') 3 if test -f config.sh; then TOP=.; 4 elif test -f ../config.sh; then TOP=..; 5 elif test -f ../../config.sh; then TOP=../..; 6 elif test -f ../../../config.sh; then TOP=../../..; 7 elif test -f ../../../../config.sh; then TOP=../../../..; 8 else 9 echo "Can't find config.sh."; exit 1 10 fi 11 . $TOP/config.sh 12 ;; 13*) 14 TOP=..;; 15esac 16revision=`awk '/^#define[ ]*REVISION/ {print $3}' < $TOP/revision.h` 17case "$0" in 18*/*) cd `expr X$0 : 'X\(.*\)/'` ;; 19esac 20echo "Extracting agent/maildist (with variable substitutions)" 21$spitshell >maildist <<!GROK!THIS! 22$startperl 23 eval "exec /usr/local/bin/perl -S \$0 \$*" 24 if \$running_under_some_shell; 25 26# $Id$ 27# 28# Copyright (c) 1990-2006, Raphael Manfredi 29# 30# You may redistribute only under the terms of the Artistic License, 31# as specified in the README file that comes with the distribution. 32# You may reuse parts of this distribution only within the terms of 33# that same Artistic License; a copy of which may be found at the root 34# of the source tree for mailagent 3.0. 35# 36# $Log: maildist.SH,v $ 37# Revision 3.0.1.5 1996/12/24 14:06:44 ram 38# patch45: silently discard hostile addresses 39# patch45: added command forwarding support 40# 41# Revision 3.0.1.4 1995/03/21 12:54:59 ram 42# patch35: added pl/cdir.pl to the list of appended files 43# 44# Revision 3.0.1.3 1994/10/10 10:22:47 ram 45# patch19: added various escapes in strings for perl5 support 46# 47# Revision 3.0.1.2 1994/10/04 17:36:03 ram 48# patch17: now uses the email config parameter to send messages to user 49# patch17: extended logging to get better error/failure tracking 50# 51# Revision 3.0.1.1 1993/12/17 08:12:18 ram 52# patch4: a regular expression got corrupted by an appliance of itself 53# 54# Revision 3.0 1993/11/29 13:48:23 ram 55# Baseline for mailagent 3.0 netwide release. 56# 57 58\$mversion = '$VERSION'; 59\$patchlevel = '$PATCHLEVEL'; 60\$revision = '$revision'; 61!GROK!THIS! 62 63$spitshell >>maildist <<'!NO!SUBS!' 64 65$prog_name = $0; # Who I am 66$prog_name =~ s|^.*/(.*)|$1|; # Keep only base name 67 68&read_config; # First, read configuration file (in ~/.mailagent) 69 70# take job number and command from environment 71# (passed by mailagent) 72$jobnum = $ENV{'jobnum'}; 73$fullcmd = $ENV{'fullcmd'}; 74$pack = $ENV{'pack'}; 75$path = $ENV{'path'}; 76 77&read_dist; # Read distributions 78 79$dest = shift; # Who should the system be sent to 80$system = shift; # Which system 81$version = shift; # Which version it is 82 83# A single '-' as first argument stands for return path 84$dest = $path if $dest eq '-'; 85 86# A single '-' for version means "highest available" version 87$version = $Version{$system} if $version eq '-' || $version eq ''; 88 89# Full program's name for H table access 90$pname = $system . "|" . $version; 91 92$maillist = "To obtain a list of what is available, send me the following mail: 93 94 Subject: Command 95 \@SH maillist $path 96 ^ note the l"; 97 98# Silently discard hostile addresses 99unless (&addr'valid($dest)) { 100 &add_log("FAILED (HOSTILE $dest)") if $loglvl > 1; 101 exit 0; 102} 103 104if (!$System{$system}) { 105 open(MAILER, "|$cf'sendmail $cf'mailopt $path $cf'email") || &nofork; 106 print MAILER 107"To: $path 108Subject: No program called $system 109X-Mailer: mailagent [version $mversion-$revision] 110 111I don't know how to send a program called \"$system\". Sorry. 112 113$maillist 114 115If $cf'name can figure out what you meant, you'll get the program anyway. 116 117-- $prog_name speaking for $cf'user 118"; 119 close MAILER; 120 if ($?) { 121 &add_log("ERROR cannot report system $system is unknown") if $loglvl; 122 } else { 123 &add_log("MSG system $system is unknown") if $loglvl > 6; 124 } 125 &add_log("FAILED (UNKNOWN SYSTEM)") if $loglvl > 1; 126 exit 0; 127} 128 129if (!$Program{$pname}) { 130 open(MAILER, "|$cf'sendmail $cf'mailopt $path $cf'email") || &nofork; 131 print MAILER 132"To: $path 133Subject: No version $version for $system 134X-Mailer: mailagent [version $mversion-$revision] 135 136I don't know how to send version $version of $system. Sorry. 137 138$maillist 139 140If $cf'name can figure out what you meant, you'll get the program anyway. 141 142-- $prog_name speaking for $cf'user 143"; 144 close MAILER; 145 if ($?) { 146 &add_log("ERROR cannot report system $system $version is unknown") 147 if $loglvl; 148 } else { 149 &add_log("MSG system $system version $version is unknown") 150 if $loglvl > 6; 151 } 152 &add_log("FAILED (BAD VERSION NUMBER)") if $loglvl > 1; 153 exit 0; 154} 155 156# Has the user made a request for an old version (patch only) ? 157if ($Patch_only{$pname}) { 158 # It is required that patch only systems have a version number 159 &abort("old system has no version number") if $version eq ''; 160 open(MAILER, "|$cf'sendmail $cf'mailopt $path $cf'email") || &nofork; 161 print MAILER 162"To: $path 163Subject: System $system $version is obsolete 164X-Mailer: mailagent [version $mversion-$revision] 165 166I can't send you version $version of $system. Sorry. 167 168This version appears to be an old one, and only patches are available. 169The up-to-date version for $system is $Version{$system}. 170 171$maillist 172 173If $cf'name can figure out what you meant, he may send you the latest version. 174 175-- $prog_name speaking for $cf'user 176"; 177 close MAILER; 178 if ($?) { 179 &add_log("ERROR cannot report system $system $version is obsolete") 180 if $loglvl; 181 } else { 182 &add_log("MSG system $system $version is obsolete") if $loglvl > 6; 183 } 184 &add_log("FAILED (PATCH ONLY VERSION)") if $loglvl > 1; 185 exit 0; 186} 187 188# If the request is not the most recent version, warn the user. 189if ($version < $Version{$system}) { 190 open(MAILER, "|$cf'sendmail $cf'mailopt $path $cf'email") || &nofork; 191 print MAILER 192"To: $path 193Subject: Version $version of $system is an old one 194X-Mailer: mailagent [version $mversion-$revision] 195 196You asked for version $version of $system. 197 198This version appears to be an old one, but it is sill available, and 199I am currently processing your request. However, I wanted to let you 200know that the up-to-date version for $system is $Version{$system}. 201 202$maillist 203 204Unless you receive an error message telling you otherwise, I am sending 205you version $version of $system. You may also request for the new version 206right now if you wish. 207 208-- $prog_name speaking for $cf'user 209"; 210 close MAILER; 211 if ($?) { 212 &add_log("ERROR cannot report $system $version is old") if $loglvl; 213 } else { 214 &add_log("MSG system $system $version is old") if $loglvl > 6; 215 } 216} 217 218# Create a temporary directory 219$tmp = "$cf'tmpdir/dmd$$"; 220mkdir($tmp, 0700); 221 222# Need to unarchive the distribution 223if ($Archived{$pname}) { 224 # Create a temporary directory for distribution 225 $tmp_loc = "$cf'tmpdir/dmdl$$"; 226 mkdir($tmp_loc, 0700); 227 $location = 228 &unpack($Location{$pname}, $tmp_loc, $Compressed{$pname}); 229} else { 230 $location = $Location{$pname}; 231} 232 233# Go to the package root directory and check for possible forwarding... 234chdir($location) || &abort("cannot chdir to $location: $!"); 235&check_forward; # Returns only if command is not forwarded 236 237# We are now in the place. Look for a MANIFEST file. If none, we will 238# send *everything* held, RCS sub-directories and executable/object files 239# excepted. 240 241$manifest = ''; 242$tmp_list = ''; 243 244if (-f 'MANIFEST') { 245 $manifest = "$location/MANIFEST"; 246} else { 247 $tmp_list = "$cf'tmpdir/mdlist$$"; 248 open(FIND, "find . -type f -print | sort |") || 249 &abort("cannot run find"); 250 open(LIST, ">$tmp_list") || 251 &abort("cannot create $tmp_list"); 252 while (<FIND>) { 253 chop; 254 s|\./||; 255 next if (m|^U/| && -f '.package'); # Skip units if meta-configured 256 next if m|^RCS/|; # Skip RCS files 257 next if m|/RCS/|; 258 next if m|,v$|; 259 next if m|bugs/|; # Skip bugs files (patches and al.) 260 next if m|^\.#|; # Skip [marked for deletion] files 261 next if m|/\.#|; 262 next if m|\.o$|; # Skip object files 263 next if m|core$|; # Skip core files 264 next if (-x $_ && -B $_); # Skip binaries 265 print LIST $_,"\n"; # Keep that file 266 } 267 close FIND; 268 close LIST; 269 $manifest = $tmp_list; 270} 271 272&add_log("manifest is in $manifest") if $loglvl > 19; 273 274# If distribution is maintained by dist 3.0 (at least), there is a .package 275# file in there and we can invoke makedist. Otherwise, we have to do it by 276# hand... 277 278if (-f '.package') { 279 system "makedist -c $tmp -f $manifest"; 280 &abort("cannot run makedist -c $tmp") if $?; 281} else { 282 &makedist; 283} 284 285$subject = "$system"; 286$subject .= " $version" if $version ne '0'; 287$subject .= " package"; 288&sendfile($dest, $tmp, $pack, $subject); 289&clean_tmp; 290 291exit 0; # Ok 292 293# Now for each file in manifest, look if there is an 294# RCS file associated with it. If so, check out either 295# the 'lastpat' version or the highest version on the 296# default branch, provided that the file does not exists 297# in checked-out form. Otherwise, only run co if 'lastpat' 298# is defined. 299sub makedist { 300 chdir $tmp || &abort("cannot chdir to $tmp"); 301 open(MANI, $manifest) || &abort("cannot open $manifest"); 302 while (<MANI>) { 303 next if /^--/; 304 s|^\s*||; # Remove leading spaces 305 ($file,$foo) = split; # Save filename, discard comments 306 next if (-d "$location/$file"); # Skip directories 307 next if ($file =~ /^\s*$/); # Skip blank lines 308 # Extract dirname and basename 309 ($dir, $base) = ('', $file) 310 unless ($dir, $base) = ($file =~ m|(.*/)(.*)|); 311 $logmsg = ''; # String to add to log message 312 $rcsfile = 'blurfl'; 313 $rcsfile = "$location/$file,v" if (-f "$location/$file,v"); 314 $rcsfile = "$location/${dir}RCS/$base,v" 315 if (-f "$location/${dir}RCS/$base,v"); 316 next unless -f "$location/$file" || -f "$rcsfile"; # Skip unexisting files 317 &makedir($dir) unless $dir eq ''; 318 open(COPY, ">$file") || &abort("cannot create $file"); 319 if ($rcsfile ne '') { 320 $rlog = `rlog $rcsfile 2>&1`; 321 ($revs) = ($rlog =~ /lastpat: (\d+)/); 322 if (!$revs) { 323 # Symbol 'lastpat' is not defined 324 # If file exists, open it. Otherwise, run co 325 if (-f "$location/$file") { 326 $logmsg = " (lastpat undefined)"; 327 $origfile = "$location/$file"; 328 open(FILE, $origfile) || 329 &abort("cannot open $origfile"); 330 } else { 331 $logmsg = " (co but no lastpat)"; 332 $origfile = $rcsfile; 333 open(FILE, "co -q -p $rcsfile |") || 334 &abort("cannot run co on $rcsfile"); 335 } 336 } else { 337 # Symbol 'lastpat' is defined 338 $logmsg = " (co lastpat)"; 339 $origfile = $rcsfile; 340 open(FILE, "co -q -p -rlastpat $rcsfile |") || 341 &abort("cannot run co on $rcsfile"); 342 } 343 } else { 344 $origfile = "$location/$file"; 345 open(FILE, "$location/$file") || 346 &abort("cannot open $location/$file"); 347 } 348 while (<FILE>) { 349 # Use Lock[e]r, not Locker, since we might apply this on 350 # ourself one day and get corrupted... 351 s|Lock[e]r:.*\$|\$|; # Remove locker mark 352 (print COPY) || &abort("copy error: $!"); 353 } 354 close(FILE) || &abort("copy error: $!"); 355 close COPY; 356 &add_log("copied $file$logmsg") if $loglvl > 19; 357 358 # If file is executable, change its permissions 359 if (-x $origfile) { 360 chmod 0755, $file; 361 } else { 362 chmod 0644, $file; 363 } 364 } 365} 366 367sub clean_tmp { 368 # Do not stay in the directories we are removing... 369 chdir $cf'home; 370 if ($tmp ne '') { 371 system '/bin/rm', '-rf', $tmp; 372 &add_log("removed dir $tmp") if $loglvl > 19; 373 } 374 if ($Archived{$pname}) { 375 system '/bin/rm', '-rf', $tmp_loc; 376 &add_log("removed dir $tmp_loc") if $loglvl > 19; 377 } 378 unlink $tmp_list if $tmp_list ne ''; 379} 380 381# Emergency exit with clean-up 382sub abort { 383 local($reason) = shift(@_); # Why we are exiting 384 &clean_tmp; 385 &fatal($reason); 386} 387 388# Report error while forking a sendmail process 389sub nofork { 390 &add_log("SYSERR fork: $!") if $loglvl; 391 &add_log("ERROR cannot launch $cf'sendmail") if $loglvl; 392} 393 394!NO!SUBS! 395$grep -v '^;#' pl/makedir.pl >>maildist 396$grep -v '^;#' pl/fatal.pl >>maildist 397$grep -v '^;#' pl/add_log.pl >>maildist 398$grep -v '^;#' pl/read_conf.pl >>maildist 399$grep -v '^;#' pl/unpack.pl >>maildist 400$grep -v '^;#' pl/sendfile.pl >>maildist 401$grep -v '^;#' pl/distribs.pl >>maildist 402$grep -v '^;#' pl/secure.pl >>maildist 403$grep -v '^;#' pl/cdir.pl >>maildist 404$grep -v '^;#' pl/addr.pl >>maildist 405$grep -v '^;#' pl/forward.pl >>maildist 406chmod 755 maildist 407$eunicefix maildist 408