File tree 2 files changed +76
-0
lines changed
2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "libexec"
4
+ require_relative "../manifest"
5
+
6
+ module RootFS
7
+ module Package
8
+ module Rpm
9
+ extend RootFS ::Manifest
10
+ include RootFS ::Manifest
11
+
12
+ # rubocop:disable Style/FormatStringToken
13
+
14
+ # https://docs.fedoraproject.org/en-US/fedora/latest/system-administrators-guide/RPM/
15
+ def installed
16
+ list = [ ]
17
+ Libexec . each_line ( "rpm -qa --qf '%{name}\n '" ) do |line |
18
+ list . push ( line . chomp )
19
+ end
20
+ list
21
+ end
22
+
23
+ def installed_by_user
24
+ list = [ ]
25
+ Libexec . each_line ( "dnf repoquery --userinstalled" ) do |line |
26
+ pkg = line . chomp . split ( ":" ) [ 0 ] . split ( "-" ) [ 0 ..-2 ] . join ( "-" )
27
+ list . push ( pkg )
28
+ end
29
+ list
30
+ end
31
+
32
+ def generate_manifest ( file = nil )
33
+ if file
34
+ Libexec . run ( "rpm -qa --qf '%{name}\t %{version}\n ' | sort > #{ file } " )
35
+ else
36
+ Libexec . run ( "rpm -qa --qf '%{name}\t %{version}\n ' | sort" )
37
+ end
38
+ end
39
+
40
+ def can_install ( any )
41
+ pkgs = any . instance_of? ( Array ) ? any : manifest_package ( any )
42
+
43
+ ignores = [ ]
44
+ Libexec . each_line ( "yum install #{ pkgs . join ( " " ) } " ) do |line |
45
+ puts line
46
+ err_pre = "No match for argument: "
47
+ if line . include? ( err_pre )
48
+ pkg = line . chomp . delete_prefix ( err_pre )
49
+ ignores . push ( pkg )
50
+ end
51
+ end
52
+ return pkgs if ignores . empty?
53
+
54
+ pkgs -= ignores
55
+ can_install ( pkgs )
56
+ end
57
+ end
58
+ end
59
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rpm"
4
+
5
+ class MyClass
6
+ extend RootFS ::Package ::Rpm
7
+ include RootFS ::Package ::Rpm
8
+ end
9
+
10
+ u = MyClass . new
11
+
12
+ # pp u.installed
13
+ # u.generate_manifest
14
+ # u.generate_manifest(".rspec_status")
15
+ # puts u.installed_by_user
16
+
17
+ puts u . can_install ( ".rspec_status" )
You can’t perform that action at this time.
0 commit comments