lib/os/user-management/add-user.js
function addUser(user, options) {
  if (!runningAsRoot()) return;
  if (!user) throw new Error('You must provide an username');
  options = _.opts(options, {systemUser: false, home: null, password: null, gid: null, uid: null, groups: []});
  if (userExists(user)) {
    return;
  }
  if (isPlatform('linux')) {
    _addUserLinux(user, options);
  } else if (isPlatform('osx')) {
    _addUserOsx(user, options);
  } else if (isPlatform('windows')) {
    throw new Error("Don't know how to add user in Windows");
  } else {
    throw new Error("Don't know how to add user in current platform");
  }
}
function addUser(user, options) {
  if (!runningAsRoot()) return;
  if (!user) throw new Error('You must provide an username');
  options = _.opts(options, {systemUser: false, home: null, password: null, gid: null, uid: null, groups: []});
  if (userExists(user)) {
    return;
  }
  if (isPlatform('linux')) {
    _addUserLinux(user, options);
  } else if (isPlatform('osx')) {
    _addUserOsx(user, options);
  } else if (isPlatform('windows')) {
    throw new Error("Don't know how to add user in Windows");
  } else {
    throw new Error("Don't know how to add user in current platform");
  }
}
function addUser ( user , options ) { if ( ! runningAsRoot ( ) ) return ; if ( ! user ) throw new Error ( 'You must provide an username' ) ; options = _ . opts ( options , { systemUser : false , home : null , password : null , gid : null , uid : null , groups : [ ] } ) ; if ( userExists ( user ) ) { return ; } if ( isPlatform ( 'linux' ) ) { _addUserLinux ( user , options ) ; } else if ( isPlatform ( 'osx' ) ) { _addUserOsx ( user , options ) ; } else if ( isPlatform ( 'windows' ) ) { throw new Error ( "Don't know how to add user in Windows" ) ; } else { throw new Error ( "Don't know how to add user in current platform" ) ; } }
Add a user to the system
@function $os~addUser
@param {string} user - Username
@param {Object} [options]
@param {boolean} [options.systemUser=false] - Set user as system user (UID within 100 and 999)
@param {string} [options.home=null] - User home directory
@param {string} [options.password=null] - User password
@param {string|number} [options.gid=null] - User Main Group ID
@param {string|number} [options.uid=null] - User ID
@param {string[]} [options.groups=[]] - Extra groups for the user
@example
// Creates a 'mysql' user and add it to 'mysql' group
$os.addUser('mysql', {gid: $os.getGid('mysql')});
Add a user to the system