2 eval "exec perl -S $0 $*"
3 if $running_under_some_shell;
5 # $Id: kitpost.SH 1 2006-08-24 12:32:52Z rmanfredi $
7 # Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
9 # You may redistribute only under the terms of the Artistic Licence,
10 # as specified in the README file that comes with the distribution.
11 # You may reuse parts of this distribution only within the terms of
12 # that same Artistic Licence; a copy of which may be found at the root
13 # of the source tree for dist 4.0.
15 # $Log: kitpost.SH,v $
16 # Revision 3.0.1.2 1994/10/29 15:48:26 ram
17 # patch36: don't use rootid as a variable, it is known by metaconfig
19 # Revision 3.0.1.1 1994/05/06 13:54:53 ram
24 $mailer='/usr/sbin/sendmail';
25 $orgname='PROCURA B.V.';
29 $progname = &profile; # Read ~/.dist_profile
31 &usage unless $#ARGV >= 0;
32 &usage unless &Getopts("hrVm:D:H:");
35 print STDERR "$progname $version PL$patchlevel\n";
41 $RCSEXT = ',v' unless $RCSEXT;
42 if ($inews eq 'inews') {
43 $inews = '/usr/lib/news/inews' if -f '/usr/lib/news/inews';
46 chdir '..' if -d '../bugs';
50 $orgname = &tilda_expand($orgname);
51 chop($orgname = `cat $orgname`) if $orgname =~ m|^/|;
54 $repost = ' (REPOST)';
58 if (/^(kit)?[1-9][\d\-]*$/) {
65 $ngroups = join(',',@ngroups) unless $#ngroups < 0;
67 &usage unless $ngroups || $dest;
71 if (-f "$package.kit10") {
72 @filelist = <$package.kit[0-9][0-9]>;
75 @filelist = <$package.kit[0-9]>;
77 pop(@filelist) =~ /(\d+)$/ && ($maxnum = $1 + 0);
84 $argv = &rangeargs(@ARGV);
85 @ARGV = split(' ', $argv);
90 print STDERR "$progname: no kits specified.\n";
93 local($s) = $#ARGV ? 's' : '';
94 print "$progname: posting $package $baserev kit$s $argv to $ngroups...\n"
96 print "$progname: mailing $package $baserev kit$s $argv to $dest...\n"
100 $desc = "$opt_D, " if $opt_D;
104 # Compute a suitable root message ID that all parts will reference, so that
105 # threaded news readers will correctly process them.
106 # Unfortunately, this works only when all kits are sent.
107 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
110 $rootmid = "$year$mon$mday$hour$min$sec.AA$$";
111 $first = $maxnum >= 10 ? "01" : "1";
112 $rootmsgid = "<$rootmid.P$first.$maintloc>";
116 $kitnum = "0$kitnum" if $kitnum < 10 && $maxnum >= 10;
117 open(FILE, "$package.kit$kitnum") ||
118 die "$progname: can't open $package.kit$kitnum: $!\n";
120 open(INEWS,"|$inews -h") || die "$progname: can't fork $inews: $!\n";
123 $opt = '-odq' if $mailer =~ /sendmail/;
125 ($to = $dest) =~ s/\s+/, /g;
126 open(MAILER,"|$mailer $opt $dest") ||
127 die "$progname: can't fork $mailer: $!\n";
130 $msg_id = "<$rootmid.P$kitnum.$maintloc>";
131 $msg_id = $rootmsgid if $kitnum == 1;
132 $msg_id .= "\nReferences: $rootmsgid" if $kitnum != 1;
134 print INEWS "Newsgroups: $ngroups\n";
135 print MAILER "To: $to\n";
137 Subject: $package $baserev - ${desc}part$kitnum/$maxnum$repost
139 Organization: $orgname
141 Submitted-by: $maintname <$maintloc>
142 Archive-name: $package-$baserev/part$kitnum
149 if ($kitnum == 1 && $opt_H) {
150 open(HEAD, $opt_H) || warn "$progname: can't open $opt_H: $!\n";
164 die "$progname: could not post part$kitnum.\n" if $ngroups && $?;
166 die "$progname: could not send part$kitnum.\n" if $dest && $?;
171 Usage: $progname [-hrV] [-H file] [-D desc] [-m dest1,dest2] [kits] [newsgroups]
172 -h : print this message and exit
173 -m : set-up recipients for (additional) mailing
174 -r : signals a repost
175 -D : specify description string for subject line
176 -H : specify file to be used as header for first part
177 -V : print version number and exit
193 elsif (s/^-(\d*)//) {
195 if ($max == 0 && $maxnum) {
203 for ($i = $min; $i <= $max; ++$i) {
212 if (! -f '.package') {
215 -f '../../.package' ||
216 -f '../../../.package' ||
217 -f '../../../../.package'
219 die "Run in top level directory only.\n";
221 die "No .package file! Run packinit.\n";
224 open(PACKAGE,'.package');
228 if (($var,$val) = /^\s*(\w+)=(.*)/) {
229 $val = "\"$val\"" unless $val =~ /^['"]/;
230 eval "\$$var = $val;";
236 # Perform ~name expansion ala ksh...
237 # (banish csh from your vocabulary ;-)
240 return $path unless $path =~ /^~/;
241 $path =~ s:^~([^/]+):(getpwnam($1))[$[+7]:e; # ~name
242 $path =~ s:^~:$ENV{'HOME'} || (getpwuid($<))[$[+7]:e; # ~
246 # Set up profile components into %Profile, add any profile-supplied options
247 # into @ARGV and return the command invocation name.
249 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
250 local($me) = $0; # Command name
251 $me =~ s|.*/(.*)|$1|; # Keep only base name
252 return $me unless -s $profile;
253 local(*PROFILE); # Local file descriptor
254 local($options) = ''; # Options we get back from profile
255 unless (open(PROFILE, $profile)) {
256 warn "$me: cannot open $profile: $!\n";
262 next if /^\s*#/; # Skip comments
264 if (s/^$me://o) { # progname: options
266 $options .= $_; # Merge options if more than one line
268 elsif (s/^$me-([^:]+)://o) { # progname-component: value
271 s/^\s+//; # Trim leading and trailing spaces
273 $Profile{$component} = $_;
277 return unless $options;
278 require 'shellwords.pl';
280 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
281 unshift(@ARGV, @opts);
282 return $me; # Return our invocation name