Module: Machines::Configuration

Defined in:
lib/machines/configuration.rb

Instance Method Summary collapse

Instance Method Details

#add(options) ⇒ Object

Add an existing user to a secondary group

Parameters:

  • options (Hash)

Options Hash (options):

  • :user (String)

    The user to add

  • :to (String)

    Adds an existing user to the specified group



22
23
24
25
# File 'lib/machines/configuration.rb', line 22

def add options
  required_options options, [:user, :to]
  Command.new("usermod -a -G #{options[:to]} #{options[:user]}", check_command("groups #{options[:user]}", options[:to]))
end

#add_user(login, options = {}) ⇒ Object

Add a new user (uses the lowlevel useradd so doesn't set a password unless specified)

Parameters:

  • login (String)

    User name to create

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :password (String)
  • :admin (Boolean)

    Adds the user to the admin group when true



9
10
11
12
13
14
15
16
# File 'lib/machines/configuration.rb', line 9

def add_user , options = {}
  password = "-p #{`openssl passwd #{options[:password]}`.gsub("\n", '')} " if options[:password]
  admin = "-G admin " if options[:admin]
  Command.new(
    "useradd -s /bin/bash -d /home/#{} -m #{password}#{admin}#{}",
    check_dir("/home/#{}")
  )
end

#configure(options) ⇒ Object

Sets gconf key value pairs

Parameters:

  • options (Hash)

    One or many key/value pairs to set



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/machines/configuration.rb', line 29

def configure options
  options.map do |key, value|
    types = {String => 'string', Fixnum => 'int', TrueClass => 'bool',
      FalseClass => 'bool', Float => 'float', Array => 'list --list-type=string'}
    type = types[value.class]
    raise 'Invalid type for configure' unless type
    value = value.to_json if value.is_a?(Array)
    value = %("#{value}") if type == 'string'
    check = "gconftool-2 --get \"#{key}\" | grep #{value} #{echo_result}"
    Command.new("gconftool-2 --set \"#{key}\" --type #{type} #{value}", check)
  end
end

#del_user(login) ⇒ Object

Removes a user, home and any other related files

Parameters:

  • login (String)

    User name to remove



44
45
46
# File 'lib/machines/configuration.rb', line 44

def del_user 
  Command.new("deluser #{} --remove-home -q", check_file('/home/login', false))
end