rsynconrails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da0b3d172bb6bb6c7ce424bf2cc7675969d396a5
4
+ data.tar.gz: 0541459bbb8dc4b88baef347a0ed30d0c45527ee
5
+ SHA512:
6
+ metadata.gz: 33ee4c2cc241f54e58a663218c615ea97f491156e8cd4f4201517418acb0cf7d7a8e348b30ad7e4b430592ecc7f4cf37066ce1dc3c5351de9b5affa3e38361e5
7
+ data.tar.gz: d22a8035090d34b928bab7dee854f6e5dc268f95458ee9c5317c4fd1fc067ac340c6b7bfb2e8c0373f53b1ac3dac605bf2000727d7d50487a273d494dc514a3e
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ testdata
2
+ chroot
3
+ *.swp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rsynconrails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p195
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'net-ssh'
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.4)
5
+ net-ssh (2.6.7)
6
+ rspec (2.13.0)
7
+ rspec-core (~> 2.13.0)
8
+ rspec-expectations (~> 2.13.0)
9
+ rspec-mocks (~> 2.13.0)
10
+ rspec-core (2.13.1)
11
+ rspec-expectations (2.13.0)
12
+ diff-lcs (>= 1.1.3, < 2.0)
13
+ rspec-mocks (2.13.1)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ net-ssh
20
+ rspec
data/README.license ADDED
@@ -0,0 +1,92 @@
1
+ rsynconrails is authored by Joshua McClintock (joshua@gravityedge.com)
2
+ Copyright (C) 2013 Joshua McClintock and Gravity Edge Systems, LLP, all rights reserved
3
+ This software may be used according to the GPL 2.0 license below
4
+
5
+
6
+ GNU GENERAL PUBLIC LICENSE
7
+
8
+ Version 2, June 1991
9
+
10
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
11
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
12
+
13
+ Everyone is permitted to copy and distribute verbatim copies
14
+ of this license document, but changing it is not allowed.
15
+
16
+ Preamble
17
+
18
+ The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
19
+
20
+ When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
21
+
22
+ To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
23
+
24
+ For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
25
+
26
+ We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
27
+
28
+ Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
29
+
30
+ Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
31
+
32
+ The precise terms and conditions for copying, distribution and modification follow.
33
+
34
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
35
+
36
+ 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
37
+
38
+ Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
39
+
40
+ 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
41
+
42
+ You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
43
+
44
+ 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
45
+
46
+ a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
47
+ b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
48
+ c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
49
+ These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
50
+
51
+ Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
52
+
53
+ In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
54
+
55
+ 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
56
+
57
+ a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
58
+ b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
59
+ c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
60
+ The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
61
+
62
+ If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
63
+
64
+ 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
65
+
66
+ 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
67
+
68
+ 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
69
+
70
+ 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
71
+
72
+ If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
73
+
74
+ It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
75
+
76
+ This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
77
+
78
+ 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
79
+
80
+ 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
81
+
82
+ Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
83
+
84
+ 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
85
+
86
+ NO WARRANTY
87
+
88
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
89
+
90
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
91
+
92
+ END OF TERMS AND CONDITIONS
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ rsynconrails
2
+ ============
3
+ Rsync on Rails is an implementation of 'just enough computing'.
4
+
5
+ Unlike tools such as chef or puppet, rsynconrails aims to manage the whole operating system, not just a small subset. Files and directories are applied to the remote host in an 'already installed' state. Instead of telling the host which deb's or rpm's it should have, you define what files, directories, and configuration it'll have. Because this is a different way of the looking at the change management world, it requires that you have all the files/directories/configuration in place already on the master side (the side pushing the content down to the remote host). This is called a 'package tree'.
6
+
7
+ The 'package tree' is where most of your work will occur. Utilties are provided to unpack standard packages such as rpm or deb and place them into the 'package tree'. The initial work for a 'package tree' can be a bit tedious at present.
8
+
9
+ While this may seem like too much work, there are some great benefits you get from doing it this way. The first is that you're guaranteed that the systems you deploy are exactly as they should be down to every file in every directory. You're also sure that if there aren't any foreign libraries sitting around which may trip up your application that someone installed trying to 'fix' something. You also get the side benefit of what tripwire does. A full filesystem audit will tell you if any of your files are different than the master source. This is good for seeing things like rootkits and other foreign binaries/libraries. Another great benefit is that since you're controlling the entire OS, you also gain the ability to easily backup the non-managed or 'excluded' parts, such as log files and other data files produced by daemons and utilities.
10
+
@@ -0,0 +1,15 @@
1
+ development:
2
+ base_dir: "/home/joshua/Projects/rsynconrails"
3
+ data_dir: "/home/joshua/Projects/rsynconrails/testdata"
4
+ hosts_dir: "/home/joshua/Projects/rsynconrails/testdata/hosts"
5
+ packages_dir: "/home/joshua/Projects/rsynconrails/testdata/packages"
6
+ transforms_dir: "/home/joshua/Projects/rsynconrails/testdata/transforms"
7
+ default_dist: "test_dist"
8
+ debug: false
9
+
10
+ test:
11
+
12
+ production:
13
+ base_dir: "/home/joshua/Projects/rsynconrails"
14
+ data_dir: "/home/joshua/Projects/rsynconrails/data"
15
+ debug: false
data/lib/cli_funcs.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'system_config'
2
+ require 'cli_utils'
3
+
4
+ class CliFuncs
5
+ attr_accessor :base_dir, :data_dir, :ignore_bad_exit, :flags_all
6
+ attr_reader :output
7
+
8
+ def initialize
9
+ @ignore_bad_exit = false
10
+ @base_dir = String
11
+ @data_dir = String
12
+ @output = Array.new
13
+ @flags_all = Array.new
14
+ set_dirs
15
+ end
16
+
17
+ def set_dirs
18
+ @base_dir = SYSTEM_CONFIG["base_dir"]
19
+ @data_dir = SYSTEM_CONFIG["data_dir"]
20
+ end
21
+
22
+ def flags_run
23
+ @flags_all
24
+ end
25
+
26
+ def flag_add(flag)
27
+ @flags_all.push(flag) unless flag == nil
28
+ end
29
+
30
+ def clear_values
31
+ @flags_all = Array.new
32
+ @output = Array.new
33
+ end
34
+
35
+ def run_and_capture(*args)
36
+ args.flatten!
37
+ begin
38
+ puts "Args: #{args}" if DEBUG
39
+ stdin, stdout_and_stderr, wait_thr = Open3.popen2e(*args)
40
+ if(wait_thr.value.exitstatus != 0 unless @ignore_bad_exit)
41
+ stdout_and_stderr.each do |line|
42
+ puts line
43
+ end
44
+ raise "Ran #{args} and command with pid #{wait_thr.value.to_i} exited #{wait_thr.value.exitstatus}, error above."
45
+ end
46
+ stdout_and_stderr.each do |line|
47
+ @output.push(line)
48
+ p line if DEBUG
49
+ end
50
+ rescue Exception => e
51
+ puts "Tried to run command: #{args[0, args.size]}, received exception: #{e}"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ require 'system_config'
2
+ require 'cli_funcs'
3
+
4
+ class Cpio < CliFuncs
5
+ attr_accessor :rpm_file, :extract_dir, :cpio_data
6
+ attr_reader :data_dir
7
+
8
+ def initialize
9
+ super
10
+ @cpio_data
11
+ @utility = CliUtils.new("cpio").utility_path
12
+ @data_dir = SYSTEM_CONFIG["data_dir"]
13
+ @extract_dir = ""
14
+ set_extract_flags
15
+ end
16
+
17
+ def cpio
18
+ begin
19
+ FileUtils.mkdir_p @extract_dir unless Dir.exists? @extract_dir
20
+ opts = { :chdir => @extract_dir, :err => "/dev/null" }
21
+ io = IO.popen([@utility, flags_run].flatten, mode='r+', opts)
22
+ io.puts @cpio_data
23
+ io.close
24
+ raise "Cpio data was zero in size, nothing extracted." if @cpio_data.length == 0
25
+ puts [@utility, flags_run, opts].flatten.inspect if DEBUG
26
+ rescue Exception => e
27
+ puts "Tried to run #{@utility} #{@rpm_file} #{opts.inspect} during Cpio.cpio, received exception: #{e}"
28
+ end
29
+ end
30
+
31
+ def set_extract_flags
32
+ flags_extract_files
33
+ end
34
+
35
+ def flags_extract_files
36
+ flag_add("-idm")
37
+ end
38
+ end
@@ -0,0 +1,268 @@
1
+ require 'system_config'
2
+ require 'cli_funcs'
3
+ require 'cli_funcs_rpm2cpio'
4
+ require 'cli_funcs_cpio'
5
+
6
+ class Rpm < CliFuncs
7
+ attr_accessor :rpm_file, :flags_all, :extract_dir
8
+ attr_reader :control, :dependencies, :provides, :filelist, :scripts, :fpp
9
+
10
+ def initialize
11
+ super
12
+ @utility = CliUtils.new("rpm").utility_path
13
+ @packages_dir = SYSTEM_CONFIG["packages_dir"]
14
+ @default_dist = SYSTEM_CONFIG["default_dist"]
15
+ @fpp = ""
16
+ @rpm_file = ""
17
+ @extract_dir = ""
18
+ @final = Array.new
19
+ @control = Hash.new
20
+ @output_filter_control = Array.new
21
+ @dependencies = Hash.new
22
+ @provides = Hash.new
23
+ @filelist = Array.new
24
+ @scripts = Hash.new
25
+ end
26
+
27
+ def rpm
28
+ run_and_capture(cmd_run)
29
+ end
30
+
31
+ def rpm2cpio
32
+ r = Rpm2Cpio.new
33
+ r.rpm_file = @rpm_file
34
+ r.rpm2cpio
35
+ c = Cpio.new
36
+ c.cpio_data = r.output
37
+ c.extract_dir = "#{@fpp}/files"
38
+ c.cpio
39
+ end
40
+
41
+ def do_extract
42
+ prepare_package_dir
43
+ extract_package
44
+ write_info
45
+ end
46
+
47
+ def extract_package
48
+ # We have to copy the package to the files directory before we can run the rpm2cpio command
49
+ begin
50
+ FileUtils.cp(@rpm_file, "#{@fpp}/files")
51
+ rescue Exception => e
52
+ puts "Tried to copy #{@rpm_file} to #{@fpp}/files during Rpm.extract_package, received exception: #{e}"
53
+ end
54
+
55
+ # This should fill up @output with the archive content
56
+ rpm2cpio
57
+
58
+ # Move the rpm to the redhat directory for safe keeping
59
+ begin
60
+ FileUtils.mv("#{@fpp}/files/#{@rpm_file.split("/")[-1]}","#{@fpp}/redhat")
61
+ rescue Exception => e
62
+ puts "Tried to move #{@fpp}/files/#{@rpm_file.split("/")[-1]} to #{@fpp}/redhat during Rpm.extract_package, received exception: #{e}"
63
+ end
64
+
65
+ end
66
+
67
+ def write_info
68
+ write_control
69
+ write_scripts
70
+ end
71
+
72
+ def write_control
73
+ begin
74
+ f = open("#{@fpp}/redhat/info", 'w+')
75
+ @control.each_pair do |k,v|
76
+ f.puts "#{k}: #{v}"
77
+ end
78
+ f.close
79
+ rescue Exception => e
80
+ puts "Tried to open file #{@fpp}/redhat/#{k} for writing during 'Rpm.write_control', received exception: #{e}"
81
+ end
82
+ end
83
+
84
+ def write_scripts
85
+ @scripts.each_pair do |k,v|
86
+ #puts "KEY: #{k} VAL: #{v}"
87
+ f = open("#{@fpp}/redhat/#{k}", 'w+')
88
+ f.print v
89
+ f.close
90
+ end
91
+ end
92
+
93
+ def prepare_package_dir
94
+ group = @control["Group"].gsub(" ","_")
95
+ name = @control["Name"]
96
+ version = "#{@control["Version"]}-#{@control["Release"]}"
97
+ arch = @rpm_file.split(".")[-2]
98
+ @fpp = "#{@packages_dir}/#{@default_dist}/#{group}/#{name}.#{arch}/#{version}"
99
+ begin
100
+ FileUtils.mkdir_p "#{@fpp}/files"
101
+ rescue Exception => e
102
+ puts "Tried to create #{@fpp}/files during 'Rpm.prepare_package_dir', received exception: #{e}"
103
+ end
104
+ begin
105
+ FileUtils.mkdir_p "#{@fpp}/redhat"
106
+ rescue Exception => e
107
+ puts "Tried to create #{@fpp}/redhat during 'Rpm.prepare_package_dir', received exception: #{e}"
108
+ end
109
+ end
110
+
111
+ def set_info
112
+ set_control
113
+ set_dependencies
114
+ set_provides
115
+ set_filelist
116
+ set_scripts
117
+ end
118
+
119
+ def set_scripts
120
+ flags_query_package_scripts
121
+ rpm
122
+ output_process_scripts
123
+ clear_values
124
+ end
125
+
126
+ def set_provides
127
+ flags_query_package_provides
128
+ rpm
129
+ output_process_provides
130
+ clear_values
131
+ end
132
+
133
+ def set_filelist
134
+ flags_query_package_filelist
135
+ rpm
136
+ output_process_filelist
137
+ clear_values
138
+ end
139
+
140
+ def set_dependencies
141
+ flags_query_package_dependencies
142
+ rpm
143
+ output_process_dependencies
144
+ clear_values
145
+ end
146
+
147
+ def set_control
148
+ set_output_filter_control
149
+ flags_query_package_control
150
+ rpm
151
+ output_process_control
152
+ clear_values
153
+ end
154
+
155
+ def output_process_scripts
156
+ script = ""
157
+
158
+ @output.each do |line|
159
+ next if line.length == 0
160
+ if line =~ /^(\w+)\sscriptlet\s/
161
+ script = $1
162
+ puts "SCRIPT: #{script}" if DEBUG
163
+ next
164
+ end
165
+ if(@scripts[script] == nil)
166
+ @scripts[script] = line
167
+ else
168
+ @scripts[script] << line
169
+ end
170
+ end
171
+ end
172
+
173
+ def output_process_control
174
+ @output.each do |line|
175
+ @output_filter_control.each do |pattern|
176
+ if line =~ /#{pattern}/
177
+ if(($1 and $2) and ($3 and $4))
178
+ @control[$1.strip] = $2.strip
179
+ @control[$3.strip] = $4.strip
180
+ elsif($1 and $2)
181
+ @control[$1.strip] = $2.strip
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ def output_process_dependencies
189
+ @output.each do |line|
190
+ pkg,ver = line.strip.chomp.split(/\s/, 2)
191
+ if(ver == nil)
192
+ @dependencies[pkg] = nil
193
+ else
194
+ @dependencies[pkg] = ver
195
+ end
196
+ end
197
+ end
198
+
199
+ def output_process_filelist
200
+ @output.each do |line|
201
+ @filelist.push(line.chomp)
202
+ end
203
+ end
204
+
205
+ def output_process_provides
206
+ @output.each do |line|
207
+ pkg,ver = line.strip.chomp.split(" = ", 2)
208
+ if(ver == nil)
209
+ @provides[pkg] = nil
210
+ else
211
+ @provides[pkg] = ver
212
+ end
213
+ end
214
+ end
215
+
216
+ def set_output_filter_control
217
+ # Name / Relocations
218
+ @output_filter_control.push("^(Name)\s+: (.*)\s+(Relocations): (.*)$")
219
+ # Version / Vendor
220
+ @output_filter_control.push("^(Version)\s+: (.*)\s+(Vendor): (.*)$")
221
+ # Release / Build Date
222
+ @output_filter_control.push("^(Release)\s+: (.*)\s+(Build Date): (.*)$")
223
+ # Install Date / Build Host
224
+ @output_filter_control.push("^(Install Date): (.*)\s+(Build Host): (.*)$")
225
+ # Group / Source RPM
226
+ @output_filter_control.push("^(Group)\s+: (.*)\s+(Source RPM): (.*)$")
227
+ # Size / License
228
+ @output_filter_control.push("^(Size)\s+: (.*)\s+(License): (.*)$")
229
+ # Signature
230
+ @output_filter_control.push("^(Signature)\s+: (.*)$")
231
+ # Packager
232
+ @output_filter_control.push("^(Packager)\s+: (.*)$")
233
+ # URL
234
+ @output_filter_control.push("^(URL)\s+: (.*)$")
235
+ # Summary
236
+ @output_filter_control.push("^(Summary)\s+: (.*)$")
237
+ # We are not capturing 'Description' right now since there's no need
238
+ end
239
+
240
+ def cmd_run
241
+ u = CliUtils.new(@utility)
242
+ puts [u.utility_path, flags_run, @rpm_file, @final].flatten.inspect if DEBUG
243
+ [u.utility_path, flags_run, @rpm_file, @final].flatten
244
+ end
245
+
246
+ def flags_query_package_control
247
+ flag_add("-qpi")
248
+ end
249
+
250
+ def flags_query_package_dependencies
251
+ flag_add("-qpR")
252
+ end
253
+
254
+ def flags_query_package_provides
255
+ flag_add("-qp")
256
+ flag_add("--provides")
257
+ end
258
+
259
+ def flags_query_package_filelist
260
+ flag_add("-qp")
261
+ flag_add("--list")
262
+ end
263
+
264
+ def flags_query_package_scripts
265
+ flag_add("-qp")
266
+ flag_add("--scripts")
267
+ end
268
+ end
@@ -0,0 +1,28 @@
1
+ require 'system_config'
2
+ require 'cli_funcs'
3
+
4
+ class Rpm2Cpio < CliFuncs
5
+ attr_accessor :rpm_file, :flags_all
6
+ attr_reader :output
7
+
8
+ def initialize
9
+ super
10
+ @output = ""
11
+ @utility = CliUtils.new("rpm2cpio").utility_path
12
+ @packages_dir = SYSTEM_CONFIG["packages_dir"]
13
+ @default_dist = SYSTEM_CONFIG["default_dist"]
14
+ @rpm_file = ""
15
+ end
16
+
17
+ def rpm2cpio
18
+ # This should turn capture3 into binary mode just by being set
19
+ opts = Hash.new
20
+ # Run our command and capture the binary output into @output
21
+ begin
22
+ @output, stderr_str, status = Open3.capture3(@utility, @rpm_file, opts)
23
+ puts [@utility, @rpm_file, opts].flatten.inspect if DEBUG
24
+ rescue Exception => e
25
+ puts "Tried to run #{@utility} #{@rpm_file} #{opts.inspect} during Rpm2Cpio.rpm2cpio, received exception: #{e}"
26
+ end
27
+ end
28
+ end