2 eval 'exec perl -S $0 "$@"'
3 if $running_under_some_shell;
5 # $Id: kitsend.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 # Original Author: Harlan Stenn <harlan@mumps.pfcs.com>
17 # $Log: kitsend.SH,v $
18 # Revision 3.0.1.2 1994/05/06 13:59:57 ram
19 # patch23: random code cleanup to follow pat tools style
20 # patch23: made configurable from dist profile
21 # patch23: now understands -V and -h options
22 # patch23: mails now flagged with a bulk precedence
23 # patch23: added X-Mailer header and now calls mailer via open()
25 # Revision 3.0.1.1 1993/08/19 06:42:15 ram
26 # patch1: leading config.sh searching was not aborting properly
28 # Revision 3.0 1993/08/18 12:04:25 ram
29 # Baseline for dist 3.0 netwide release.
32 $orgname='PROCURA B.V.';
33 $mailer='/usr/sbin/sendmail';
37 $progname = &profile; # Read ~/.dist_profile
39 &usage unless &Getopts('hV');
42 print STDERR "$progname $version PL$patchlevel\n";
48 $orgname = &tilda_expand($orgname);
49 chop($orgname = `cat $orgname`) if $orgname =~ m|^/|;
54 if (/^(kit)?[1-9][\d,-]*$/) {
62 $dest = join(' ',@dest);
67 if (-f "$package.kit10") {
68 @filelist = <$package.kit[0-9][0-9]>;
71 @filelist = <$package.kit[0-9]>;
73 pop(@filelist) =~ /(\d+)$/ && ($maxnum = $1 + 0);
79 $argv = &rangeargs(@ARGV);
80 @ARGV = split(' ', $argv);
85 die "$progname: no kits specified.\n";
87 print "$progname: sending $package $baserev kits $argv to $dest...\n";
89 print "$progname: sending $package $baserev kit $argv to $dest...\n";
94 $opt = '-odq' if $mailer =~ /sendmail/;
99 # Provision for broken mailers...
100 @dest = split(' ', $dest);
101 while (@smalldest = splice(@dest, 0, 50)) {
102 $to = join(', ', @smalldest); # Sensible To: for sendmail
103 $smalldest = join(' ', @smalldest);
105 open(MAILER, "|$mailer $opt $smalldest") ||
106 die "$progname: can't fork $mailer: $!\n";
109 Subject: $package $baserev kit #$kitnum
111 X-Mailer: dist [version $version PL$patchlevel]
112 Organization: $orgname
114 [There are $maxnum kits for $package version $baserev.]
117 $kitnum = "0$kitnum" if $kitnum < 10 && $maxnum >= 10;
118 open(FILE,"$package.kit$kitnum") ||
119 die "$progname: can't open $package.kit$kitnum: $!\n";
125 warn "$progname: ERROR mailing of $package.kit$kitnum to $dest\n" if $?;
131 Usage: $progname [-hV] [kits] dest
132 -h : print this message and exit
133 -V : print version number and exit
149 elsif (s/^-(\d*)//) {
151 if ($max == 0 && $maxnum) {
159 for ($i = $min; $i <= $max; ++$i) {
168 if (! -f '.package') {
171 -f '../../.package' ||
172 -f '../../../.package' ||
173 -f '../../../../.package'
175 die "Run in top level directory only.\n";
177 die "No .package file! Run packinit.\n";
180 open(PACKAGE,'.package');
184 if (($var,$val) = /^\s*(\w+)=(.*)/) {
185 $val = "\"$val\"" unless $val =~ /^['"]/;
186 eval "\$$var = $val;";
192 # Perform ~name expansion ala ksh...
193 # (banish csh from your vocabulary ;-)
196 return $path unless $path =~ /^~/;
197 $path =~ s:^~([^/]+):(getpwnam($1))[$[+7]:e; # ~name
198 $path =~ s:^~:$ENV{'HOME'} || (getpwuid($<))[$[+7]:e; # ~
202 # Set up profile components into %Profile, add any profile-supplied options
203 # into @ARGV and return the command invocation name.
205 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
206 local($me) = $0; # Command name
207 $me =~ s|.*/(.*)|$1|; # Keep only base name
208 return $me unless -s $profile;
209 local(*PROFILE); # Local file descriptor
210 local($options) = ''; # Options we get back from profile
211 unless (open(PROFILE, $profile)) {
212 warn "$me: cannot open $profile: $!\n";
218 next if /^\s*#/; # Skip comments
220 if (s/^$me://o) { # progname: options
222 $options .= $_; # Merge options if more than one line
224 elsif (s/^$me-([^:]+)://o) { # progname-component: value
227 s/^\s+//; # Trim leading and trailing spaces
229 $Profile{$component} = $_;
233 return unless $options;
234 require 'shellwords.pl';
236 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
237 unshift(@ARGV, @opts);
238 return $me; # Return our invocation name