nub 0.0.76 → 0.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nub/fileutils.rb +10 -24
- data/lib/nub/pacman.rb +60 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3efbedee8e45692f1b9cf2039541b2196ad9d9e511916964bae27f1777c9a796
|
4
|
+
data.tar.gz: 7928aabd0d289dd414473f7aa18c2c50e2b3f9626efb557dc801a2bdef5468a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b768e4e55ac03d9619cbcf64c5429e045c3dc9e8975825b8aaf3352843ac2effa06a6d0866ee7c8157e60ec0b29aa594358145b623b07c308fbdedda57a9a085
|
7
|
+
data.tar.gz: 89fb4422d0d78aa692a096401468508ebdbf3abd611ebff5fdfc3c6cc504bf046cfc4ed69ec703af6aba503b34203e01ef75ac87d463b64f5f28d32cee697923
|
data/lib/nub/fileutils.rb
CHANGED
@@ -119,38 +119,24 @@ module FileUtils
|
|
119
119
|
def self.insert(file, values, regex:nil, offset:1)
|
120
120
|
return false if not values or values.empty?
|
121
121
|
|
122
|
-
changed = false
|
123
122
|
values = [values] if values.is_a?(String)
|
124
123
|
FileUtils.touch(file) if not File.exist?(file)
|
125
124
|
|
126
|
-
|
127
|
-
|
128
|
-
File.open(file, 'r+') do |f|
|
129
|
-
data = f.read
|
130
|
-
lines = data.split("\n")
|
125
|
+
changed = self.update(file){|data|
|
126
|
+
lines = data.split("\n")
|
131
127
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
return false if not i
|
128
|
+
# Match regex for insert location
|
129
|
+
regex = Regexp.new(regex) if regex.is_a?(String)
|
130
|
+
if i = regex ? lines.index{|x| x =~ regex} : lines.size
|
136
131
|
i += offset if regex and offset
|
137
132
|
|
138
133
|
# Insert at offset
|
139
|
-
values.each{|x|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
# Truncate then write out new content
|
145
|
-
f.seek(0)
|
146
|
-
f.truncate(0)
|
147
|
-
f.puts(lines)
|
134
|
+
values.each{|x| lines.insert(i, x) and i += 1}
|
135
|
+
|
136
|
+
# Change data inline
|
137
|
+
data.gsub!(data, lines * "\n")
|
148
138
|
end
|
149
|
-
|
150
|
-
# Revert back to the original incase of failure
|
151
|
-
File.open(file, 'w'){|f| f << data} if data
|
152
|
-
raise
|
153
|
-
end
|
139
|
+
}
|
154
140
|
|
155
141
|
return changed
|
156
142
|
end
|
data/lib/nub/pacman.rb
CHANGED
@@ -23,71 +23,93 @@ require 'fileutils'
|
|
23
23
|
require_relative 'log'
|
24
24
|
require_relative 'sys'
|
25
25
|
require_relative 'module'
|
26
|
+
require_relative 'fileutils'
|
26
27
|
|
27
28
|
# Wrapper around system Arch Linux pacman
|
28
29
|
module Pacman
|
29
30
|
extend self
|
30
|
-
mattr_accessor(:path, :config, :sysroot)
|
31
|
+
mattr_accessor(:path, :config, :sysroot, :mirrors, :repos, :arch, :env)
|
31
32
|
|
32
33
|
# Configure pacman for the given root
|
33
34
|
# @param path [String] path where all pacman artifacts will be (i.e. logs, cache etc...)
|
34
35
|
# @param config [String] config file path to use, note gets copied in
|
36
|
+
# @param mirrors [Array] of mirror paths to use, mirror file name is expected to be the
|
37
|
+
# name of the repo e.g. archlinux.mirrorlist
|
38
|
+
# @param arch [String] capturing the pacman target architecture e.g. x86_64
|
35
39
|
# @param sysroot [String] path to the system root to use
|
36
|
-
|
40
|
+
# @param env [Hash] of environment variables to set for session
|
41
|
+
def init(path, config, mirrors, arch:'x86_64', sysroot:nil, env:nil)
|
42
|
+
mirrors = [mirrors] if mirrors.is_a?(String)
|
37
43
|
self.path = path
|
44
|
+
self.arch = arch
|
38
45
|
self.sysroot = sysroot
|
39
46
|
self.config = File.join(path, File.basename(config))
|
47
|
+
self.repos = mirrors.map{|x| File.basename(x, '.mirrorlist')}
|
48
|
+
self.mirrors = mirrors.map{|x| File.join(path, File.basename(x))}
|
40
49
|
|
41
50
|
# Validate incoming params
|
42
|
-
Log.die("pacman
|
43
|
-
Log.die("pacman sysroot '#{sysroot}' doesn't exist") unless Dir.exist?(sysroot)
|
44
|
-
Log.die("pacman config file '#{config}' doesn't exist") unless File.exist?(config)
|
51
|
+
Log.die("pacman config '#{config}' doesn't exist") unless File.exist?(config)
|
45
52
|
|
46
|
-
#
|
53
|
+
# Copy in pacman files for use in target
|
47
54
|
FileUtils.rm_rf(File.join(path, '.'))
|
55
|
+
FileUtils.mkdir_p(File.join(self.path, 'db'))
|
56
|
+
FileUtils.mkdir_p(self.sysroot) if self.sysroot && !Dir.exist?(self.sysroot)
|
48
57
|
FileUtils.cp(config, path, preserve: true)
|
49
|
-
|
50
|
-
Sys.exec("cp -a #{@pacman_src_mirrors} #{@pacman_path}")
|
51
|
-
Fedit.replace(@pacman_conf, /(Architecture = ).*/, "\\1#{@vars.arch}")
|
52
|
-
# Leave DBPath set as /var/lib/pacman and copy out sync
|
53
|
-
Fedit.replace(@pacman_conf, /#(CacheDir\s+= ).*/, "\\1#{File.join(@pacman_path, 'cache')}")
|
54
|
-
Fedit.replace(@pacman_conf, /#(LogFile\s+= ).*/, "\\1#{File.join(@pacman_path, 'pacman.log')}")
|
55
|
-
Fedit.replace(@pacman_conf, /#(GPGDir\s+= ).*/, "\\1#{File.join(@pacman_path, 'gnupg')}")
|
56
|
-
Fedit.replace(@pacman_conf, /#(HookDir\s+= ).*/, "\\1#{File.join(@pacman_path, 'hooks')}")
|
57
|
-
Fedit.replace(@pacman_conf, /.*(\/.*mirrorlist).*/, "Include = #{@pacman_path}\\1")
|
58
|
+
FileUtils.cp(mirrors, path, preserve: true)
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
# Update the given pacman config file to use the given path
|
61
|
+
FileUtils.replace(self.config, /(Architecture = ).*/, "\\1#{self.arch}")
|
62
|
+
FileUtils.replace(self.config, /#(DBPath\s+= ).*/, "\\1#{File.join(self.path, 'db')}")
|
63
|
+
FileUtils.replace(self.config, /#(CacheDir\s+= ).*/, "\\1#{File.join(self.path, 'cache')}")
|
64
|
+
FileUtils.replace(self.config, /#(LogFile\s+= ).*/, "\\1#{File.join(self.path, 'pacman.log')}")
|
65
|
+
FileUtils.replace(self.config, /#(GPGDir\s+= ).*/, "\\1#{File.join(self.path, 'gnupg')}")
|
66
|
+
FileUtils.replace(self.config, /#(HookDir\s+= ).*/, "\\1#{File.join(self.path, 'hooks')}")
|
67
|
+
FileUtils.replace(self.config, /.*(\/.*mirrorlist).*/, "Include = #{self.path}\\1")
|
62
68
|
|
63
69
|
# Initialize pacman keyring
|
64
|
-
|
65
|
-
|
70
|
+
Sys.exec("pacman-key --config #{self.config} --init")
|
71
|
+
Sys.exec("pacman-key --config #{self.config} --populate #{repos * ' '}")
|
66
72
|
end
|
67
73
|
|
68
74
|
# Update the pacman database
|
69
75
|
def update
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
cmd = "pacman -Sy"
|
74
|
-
cmd += " --sysroot #{self.sysroot}" if self.sysroot
|
75
|
-
Sys.exec(cmd)
|
76
|
-
success = true
|
77
|
-
rescue Exception => e
|
78
|
-
puts(e.message)
|
79
|
-
end
|
80
|
-
end
|
76
|
+
cmd = "pacman -Sy"
|
77
|
+
cmd += " --config #{self.config}" if self.config
|
78
|
+
Sys.exec(cmd)
|
81
79
|
end
|
82
80
|
|
83
81
|
# Install the given packages
|
84
|
-
# @param pkgs [Array]
|
85
|
-
|
86
|
-
|
87
|
-
cmd = [
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
# @param pkgs [Array] of packages to install
|
83
|
+
# @param ignore [Array] of packages to ignore
|
84
|
+
def install(pkgs, ignore:nil)
|
85
|
+
cmd = []
|
86
|
+
|
87
|
+
if self.sysroot
|
88
|
+
cmd += ["pacstrap", "-GMc", self.sysroot, '--config', self.config]
|
89
|
+
else
|
90
|
+
cmd += ["pacman", "-S"]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Ignore any packages called out
|
94
|
+
ignore = [ignore] if ignore.is_a?(String)
|
95
|
+
cmd += ["--ignore", "#{ignore * ','}"] if ignore && ignore.any?
|
96
|
+
|
97
|
+
# Add packages to install
|
98
|
+
cmd += ['--needed', *pkgs]
|
99
|
+
|
100
|
+
# Execute if there are any packages given
|
101
|
+
if pkgs.any?
|
102
|
+
self.env ? Sys.exec(cmd, env:self.env) : Sys.exec(cmd)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Remove the given conflicting packages
|
107
|
+
# @param pkgs [Array] of packages to remove
|
108
|
+
def remove_conflict(pkgs)
|
109
|
+
cmd = "pacman -Rn"
|
110
|
+
cmd += " -r #{self.sysroot}" if self.sysroot
|
111
|
+
cmd += " -d -d --noconfirm #{pkgs * ' '} &>/dev/null || true"
|
112
|
+
Sys.exec(cmd)
|
91
113
|
end
|
92
114
|
end
|
93
115
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.81
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Crummett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|