lxdev 0.1.2 → 0.1.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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/lxdev/main.rb +23 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0b31393a23f8385606e4eac0f3bce19b0d9c8d24
4
- data.tar.gz: 36d736278c01df9698f937504d759ae0c8605773
2
+ SHA256:
3
+ metadata.gz: bd005fcf499291c992c0176018a0feac0e2fca7bc8a130801d2089a92dabc313
4
+ data.tar.gz: fb3a2b1facc6caedd1928dd03f0c6cd710a99bfdc30355721978d9146e9616bb
5
5
  SHA512:
6
- metadata.gz: e36ccf0712ada1a0c1ac016405607d60ed1c8674a20425b4513a0ea07f46c46673531d51aeb5b2b5885f469fbb09ab2610795c37cf68b83d79820823aeeb176a
7
- data.tar.gz: d364c34c12388a837b5700f8e6eb7f3947ffb714a0d6b1021114b08b33220078ce61d1aabf45565a42a0f41ad4f7caecd0b3c00da14e9891e4f99c1003d840e6
6
+ metadata.gz: 67cd321fc6066831e289c92887566034a452c8128d36be956c5f7021ebf618ab31d66abb9ef62ae02f745b64519fce38c069a00bed4791e00de9e9cd22183f87
7
+ data.tar.gz: 66be27cb60e0d0442b73c5be27d128aa8222614b62b53f1d2f300ed60978aa27b3ad439a9b9b6434946ae0cc4d169eea39333283c5e4107f69bcc87c1ebb8f11
data/lib/lxdev/main.rb CHANGED
@@ -8,7 +8,7 @@ module LxDev
8
8
  WHITELISTED_SUDO_COMMANDS = ["lxc", "redir", "kill"]
9
9
  SHELLS = ["bash", "zsh", "sh", "csh", "tcsh", "ash"]
10
10
  BOOT_TIMEOUT = 30
11
- VERSION = '0.1.2'
11
+ VERSION = '0.1.3'
12
12
 
13
13
  def initialize
14
14
  @uid = System.exec("id -u").output.chomp
@@ -30,6 +30,7 @@ module LxDev
30
30
  end
31
31
 
32
32
  def self.setup
33
+ self.check_requirements
33
34
  unless lxd_initialized?
34
35
  puts "Please run 'lxd init' and configure LXD first"
35
36
  return false
@@ -339,8 +340,25 @@ module LxDev
339
340
  end
340
341
  end
341
342
 
343
+ def self.check_requirements
344
+ WHITELISTED_SUDO_COMMANDS.each do |cmd|
345
+ unless System.exec("which #{cmd}").exitstatus == 0
346
+ puts "The command '#{cmd}' is not installed or not available."
347
+ puts "Please install it before continuing."
348
+ exit 1
349
+ end
350
+ end
351
+ end
352
+
342
353
  def self.create_sudoers_file
354
+ self.check_requirements
343
355
  user = System.exec("whoami").output.chomp
356
+ content = []
357
+ content << "# Created by lxdev #{Time.now}"
358
+ WHITELISTED_SUDO_COMMANDS.each do |cmd|
359
+ cmd_with_path = System.exec("which #{cmd}").output.chomp
360
+ content << "#{user} ALL=(root) NOPASSWD: #{cmd_with_path}"
361
+ end
344
362
  puts <<-EOS
345
363
  !! WARNING !!
346
364
  This will create a file, /etc/sudoers.d/lxdev,
@@ -350,19 +368,16 @@ the following commands :
350
368
  with superuser privileges. If you do not know what you're
351
369
  doing, this can be dangerous and insecure.
352
370
 
353
- If you want to do this, type 'yesplease'
354
371
  EOS
372
+ puts "The following content will be created in /etc/sudoers.d/lxdev :"
373
+ puts
374
+ puts content
375
+ puts "\nIf you want to do this, type 'yesplease'"
355
376
  action = STDIN.gets.chomp
356
377
  unless action == 'yesplease'
357
378
  puts "Not creating sudoers file"
358
379
  return
359
380
  end
360
- content = []
361
- content << "# Created by lxdev #{Time.now}"
362
- WHITELISTED_SUDO_COMMANDS.each do |cmd|
363
- cmd_with_path = System.exec("which #{cmd}").output.chomp
364
- content << "#{user} ALL=(root) NOPASSWD: #{cmd_with_path}"
365
- end
366
381
  System.exec(%{printf '#{content.join("\n")}\n' | sudo tee /etc/sudoers.d/lxdev})
367
382
  System.exec("sudo chmod 0440 /etc/sudoers.d/lxdev")
368
383
  puts "Created sudoers file."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lxdev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Lønaas
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  requirements: []
71
71
  rubyforge_project:
72
- rubygems_version: 2.5.2.1
72
+ rubygems_version: 2.7.6
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Automagic development environment with LXD