litbuild 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cc983f70c85f96dd03544d804f4c5971a55d401799209fbbfccdab244de6c28
4
- data.tar.gz: 0e0dd20d35dd4565daff7ced67a1cf5e17a0394739a313042350c61e52ee4250
3
+ metadata.gz: 79441e2b11890ec0e9a3271224f80ed9ca7c40f548fc3ee59bf774a55d3ff54f
4
+ data.tar.gz: 77ab5c060afb201d5a0014e92bd8e2ad1352efc8dbc0d37d864992d159a53be9
5
5
  SHA512:
6
- metadata.gz: 16a83a065cd551c5a0e5adb179305097a663bdf09c5c436245206232897a4f754c922faf42df656f81e2a083a5c9c8182689602644d6c69a8999bfc7d7791909
7
- data.tar.gz: 2b5f178c9c2343bd5a05e9874ca8e4076a21ec3a0acd7964f85e3cab5419c37b8c4f9306b8aafe7b2658e9170097afd6a113fe4ea80eae6928b1b223e63c92c6
6
+ metadata.gz: 5f0a0bb98c15066ad8f945a1717ccbfdaa59bb7ac60caa8975459cf62a2601367dab0d68e3e7722999726de22f3d1acbac92a957972574184b430a8ee1d8dbef
7
+ data.tar.gz: a366a4a6c91629107a7f9d3868273b8bce8baf26670dc22b4d1edb53d5c31dcbd8fc1e9c2835561f96d576c6cc5a113d6cd261663a12edff7e285085b8d07d0e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README CHANGED
@@ -112,6 +112,16 @@ comprehensible, or when all the parts of a build need to share a common
112
112
  configuration or environment -- which is the case for most complicated
113
113
  processes.
114
114
 
115
+ If any commands in the generated scripts appear to be run under `sudo`,
116
+ litbuild has a feature that can help to run those scripts
117
+ non-interactively: it will produce sudoers entries (which can be
118
+ included in `/etc/sudoers` or in a file in `/etc/sudoers.d`) that permit
119
+ exactly those commands to be run under sudo without a password. For this
120
+ feature to work, all programs run under `sudo` must either be specified
121
+ with a full absolute path, or must exist in a specific set of default
122
+ directories: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, and
123
+ /usr/local/sbin.
124
+
115
125
  Debugging Blueprints
116
126
  ====================
117
127
 
@@ -128,7 +128,7 @@ module Litbuild
128
128
  FileUtils.chmod('ugo+x', script_path)
129
129
  envcmds = environment_commands(blueprint).reject { |c| c =~ /^mkdir/ }
130
130
  unless envcmds.empty?
131
- envscript = File.join(location, "#{blueprint.file_name}_env.sh")
131
+ envscript = File.join(location, "env_#{blueprint.file_name}.sh")
132
132
  File.open(envscript, 'w') do |f|
133
133
  envcmds.each { |cmd| f.puts(cmd) }
134
134
  end
@@ -186,22 +186,40 @@ module Litbuild
186
186
  end
187
187
  end
188
188
 
189
- def sudoers_entries
189
+ def running_as_root
190
190
  uid = `id -u`.strip
191
- return [] if uid == '0'
191
+ uid == '0'
192
+ end
193
+
194
+ SUDOPATH = %w[/bin /sbin
195
+ /usr/bin /usr/sbin
196
+ /usr/local/bin /usr/local/sbin].freeze
197
+
198
+ def convert_to_absolute(command)
199
+ return command if command.start_with?('/')
200
+
201
+ cmd_tokens = command.split
202
+ program = cmd_tokens.shift
203
+ possible_paths = SUDOPATH.map { |dir| File.join(dir, program) }
204
+ fullpath = possible_paths.detect { |path| File.exist?(path) }
205
+ unless fullpath
206
+ msg = "Program #{program}, run via sudo, cannot be found in " \
207
+ 'any of the standard directories.'
208
+ raise(SudoProgramNotFound, msg)
209
+ end
210
+ ([fullpath] + cmd_tokens).join(' ')
211
+ end
212
+
213
+ def sudoers_entries
214
+ return [] if running_as_root
192
215
 
193
216
  raw_sudo_cmds = @all_commands.select do |c|
194
217
  c =~ /sudo / && c.lines.size < 2
195
218
  end.uniq
196
219
  sudo_cmds = raw_sudo_cmds.map do |c|
197
- command = c.sub(/.*sudo /, '')
198
- unless command.start_with?('/')
199
- base_command = command.sub(/ .*$/, '')
200
- raise(RelativeSudo,
201
- "Need absolute path for \"#{base_command}\" in \"#{c}\"")
202
- end
203
220
  sudoed_cmd = c.sub(/^.*sudo (.*)$/, '\\1')
204
221
  sudoed_cmd = sudoed_cmd.sub(/;.*$/, '') if sudoed_cmd.match?(/;/)
222
+ sudoed_cmd = convert_to_absolute(sudoed_cmd)
205
223
  sudoed_cmd.gsub(/([,:=\\])/, '\\\\\1')
206
224
  end
207
225
  username = `id -un`.strip
@@ -408,12 +426,13 @@ module Litbuild
408
426
  end
409
427
 
410
428
  def render_command(script, command, log)
411
- @all_commands << command
412
- if command.match?(/>/)
429
+ unfolded_command = command.gsub(/ ?\\\n */, ' ')
430
+ @all_commands << unfolded_command
431
+ if unfolded_command.match?(/>/)
413
432
  # redirecting output of command, can't put stdout in log.
414
- script.puts(command)
433
+ script.puts(unfolded_command)
415
434
  else
416
- script.puts("#{command} >> #{log} 2>&1")
435
+ script.puts("#{unfolded_command} >> #{log} 2>&1")
417
436
  end
418
437
  end
419
438
 
@@ -30,10 +30,11 @@ module Litbuild
30
30
  # More than one blueprint exists with some name.
31
31
  class DuplicateBlueprint < Error; end
32
32
 
33
- # A command executed through sudo does not have an absolute path.
34
- class RelativeSudo < Error; end
35
-
36
33
  # A blueprints directive specifies a blueprint that has already been
37
34
  # included elsewhere.
38
35
  class UnrenderedComponent < Error; end
36
+
37
+ # A command run under `sudo` without specified path cannot be found in
38
+ # any of the standard directories.
39
+ class SudoProgramNotFound < Error; end
39
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Litbuild
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litbuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Neumeier
@@ -34,7 +34,7 @@ cert_chain:
34
34
  PvrrfEkjwo+u4dPBTaO5ZBa4qsFE5bK/1l6d4AVV5Yi5NohUwmpp1bFFCGPqvzVA
35
35
  bhee2x0YS1uGTnADpv2GLkmNMIA=
36
36
  -----END CERTIFICATE-----
37
- date: 2019-09-05 00:00:00.000000000 Z
37
+ date: 2019-09-14 00:00:00.000000000 Z
38
38
  dependencies: []
39
39
  description: A build system based on Knuth's idea of literate programming.
40
40
  email:
metadata.gz.sig CHANGED
Binary file