Programmatically creating users, groups, and i-bays

You can create users, groups, and i-bays by creating database defaults, or through code. Refer to the useraccounts, groups and ibays panels for examples of how to create these items. You can also create accounts with simple shell scripts.

For example, here is a shell script to create a user (account "abc", name "Albert Collins"):

#!/bin/sh

PATH=/sbin/e-smith:$PATH

if db accounts get abc >/dev/null
then
    echo "abc already exists in the accounts database"
    db accounts show abc
    exit 1
fi

db accounts set abc user PasswordSet no
db accounts setprop abc FirstName Albert 
db accounts setprop abc LastName Collins
db accounts setprop abc EmailForward local

signal-event user-create abc

Note that we could have provided all of the properties to the set command and created the record in one step. Here's the same example using the Perl libraries

#!/usr/bin/perl -w

use strict;
use warnings;
use esmith::AccountsDB;

my $db = esmith::AccountsDB->open or die "Couldn't open AccountsDB\n";

my $abc = $db->get("abc");

if ($abc)
{
    die "abc already exists in the accounts database\n" .
        $abc->show . "\n";
}

$db->new_record("abc",
        {
            type         => 'user',
            PasswordSet  => 'no',
            FirstName    => 'Albert',
            LastName     => 'Collins',
            EmailForward => 'local',
        });

unless ( system("/sbin/e-smith/signal-event", "user-create", "abc") == 0 )
{
    die "user-create abc failed\n";
}

exit 0;