4 my $USAGE = <<'#'; |
4 my $USAGE = <<'#'; |
5 $ME [options] |
5 $ME [options] |
6 --[no]db insert into log database [$opt_db] |
6 --[no]db insert into log database [$opt_db] |
7 --[no]mail send mails to @config::mailto [$opt_mail] |
7 --[no]mail send mails to @config::mailto [$opt_mail] |
8 --message=s message |
8 --message=s message |
9 - if the message looks like a file name (e.g.: |
9 - if the message starts with '@' it's considered |
10 ./text or /tmp/text, the message is read |
10 to be a message FILE. |
11 from this file) |
11 - message can be: apt[:text]@<FILE> - this will |
12 - if message is 'upgrade:<FILE>' or |
12 start special file processing (assuming output |
13 'dist-upgrade:<FILE>', the file is parsed as apt |
13 from apt, with text (default: APT: upgrade) going |
14 output |
14 to the first line) |
15 # |
15 # |
16 |
16 |
17 use strict; |
17 use strict; |
18 use warnings; |
18 use warnings; |
19 use File::Basename; |
19 use File::Basename; |
70 "mail!" => \$opt_mail, |
70 "mail!" => \$opt_mail, |
71 "message=s" => \$opt_message, |
71 "message=s" => \$opt_message, |
72 "type=s" => \$opt_apt, |
72 "type=s" => \$opt_apt, |
73 ) or die eval "\"$USAGE\""; |
73 ) or die eval "\"$USAGE\""; |
74 |
74 |
75 if ($opt_message =~ /^\.?\// and -f $opt_message) { |
75 if ($opt_message =~ /^@(.*)/) { |
76 @ARGV = ($opt_message); |
76 @ARGV = $1; |
77 $opt_message = join "", <>; |
77 $opt_message = join "", <>; |
78 } elsif ($opt_message eq "-") { |
78 } elsif ($opt_message eq "-") { |
79 $opt_message = join "", <STDIN>; |
79 $opt_message = join "", <STDIN>; |
80 } elsif ($opt_message =~ /^((?:dist-)?upgrade):(.*)/) { |
80 } elsif ($opt_message =~ /^apt(?::(.*))?\@(\S+)/) { |
81 open(I, $2) or die "Can't open $2: $!\n"; |
81 open(I, $2) or die "Can't open $2: $!\n"; |
82 $opt_message = "$1\n" |
82 $opt_message = ($1 ? "APT: $1\n" : "APT: upgrade\n") |
83 . join "", grep /^(?:\d|Inst|Conf|Remv)/, <I>; |
83 . join "", map { /^(?:\d|Inst|Conf|Remv)/ ? "- $_" : () } <I>; |
84 |
|
85 die $opt_message; |
|
86 } |
84 } |
87 |
85 |
88 if ($opt_message =~ /\n/) { |
86 if ($opt_message =~ /\n/) { |
89 $opt_message =~ s/\n/\n /g; |
87 $opt_message =~ s/\n/\n /g; |
90 } |
88 } |