lib/vanagon/platform.rb
def add_user(user)
      cmd_args = ["'#{user.name}'"]
      cmd_args.unshift "--home '#{user.homedir}'" if user.homedir
      if user.shell
        cmd_args.unshift "--shell '#{user.shell}'"
      elsif user.is_system
        cmd_args.unshift "--shell '/usr/sbin/nologin'"
      end
      cmd_args.unshift "--gid '#{user.group}'" if user.group
      cmd_args.unshift '--system' if user.is_system

      # Collapse the cmd_args array into a string that can be used
      # as an argument to `useradd`
      useradd_args = cmd_args.join "\s"

      # Collapse the cmd_args array into a string that can be used
      # as an argument to `usermod`; If this is a system account,
      # then specify it as such for user addition only (strip
      # --system from usermod_args)
      usermod_args = (cmd_args - ["--system"]).join "\s"

      return <<-HERE.undent
        if getent passwd '#{user.name}' > /dev/null 2>&1; then
          /usr/sbin/usermod #{usermod_args}
        else
          /usr/sbin/useradd #{useradd_args}
        fi
      HERE
    end
# Generate the scripts required to add a user to the package generated.
# This will also update the user if it has changed.
#
# @param user [Vanagon::Common::User] the user to create
# @return [String] the commands required to add a user to the system
Generate the scripts required to add a user to the package generated.
This will also update the user if it has changed.
Generate the scripts required to add a user to the package generated . This will also update the user if it has changed .
def add_user(user)
      cmd_args = ["'#{user.name}'"]
      cmd_args.unshift "--home '#{user.homedir}'" if user.homedir
      if user.shell
        cmd_args.unshift "--shell '#{user.shell}'"
      elsif user.is_system
        cmd_args.unshift "--shell '/usr/sbin/nologin'"
      end
      cmd_args.unshift "--gid '#{user.group}'" if user.group
      cmd_args.unshift '--system' if user.is_system
      useradd_args = cmd_args.join "\s"
      usermod_args = (cmd_args - ["--system"]).join "\s"
      return <<-HERE.undent
        if getent passwd '#{user.name}' > /dev/null 2>&1; then
          /usr/sbin/usermod #{usermod_args}
        else
          /usr/sbin/useradd #{useradd_args}
        fi
      HERE
    end
def add_user ( user ) cmd_args = [ "'#{user.name}'" ] cmd_args . unshift "--home '#{user.homedir}'" if user . homedir if user . shell cmd_args . unshift "--shell '#{user.shell}'" elsif user . is_system cmd_args . unshift "--shell '/usr/sbin/nologin'" end cmd_args . unshift "--gid '#{user.group}'" if user . group cmd_args . unshift '--system' if user . is_system useradd_args = cmd_args . join "\s" usermod_args = ( cmd_args - [ "--system" ] ) . join "\s" return <<-HERE . undent 
        if getent passwd ' #{ user . name } ' > /dev/null 2>&1; then
          /usr/sbin/usermod  #{ usermod_args } 
        else
          /usr/sbin/useradd  #{ useradd_args } 
        fi
       HERE end
Generate the scripts required to add a user to the package generated.
Generate the scripts required to add a user to the package generated .
# Collapse the cmd_args array into a string that can be used # as an argument to `useradd` # Collapse the cmd_args array into a string that can be used # as an argument to `usermod`; If this is a system account, # then specify it as such for user addition only (strip # --system from usermod_args)
the commands required to add a user to the system
the commands required to add a user to the system
String
user
the user to create
the user to create