line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 tw=0: |
5
|
|
|
|
|
|
|
# vim: set expandtab: |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Rex::Apache::Inject::Command; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=begin |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head2 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This is a (R)?ex module to ease the deployments of PHP, Perl or other languages. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1502
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
18
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use Rex::Commands::Run; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
21
|
1
|
|
|
1
|
|
81
|
use Rex::Commands::Fs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
22
|
1
|
|
|
1
|
|
437
|
use Rex::Commands::Upload; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
23
|
1
|
|
|
1
|
|
60
|
use Rex::Commands; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
24
|
1
|
|
|
1
|
|
799
|
use File::Basename qw(dirname basename); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
25
|
1
|
|
|
1
|
|
4
|
use Cwd qw(getcwd); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#require Exporter; |
28
|
|
|
|
|
|
|
#use base qw(Exporter); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
6
|
use vars qw(@EXPORT $inject_command); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
759
|
|
31
|
|
|
|
|
|
|
@EXPORT = qw(inject |
32
|
|
|
|
|
|
|
inject_command); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $work_dir = getcwd; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
############ deploy functions ################ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub inject { |
39
|
0
|
|
|
0
|
0
|
|
my ( $to, @options ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $option = {@options}; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $cmd1 = sprintf( _get_extract_command($to), "../$to" ); |
44
|
0
|
|
|
|
|
|
my $cmd2 = sprintf( _get_pack_command($to), "../$to", "." ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
mkdir("tmp"); |
47
|
0
|
|
|
|
|
|
chdir("tmp"); |
48
|
0
|
|
|
|
|
|
run $cmd1; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
for my $opt ( $option->{"inject"} ) { |
51
|
0
|
|
|
|
|
|
run sprintf( $inject_command, $opt->{"key"}, $opt->{"value"} ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ( exists $option->{"pre_pack_hook"} ) { |
55
|
0
|
|
|
|
|
|
&{ $option->{"pre_pack_hook"} }; |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
run $cmd2; |
59
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
60
|
0
|
|
|
|
|
|
chdir(".."); |
61
|
0
|
|
|
|
|
|
system("rm -rf tmp"); |
62
|
0
|
|
|
|
|
|
die("Can't re-pack archive. Please check permissions. Command was: $cmd2"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ( exists $option->{"post_pack_hook"} ) { |
66
|
0
|
|
|
|
|
|
&{ $option->{"post_pack_hook"} }; |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
chdir(".."); |
70
|
0
|
|
|
|
|
|
system("rm -rf tmp"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
############ configuration functions ############# |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub inject_command { |
76
|
0
|
|
|
0
|
0
|
|
$inject_command = shift; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
############ helper functions ############# |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _get_extract_command { |
82
|
0
|
|
|
0
|
|
|
my ($file) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ( $file =~ m/\.tar\.gz$/ ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return "tar xzf %s"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif ( $file =~ m/\.zip$/ ) { |
88
|
0
|
|
|
|
|
|
return "unzip %s"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ( $file =~ m/\.tar\.bz2$/ ) { |
91
|
0
|
|
|
|
|
|
return "tar xjf %s"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ( $file =~ m/\.war$/ ) { |
94
|
0
|
|
|
|
|
|
return "unzip %s"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif ( $file =~ m/\.jar$/ ) { |
97
|
0
|
|
|
|
|
|
return "unzip %s"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
die("Unknown Archive Format."); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _get_pack_command { |
104
|
0
|
|
|
0
|
|
|
my ($file) = @_; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if ( $file =~ m/\.tar\.gz$/ ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return "tar czf %s %s"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ( $file =~ m/\.zip$/ ) { |
110
|
0
|
|
|
|
|
|
return "zip -r %s %s"; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif ( $file =~ m/\.tar\.bz2$/ ) { |
113
|
0
|
|
|
|
|
|
return "tar cjf %s %s"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
elsif ( $file =~ m/\.war$/ ) { |
116
|
0
|
|
|
|
|
|
return "zip -r %s %s"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif ( $file =~ m/\.jar$/ ) { |
119
|
0
|
|
|
|
|
|
return "zip -r %s %s"; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
die("Unknown Archive Format."); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _get_ext { |
126
|
0
|
|
|
0
|
|
|
my ($file) = @_; |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if ( $file =~ m/\.tar\.gz$/ ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return ".tar.gz"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
elsif ( $file =~ m/\.zip$/ ) { |
132
|
0
|
|
|
|
|
|
return ".zip"; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
elsif ( $file =~ m/\.tar\.bz2$/ ) { |
135
|
0
|
|
|
|
|
|
return ".tar.bz2"; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif ( $file =~ m/\.war$/ ) { |
138
|
0
|
|
|
|
|
|
return ".war"; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif ( $file =~ m/\.jar$/ ) { |
141
|
0
|
|
|
|
|
|
return ".jar"; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
die("Unknown Archive Format."); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
####### import function ####### |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub import { |
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
98
|
|
153
|
0
|
|
|
0
|
|
|
for my $func (@EXPORT) { |
154
|
0
|
|
|
|
|
|
Rex::Logger::debug("Registering main::$func"); |
155
|
0
|
|
|
|
|
|
*{"$_[1]::$func"} = \&$func; |
|
0
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |