slack-utils 0.6.2 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -20
- data/bin/slf +23 -11
- data/bin/slfindlinked +1 -1
- data/bin/sli +22 -10
- data/bin/sll +22 -9
- data/bin/slo +17 -5
- data/bin/slp +22 -10
- data/bin/slt +21 -11
- data/examples/before_then.rb +1 -0
- data/examples/list_packages.rb +4 -3
- data/examples/repo.rb +1 -0
- data/examples/repo_difference.rb +1 -0
- data/lib/slackware/args.rb +80 -73
- data/lib/slackware/changelog/rss.rb +3 -0
- data/lib/slackware/changelog.rb +15 -12
- data/lib/slackware/log.rb +53 -0
- data/lib/slackware/package.rb +232 -203
- data/lib/slackware/package_bundle.rb +43 -40
- data/lib/slackware/paths.rb +57 -0
- data/lib/slackware/repo.rb +134 -129
- data/lib/slackware/system.rb +179 -153
- data/lib/slackware/utils.rb +247 -244
- data/lib/slackware/version.rb +12 -9
- data/lib/slackware.rb +24 -0
- metadata +5 -3
data/lib/slackware/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
# Copyright 2010,2011 Vincent Batts, Vienna, VA
|
2
4
|
# All rights reserved.
|
3
5
|
#
|
@@ -18,7 +20,7 @@
|
|
18
20
|
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
19
21
|
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20
22
|
|
21
|
-
# started - Fri Oct
|
23
|
+
# started - Fri Oct 9 15:48:43 CDT 2009
|
22
24
|
# updated for args - Tue Mar 23 14:54:19 CDT 2010
|
23
25
|
# Copyright 2009, 2010 Vincent Batts, http://hashbangbash.com/
|
24
26
|
|
@@ -35,224 +37,224 @@ require 'slackware'
|
|
35
37
|
|
36
38
|
# This is base builder of the packe list
|
37
39
|
def build_packages(opts = {}, args = [])
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
40
|
+
pkgs = Slackware::System.installed_packages
|
41
|
+
|
42
|
+
# separated this little thing out, since it adds a little more time
|
43
|
+
if (opts[:time])
|
44
|
+
pkgs = pkgs.each {|p| p.get_time }
|
45
|
+
end
|
46
|
+
|
47
|
+
if (opts[:all])
|
48
|
+
if (args.count > 0)
|
49
|
+
args.each {|arg|
|
50
|
+
# about 0.012s performance improvement,
|
51
|
+
# by compiling it here, instead of inside the iteration.
|
52
|
+
if (opts[:case_insensitive])
|
53
|
+
re = /#{arg}/i
|
54
|
+
else
|
55
|
+
re = /#{arg}/
|
56
|
+
end
|
57
|
+
|
58
|
+
pkgs = pkgs.find_all {|pkg| pkg.fullname =~ re }
|
59
|
+
}
|
60
|
+
end
|
61
|
+
re = nil
|
62
|
+
end
|
63
|
+
if (opts[:pkg])
|
64
|
+
if (opts[:case_insensitive])
|
65
|
+
re = /#{opts[:pkg]}/i
|
66
|
+
else
|
67
|
+
re = /#{opts[:pkg]}/
|
68
|
+
end
|
69
|
+
pkgs = pkgs.map {|p|
|
70
|
+
if p.name =~ re
|
71
|
+
if (opts[:color])
|
72
|
+
p.name = p.name.gsub(re, "#{@st}\\&#{@en}")
|
73
|
+
end
|
74
|
+
p
|
75
|
+
end
|
76
|
+
}.compact
|
77
|
+
re = nil
|
78
|
+
end
|
79
|
+
if (opts[:Version])
|
80
|
+
if (opts[:case_insensitive])
|
81
|
+
re = Regexp.new(Regexp.escape(opts[:Version]), Regexp::IGNORECASE)
|
82
|
+
else
|
83
|
+
re = Regexp.new(Regexp.escape(opts[:Version]))
|
84
|
+
end
|
85
|
+
pkgs = pkgs.map {|p|
|
86
|
+
if p.version =~ re
|
87
|
+
if (opts[:color])
|
88
|
+
p.version = p.version.gsub(re, "#{@st}\\&#{@en}")
|
89
|
+
end
|
90
|
+
p
|
91
|
+
end
|
92
|
+
}.compact
|
93
|
+
re = nil
|
94
|
+
end
|
95
|
+
if (opts[:arch])
|
96
|
+
if (opts[:case_insensitive])
|
97
|
+
re = /#{opts[:arch]}/i
|
98
|
+
else
|
99
|
+
re = /#{opts[:arch]}/
|
100
|
+
end
|
101
|
+
pkgs = pkgs.map {|p|
|
102
|
+
if p.arch =~ re
|
103
|
+
if (opts[:color])
|
104
|
+
p.arch = p.arch.gsub(re, "#{@st}\\&#{@en}")
|
105
|
+
end
|
106
|
+
p
|
107
|
+
end
|
108
|
+
}.compact
|
109
|
+
re = nil
|
110
|
+
end
|
111
|
+
if (opts[:build])
|
112
|
+
if (opts[:case_insensitive])
|
113
|
+
re = /#{opts[:build]}/i
|
114
|
+
else
|
115
|
+
re = /#{opts[:build]}/
|
116
|
+
end
|
117
|
+
pkgs = pkgs.map {|p|
|
118
|
+
if p.build =~ re
|
119
|
+
if (opts[:color])
|
120
|
+
p.build = p.build.gsub(re, "#{@st}\\&#{@en}")
|
121
|
+
end
|
122
|
+
p
|
123
|
+
end
|
124
|
+
}.compact
|
125
|
+
re = nil
|
126
|
+
end
|
127
|
+
if (opts[:tag])
|
128
|
+
if (opts[:case_insensitive])
|
129
|
+
re = /#{opts[:tag]}/i
|
130
|
+
else
|
131
|
+
re = /#{opts[:tag]}/
|
132
|
+
end
|
133
|
+
pkgs = pkgs.map {|p|
|
134
|
+
if p.tag =~ re
|
135
|
+
if (opts[:color])
|
136
|
+
p.tag = p.tag.gsub(re, "#{@st}\\&#{@en}")
|
137
|
+
end
|
138
|
+
p
|
139
|
+
end
|
140
|
+
}.compact
|
141
|
+
re = nil
|
142
|
+
end
|
143
|
+
|
144
|
+
return pkgs
|
143
145
|
end
|
144
146
|
|
145
147
|
def print_packages(pkgs)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
if (pkgs.count > 0 && pkgs.first.class == Slackware::Package)
|
149
|
+
pkgs.each {|pkg|
|
150
|
+
printf("%s\n", pkg.fullname )
|
151
|
+
}
|
152
|
+
end
|
151
153
|
end
|
152
154
|
|
153
155
|
def print_packages_times(pkgs, epoch = false)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
156
|
+
if (epoch == true)
|
157
|
+
pkgs.each {|pkg| printf("%s : %s\n", pkg.fullname, pkg.time.to_i) }
|
158
|
+
else
|
159
|
+
pkgs.each {|pkg| printf("%s : %s\n", pkg.fullname, pkg.time.to_s) }
|
160
|
+
end
|
159
161
|
end
|
160
162
|
|
161
163
|
def print_packages_description(pkgs)
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
164
|
+
if (pkgs.count > 0 && pkgs.first.class == Slackware::Package)
|
165
|
+
pkgs.each {|pkg|
|
166
|
+
printf("%s: COMPRESSED SIZE: %s\n", pkg.fullname, pkg.compressed_size )
|
167
|
+
printf("%s: UNCOMPRESSED SIZE: %s\n", pkg.fullname, pkg.uncompressed_size )
|
168
|
+
pkg.package_description.each {|line|
|
169
|
+
printf("%s: %s\n", pkg.fullname, line )
|
170
|
+
}
|
171
|
+
}
|
172
|
+
end
|
171
173
|
end
|
172
174
|
|
173
175
|
# package file listing
|
174
176
|
def print_package_file_list(pkgs)
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
177
|
+
if (pkgs.count > 1)
|
178
|
+
pkgs.each {|pkg|
|
179
|
+
pkg.get_owned_files.each {|line|
|
180
|
+
puts pkg.name + ": " + line
|
181
|
+
}
|
182
|
+
}
|
183
|
+
else
|
184
|
+
pkgs.each {|pkg| puts pkg.get_owned_files }
|
185
|
+
end
|
184
186
|
end
|
185
187
|
|
186
188
|
# search Array of Slackware::Package's for files
|
187
189
|
# and print the items found
|
188
190
|
def print_package_searched_files(pkgs, files)
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
191
|
+
found_files = []
|
192
|
+
files.each {|file|
|
193
|
+
found_files += Slackware::System.owns_file(file)
|
194
|
+
}
|
195
|
+
found_files.each {|file|
|
196
|
+
puts file[0].fullname + ": " + file[1]
|
197
|
+
}
|
196
198
|
end
|
197
199
|
|
198
200
|
# find orpaned files from /etc/
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
201
|
+
# * build a list of files from removed_packages
|
202
|
+
# * check the list to see if they are currently owned by a package
|
203
|
+
# * check the unowned members, to see if they still exist on the filesystem
|
204
|
+
# * return existing files
|
203
205
|
def find_orphaned_config_files
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
206
|
+
# build a list of config files currently installed
|
207
|
+
installed_config_files = Slackware::System.installed_packages.map {|pkg|
|
208
|
+
pkg.get_owned_files.map {|file|
|
209
|
+
if not(file =~ /\/$/)
|
210
|
+
if (file =~ /^etc\//)
|
211
|
+
file
|
212
|
+
end
|
213
|
+
end
|
214
|
+
}
|
215
|
+
}.flatten.compact
|
216
|
+
|
217
|
+
# this Array is where we'll stash removed packages that have config file to check
|
218
|
+
pkgs = Array.new
|
219
|
+
Slackware::System.removed_packages.each {|r_pkg|
|
220
|
+
# find config files for this removed package
|
221
|
+
config = r_pkg.get_owned_files.grep(/^etc\/.*[\w|\d]$/)
|
222
|
+
# continue if there are none
|
223
|
+
if (config.count > 0)
|
224
|
+
# remove config files that are owned by a currently installed package
|
225
|
+
config = config.map {|file|
|
226
|
+
if not(installed_config_files.include?(file))
|
227
|
+
if not(installed_config_files.include?(file + ".new"))
|
228
|
+
file
|
229
|
+
end
|
230
|
+
end
|
231
|
+
}.compact
|
232
|
+
# check again, and continue if there are no config files left
|
233
|
+
if (config.count > 0)
|
234
|
+
# otherwise add this package, and its files, to the stack
|
235
|
+
pkgs << {:pkg => r_pkg, :files => config}
|
236
|
+
end
|
237
|
+
end
|
238
|
+
}
|
239
|
+
|
240
|
+
# setup list of files to check whether they still exist on the filesystem
|
241
|
+
files = []
|
242
|
+
pkgs.map {|pkg| files << pkg[:files] }
|
243
|
+
files.flatten!.uniq!
|
244
|
+
|
245
|
+
orphaned_config_files = []
|
246
|
+
files.each {|file|
|
247
|
+
if (File.exist?("/" + file))
|
248
|
+
orphaned_config_files << file
|
249
|
+
end
|
250
|
+
}
|
251
|
+
|
252
|
+
return orphaned_config_files
|
251
253
|
|
252
254
|
end
|
253
255
|
|
254
256
|
def print_orphaned_files(files)
|
255
|
-
|
257
|
+
puts files
|
256
258
|
end
|
257
259
|
|
258
260
|
# XXX This is a work in progress
|
@@ -264,69 +266,70 @@ end
|
|
264
266
|
# That way, those entries alone could be updated if they are newer,
|
265
267
|
# otherwise it's just a query.
|
266
268
|
def find_linked(file_to_find)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
269
|
+
require 'find'
|
270
|
+
|
271
|
+
dirs = %w{ /lib /lib64 /usr/lib /usr/lib64 /bin /sbin /usr/bin /usr/sbin }
|
272
|
+
re_so = /ELF.*shared object/
|
273
|
+
re_exec = /ELF.*executable/
|
274
|
+
|
275
|
+
if File.exist?(file_to_find)
|
276
|
+
file_to_find = File.expand_path(file_to_find)
|
277
|
+
end
|
278
|
+
if not(filemagic(File.dirname(file_to_find) + "/" + File.readlink(file_to_find)) =~ re_so)
|
279
|
+
printf("%s is not a shared object\n",file_to_find)
|
280
|
+
return nil
|
281
|
+
end
|
282
|
+
|
283
|
+
includes_linked = []
|
284
|
+
printf("Searching through ... ")
|
285
|
+
dirs.each {|dir|
|
286
|
+
printf("%s ", dir)
|
287
|
+
Find.find(dir) {|file|
|
288
|
+
if File.directory?(file)
|
289
|
+
next
|
290
|
+
end
|
291
|
+
file_magic = filemagic(file)
|
292
|
+
if (file_magic =~ re_so || file_magic =~ re_exec)
|
293
|
+
l = `/usr/bin/ldd #{file} 2>/dev/null `
|
294
|
+
if l.include?(file_to_find)
|
295
|
+
printf(".")
|
296
|
+
l = l.sub(/\t/, '').split(/\n/)
|
297
|
+
includes_linked << {:file => file, :links => l}
|
298
|
+
end
|
299
|
+
end
|
300
|
+
}
|
301
|
+
}
|
302
|
+
printf("\n")
|
303
|
+
return includes_linked
|
302
304
|
end
|
303
305
|
|
304
306
|
# This is intended to take the return of the find_linked() method
|
305
307
|
def packages_of_linked_files(linked_files_arr)
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
308
|
+
pkgs = Slackware::System.installed_packages
|
309
|
+
owned_pkgs = []
|
310
|
+
pkgs.map {|pkg|
|
311
|
+
files.each {|file|
|
312
|
+
if pkg.owned_files.include?(file)
|
313
|
+
owned_pkgs << {:pkg => pkg, :file => file}
|
314
|
+
end
|
315
|
+
}
|
316
|
+
}
|
317
|
+
return owned_pkgs
|
316
318
|
end
|
317
319
|
|
318
320
|
# Pretty print the output of find_linked()
|
319
321
|
def print_find_linked(file_to_find)
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
322
|
+
files = find_linked(file_to_find)
|
323
|
+
printf("files linked to '%s' include:\n", file_to_find)
|
324
|
+
files.each {|file|
|
325
|
+
printf(" %s\n", file)
|
326
|
+
}
|
325
327
|
end
|
326
328
|
|
327
329
|
private
|
328
330
|
|
329
331
|
def filemagic(file)
|
330
|
-
|
332
|
+
return `/usr/bin/file "#{file}"`.chomp
|
331
333
|
end
|
332
334
|
|
335
|
+
# vim:sw=2:sts=2:et:
|