lxdev 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/bin/lxdev +10 -1
  3. data/lib/lxdev/main.rb +19 -8
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: bd005fcf499291c992c0176018a0feac0e2fca7bc8a130801d2089a92dabc313
4
- data.tar.gz: fb3a2b1facc6caedd1928dd03f0c6cd710a99bfdc30355721978d9146e9616bb
2
+ SHA1:
3
+ metadata.gz: c603e8b103efda46294c12b2fd712467c36acbab
4
+ data.tar.gz: 46e2fdf820c4a1991e393a9242d3c86a7c6d50fa
5
5
  SHA512:
6
- metadata.gz: 67cd321fc6066831e289c92887566034a452c8128d36be956c5f7021ebf618ab31d66abb9ef62ae02f745b64519fce38c069a00bed4791e00de9e9cd22183f87
7
- data.tar.gz: 66be27cb60e0d0442b73c5be27d128aa8222614b62b53f1d2f300ed60978aa27b3ad439a9b9b6434946ae0cc4d169eea39333283c5e4107f69bcc87c1ebb8f11
6
+ metadata.gz: 7cd7b1a83e49543fb0f0efbd71c8910e0cdf812c31c369a65651c6acb18f8251b55b2b676344d431166ceb27b6a3dad95275058cb6aea2bcdac8589aafba75c4
7
+ data.tar.gz: 12b3fd2021f8a09e39c332093c6e5e4c0dfbbe9a489a979e09551e31cac2115c4c3afd7a563e724662584e4693a7ce93980c1950ef14694203c627f9acdb2b93
data/bin/lxdev CHANGED
@@ -2,6 +2,8 @@
2
2
  require 'lxdev/main'
3
3
  require 'optparse'
4
4
 
5
+ $config_file = 'lxdev.yml'
6
+
5
7
  def option_parser
6
8
  opt_parser = OptionParser.new do |opts|
7
9
  opts.banner = "Usage: lxdev [options] command"
@@ -16,6 +18,13 @@ def option_parser
16
18
  exit
17
19
  end
18
20
 
21
+ opts.on("-c F", "--config F", String, "Specify config file, defaults to lxdev.yml") do |filename|
22
+ puts filename
23
+ unless filename.nil?
24
+ $config_file = filename
25
+ end
26
+ end
27
+
19
28
  end
20
29
  opt_parser.separator ""
21
30
  opt_parser.separator <<-EOS
@@ -97,7 +106,7 @@ end
97
106
 
98
107
 
99
108
  option_parser
100
- lxdev = LxDev::Main.setup()
109
+ lxdev = LxDev::Main.setup($config_file)
101
110
  if lxdev
102
111
  execute_main_command(lxdev)
103
112
  lxdev.save_state
data/lib/lxdev/main.rb CHANGED
@@ -2,18 +2,19 @@ require 'yaml'
2
2
  require 'json'
3
3
  require 'terminal-table'
4
4
  require 'lxdev/system'
5
+ require 'tempfile'
5
6
 
6
7
  module LxDev
7
8
  class Main
8
9
  WHITELISTED_SUDO_COMMANDS = ["lxc", "redir", "kill"]
9
10
  SHELLS = ["bash", "zsh", "sh", "csh", "tcsh", "ash"]
10
11
  BOOT_TIMEOUT = 30
11
- VERSION = '0.1.3'
12
+ VERSION = '0.1.4'
12
13
 
13
- def initialize
14
+ def initialize(config_file)
14
15
  @uid = System.exec("id -u").output.chomp
15
16
  @gid = System.exec("id -g").output.chomp
16
- @config = YAML.load_file('lxdev.yml')
17
+ @config = YAML.load_file(config_file)
17
18
  @name = @config['box']['name']
18
19
  @image = @config['box']['image']
19
20
  @user = @config['box']['user']
@@ -25,17 +26,17 @@ module LxDev
25
26
  @state = Hash.new
26
27
  end
27
28
  rescue Errno::ENOENT
28
- puts "lxdev.yml not found"
29
+ puts "#{config_file} not found"
29
30
  exit 1
30
31
  end
31
32
 
32
- def self.setup
33
+ def self.setup(config_file = 'lxdev.yml')
33
34
  self.check_requirements
34
35
  unless lxd_initialized?
35
36
  puts "Please run 'lxd init' and configure LXD first"
36
37
  return false
37
38
  end
38
- lxdev = Main.new
39
+ lxdev = Main.new(config_file)
39
40
  unless lxdev.set_ssh_keys
40
41
  puts "No ssh keys detected. Make sure you have an ssh key, a running agent, and the key added to the agent, e.g. with ssh-add."
41
42
  return false
@@ -359,6 +360,7 @@ module LxDev
359
360
  cmd_with_path = System.exec("which #{cmd}").output.chomp
360
361
  content << "#{user} ALL=(root) NOPASSWD: #{cmd_with_path}"
361
362
  end
363
+ content << "\n"
362
364
  puts <<-EOS
363
365
  !! WARNING !!
364
366
  This will create a file, /etc/sudoers.d/lxdev,
@@ -378,8 +380,17 @@ doing, this can be dangerous and insecure.
378
380
  puts "Not creating sudoers file"
379
381
  return
380
382
  end
381
- System.exec(%{printf '#{content.join("\n")}\n' | sudo tee /etc/sudoers.d/lxdev})
382
- System.exec("sudo chmod 0440 /etc/sudoers.d/lxdev")
383
+ temp_file = Tempfile.create('lxdev-sudoers')
384
+ temp_file.write(content.join("\n"))
385
+ temp_file_name = temp_file.to_path
386
+ temp_file.close
387
+ unless System.exec("visudo -c -f #{temp_file_name}").exitstatus == 0
388
+ puts "Generated sudoers file contains errors, aborting."
389
+ exit 1
390
+ end
391
+ System.exec("sudo chown root:root #{temp_file_name}")
392
+ System.exec("sudo chmod 0440 #{temp_file_name}")
393
+ System.exec("sudo mv #{temp_file_name} /etc/sudoers.d/lxdev")
383
394
  puts "Created sudoers file."
384
395
  end
385
396
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Lønaas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-06 00:00:00.000000000 Z
12
+ date: 2019-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -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.7.6
72
+ rubygems_version: 2.5.2.1
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Automagic development environment with LXD