fix permissions
[spider.git] / perl / importkeps.pl
1 #!/usr/bin/perl
2 #
3 # Take a 2 line keps email file on STDIN, prepare it for import into standard import directory
4 # and then shove it there, marked for SB ALL.
5 #
6 # Copyright (c) 2004 Dirk Koopman G1TLH
7 #
8 # $Id$
9 #
10
11 use strict;
12
13 our $root;
14
15 # search local then perl directories
16 BEGIN {
17         # root of directory tree for this system
18         $root = "/spider"; 
19         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
20         
21         unshift @INC, "$root/perl";     # this IS the right way round!
22         unshift @INC, "$root/local";
23 }
24
25 my $fromcall = shift || 'G1TLH';
26 my $inp;
27 {
28         local $/ = undef;
29         $inp = <STDIN>;
30 }
31
32 # is it a 2 line kep file?
33 if ($inp =~ /ubject:\s+\[keps\]\s+orb\d{5}\.2l\.amsat/) {
34         process();
35 }
36
37 exit(0);
38
39
40 #
41 # process the file
42 #
43
44 sub process
45 {
46         # chop off most of the beginning
47         return unless $inp =~ s/^.*SB\s+KEPS\s+\@\s+AMSAT\s+\$ORB\d{5}\.\w/SB ALL < $fromcall/s;
48         return unless $inp =~ s/2Line\s+Orbital\s+Elements/2Line Keps/;
49         
50         # open the output file in the data area
51         my $fn = "$root/tmp/keps.txt.$$";
52         open OUT, ">$fn" or die "$fn $!";
53         chmod 0666, $fn;
54         print OUT $inp;
55         close OUT;
56
57         link $fn, "$root/msg/import/keps.txt.$$";
58         unlink $fn;
59 }