58 "V|version" => sub { version($ME, $VERSION); exit $ERRORS{OK}; } |
58 "V|version" => sub { version($ME, $VERSION); exit $ERRORS{OK}; } |
59 ) or pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL}); |
59 ) or pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL}); |
60 |
60 |
61 $opt->{url} // pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL}); |
61 $opt->{url} // pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL}); |
62 |
62 |
63 my $file = download($opt->{url}, $opt->{path}); |
63 my $tmp = File::Temp->new(); |
64 my $run_file = verify($file); |
64 my $file = download($opt->{url}, $opt->{path}); |
|
65 my $run_file = verify($file => $tmp); |
65 |
66 |
66 warn "<< $run_file >>\n"; |
67 warn "<< $run_file >>\n"; |
67 die `cat $run_file`; |
68 die `cat $run_file`; |
68 } |
69 } |
69 |
70 |
99 |
100 |
100 unless (-d $path) { |
101 unless (-d $path) { |
101 mkpath($path, { mode => 0700, error => \my $err }); |
102 mkpath($path, { mode => 0700, error => \my $err }); |
102 for my $diag (@$err) { |
103 for my $diag (@$err) { |
103 my ($directory, $message) = %$diag; |
104 my ($directory, $message) = %$diag; |
104 print "EXEC CRITICAL: Can't create directory $directory: $message\n"; |
105 print |
|
106 "EXEC CRITICAL: Can't create directory $directory: $message\n"; |
105 } |
107 } |
106 exit $ERRORS{CRITICAL} if defined $err; |
108 exit $ERRORS{CRITICAL} if defined $err; |
107 } |
109 } |
108 |
110 |
109 $file = "$path/$file"; |
111 $file = "$path/$file"; |
110 |
112 |
111 my $rc = getstore($url, $file); |
113 my $rc = getstore($url, $file); |
112 if (is_error($rc)) { |
114 if (is_error($rc)) { |
113 unlink $file; |
115 unlink $file; |
114 |
116 |
115 if ($rc == 404) { |
117 if ($rc == 404) { |
116 print "EXEC OK: $url ", status_message($rc), "\n"; |
118 print "EXEC OK: $url ", status_message($rc), "\n"; |
117 exit $ERRORS{OK}; |
119 exit $ERRORS{OK}; |
118 } |
120 } |
119 |
121 |
120 print "EXEC CRITICAL: $url ", status_message($rc), "\n"; |
122 print "EXEC CRITICAL: $url ", status_message($rc), "\n"; |
121 exit $ERRORS{CRITICAL}; |
123 exit $ERRORS{CRITICAL}; |
122 } |
124 } |
123 |
125 |
124 return $file; |
126 return $file; |
125 } |
127 } |
126 |
128 |
127 sub verify($) { |
129 sub verify($$) { |
128 my $file = shift; |
130 my ($file, $tmp) = @_; |
129 my $dir = dirname($file); |
131 my $dir = dirname($file); |
130 my $tmp = File::Temp->new(); |
|
131 my $home_dir = (getpwuid($>))[7]; |
132 my $home_dir = (getpwuid($>))[7]; |
132 |
133 |
133 |
134 my $dc = |
134 my $dc = "$opt->{binary} --output @{[$tmp->filename]} --homedir $home_dir/.gnupg --batch --yes"; |
135 "$opt->{binary} --output $tmp --homedir $home_dir/.gnupg --batch --yes"; |
135 my @r = qx($dc $file 2>&1); |
136 my @r = qx($dc $file 2>&1); |
136 if ($?) { |
137 if ($?) { |
137 print "EXEC CRITICAL: @r"; |
138 print "EXEC CRITICAL: @r"; |
138 exit $ERRORS{CRITICAL}; |
139 exit $ERRORS{CRITICAL}; |
139 } |
140 } |