Method: Pawnee::Actions::User#save

Defined in:
lib/pawnee/pawnee/actions/user.rb

#saveObject

Write any changes out



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/pawnee/pawnee/actions/user.rb', line 125

def save
  # Since groups is an array, we have to manually check to see if
  # its changed, because people can do << to it
  if @original_groups_value != @groups
    # Mark as changed
    self.groups_will_change!
    
    @original_groups_value = @groups
  end
  
  if changed?
    raise "A login must be specified" unless 
    
    if new_record?
      # Just create a new user
      command = ["useradd"]
      base.say_status :create_user, , :green
    else
      # Modify an existing user
      command = ["usermod"]
      base.say_status :update_user, , :green
    end
    
    # Set options
    command << "-u #{uid}" if uid && uid_changed?
    command << "-g #{gid}" if gid && gid_changed?
    command << "-G #{groups.join(',')}" if groups && groups_changed? && groups.size != 0
    command << "-c #{comment.inspect}" if comment && comment_changed?
    command << "-s #{shell.inspect}" if shell && shell_changed?
    command << "-p #{password.inspect}" if password && password_changed?
    
    # TODO: If update, we need to make the directory first to move things to
    command << "-m -d #{home.inspect}" if home && home_changed?
    command << 
    
    base.as_root do
      base.exec(command.join(' '), :no_pty => true)
    end
  else
    base.say_status :user_exists, , :blue
  end
end