Module: Machines::Configuration
- Defined in:
- lib/machines/configuration.rb
Instance Method Summary collapse
-
#add(options) ⇒ Object
Add an existing user to a secondary group.
-
#add_user(login, options = {}) ⇒ Object
Add a new user (uses the lowlevel useradd so doesn't set a password unless specified).
-
#configure(options) ⇒ Object
Sets gconf key value pairs.
-
#del_user(login) ⇒ Object
Removes a user, home and any other related files.
Instance Method Details
#add(options) ⇒ Object
Add an existing user to a secondary group
22 23 24 25 |
# File 'lib/machines/configuration.rb', line 22 def add , [:user, :to] Command.new("usermod -a -G #{[:to]} #{[:user]}", check_command("groups #{[:user]}", [:to])) end |
#add_user(login, options = {}) ⇒ Object
Add a new user (uses the lowlevel useradd so doesn't set a password unless specified)
9 10 11 12 13 14 15 16 |
# File 'lib/machines/configuration.rb', line 9 def add_user login, = {} password = "-p #{`openssl passwd #{[:password]}`.gsub("\n", '')} " if [:password] admin = "-G admin " if [:admin] Command.new( "useradd -s /bin/bash -d /home/#{login} -m #{password}#{admin}#{login}", check_dir("/home/#{login}") ) end |
#configure(options) ⇒ Object
Sets gconf key value pairs
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/machines/configuration.rb', line 29 def configure .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 |