C Sample Scripts for Updating Default Attributes for Provisioning

This appendix provides sample scripts for editing the default attribute mappings for provisioning.

Sample scripts for the procedure described in Adding Custom Attributes for Provisioning are as follows:

C.1 Original Sample Script

This is the original CreateNativeUser.txt script.

if [ ! -z "$__UID__" ] ;then
    __NAME__=$__UID__;
else
    __NAME__=$__NAME__;
fi;
if id $__NAME__ > /dev/null 2>&1 ;then 
    echo "User already exists";
else 
    globalVar="true";
    if [ ! -z $SECONDARYGROUP ] ;then 
        command="$command -G $SECONDARYGROUP";
    fi;
 
    homedir="";
    if [ ! -z $HOME_DIR ] ;then 
        homedir=$HOME_DIR;
    else 
        if [ ! -z $defaultHomeBaseDir ] ;then 
            homedir=$defaultHomeBaseDir;
        fi;
    fi;
    if [ ! -z $homedir ] ;then 
        checkHomeBaseDir=$(test -d $homedir && echo "true" || echo "false");
        if [ $checkHomeBaseDir == "true" ]; then 
            command="$command -d $homedir/$__NAME__";
        else 
            globalVar="false";
            echo "useradd: cannot create directory $homedir/$__NAME__";
        fi;
    fi;
    if [ ! -z $EXP_DATE ] ;then 
        command="$command -e $EXP_DATE";
    fi;
    if [ ! -z $INACTIVE ] ;then 
        command="$command -f $INACTIVE";
    fi;
    if [ ! -z $PGROUP ] ;then 
        grp=$PGROUP;
    else 
        if [ ! -z $defaultPriGroup ] ;then 
            grp=$defaultPriGroup;
        fi;
    fi;
    if [ ! -z $grp ] ;then 
        getent group $grp;
        if [ $? -ne 0 ] ;then 
            echo "PGROUP=$grp";
            echo "Invalid primary group :- $grp";
            globalVar="false";
        else 
            command="$command -g $grp";
        fi;
    fi;
    if [ ! -z $CREATE_HOME_DIR ] && [  $CREATE_HOME_DIR == "true" ] ;then 
        command="$command -m";
            if [ ! -z $SKEL_DIR ] ;then 
                command="$command -k $SKEL_DIR";
            fi;
    fi;
    if [ ! -z $CREATE_USER_GROUP ] && [  $CREATE_USER_GROUP == "false" ] ;then 
        command="$command -n";
    fi;
    if [ ! -z $USER_SHELL ] ;then 
        command="$command -s $USER_SHELL";
    else 
        if [ ! -z $defaultShell ] ;then 
            command="$command -s $defaultShell";
        fi;
    fi;
    if [ ! -z $USID ] && [  $USID -gt 0 ] ;then 
        command="$command -u $USID";
        if [ ! -z $UNIQUE_USID ] && [  $UNIQUE_USID == "false" ] ;then 
            command="$command -o";
        fi;
    fi;
    if [ $globalVar == "true" ] ;then 
        echo "useradd $command $__NAME__";
        useradd $command $__NAME__;
        if [ $? -eq 0 ]; then echo "SUCCESS";
            if [ ! -z "$COMMENTS" ] ; then echo "usermod -c \""$COMMENTS"\" $__NAME__";
                usermod -c "$COMMENTS" $__NAME__; 
            fi;
        fi;
    fi;
fi;
unset bar COMMENTS HOME_DIR PGROUP grp EXP_DATE SKEL_DIR UNIQUE_USID __NAME__ __UID__ CREATE_HOME_DIR;
unset USER_SHELL USID CREATE_USER_GROUP INACTIVE SECONDARYGROUP command globalVar name;
unset defaultHomeBaseDir homedir checkHomeBaseDir grp defaultPriGroup;

C.2 Updated Sample Script

This is the CreateNativeUser.txt script that has been updated to include the newly added __GID__ attribute. The updated lines are represented in bold font.

if [ ! -z "$__UID__" ] ;then
    __NAME__=$__UID__;
else
    __NAME__=$__NAME__;
fi;
if id $__NAME__ > /dev/null 2>&1 ;then 
    echo "User already exists";
else 
    globalVar="true";
    if [ ! -z $SECONDARYGROUP ] ;then 
        command="$command -G $SECONDARYGROUP";
    fi;
 
    homedir="";
    if [ ! -z $HOME_DIR ] ;then 
        homedir=$HOME_DIR;
    else 
        if [ ! -z $defaultHomeBaseDir ] ;then 
            homedir=$defaultHomeBaseDir;
        fi;
    fi;
    if [ ! -z $homedir ] ;then 
        checkHomeBaseDir=$(test -d $homedir && echo "true" || echo "false");
        if [ $checkHomeBaseDir == "true" ]; then 
            command="$command -d $homedir/$__NAME__";
        else 
            globalVar="false";
            echo "useradd: cannot create directory $homedir/$__NAME__";
        fi;
    fi;
    if [ ! -z $EXP_DATE ] ;then 
        command="$command -e $EXP_DATE";
    fi;
    if [ ! -z $INACTIVE ] ;then 
        command="$command -f $INACTIVE";
    fi;
    if [ ! -z $PGROUP ] ;then 
        grp=$PGROUP;
    else 
        if [ ! -z $defaultPriGroup ] ;then 
            grp=$defaultPriGroup;
        fi;
    fi;
    if [ ! -z $grp ] ;then 
        getent group $grp;
        if [ $? -ne 0 ] ;then 
            echo "PGROUP=$grp";
            echo "Invalid primary group :- $grp";
            globalVar="false";
        else 
            command="$command -g $grp";
        fi;
    fi;
    if [ ! -z $CREATE_HOME_DIR ] && [  $CREATE_HOME_DIR == "true" ] ;then 
        command="$command -m";
            if [ ! -z $SKEL_DIR ] ;then 
                command="$command -k $SKEL_DIR";
            fi;
    fi;
    if [ ! -z $CREATE_USER_GROUP ] && [  $CREATE_USER_GROUP == "false" ] ;then 
        command="$command -n";
    fi;
    if [ ! -z $USER_SHELL ] ;then 
        command="$command -s $USER_SHELL";
    else 
        if [ ! -z $defaultShell ] ;then 
            command="$command -s $defaultShell";
        fi;
    fi;
    if [ ! -z $USID ] && [  $USID -gt 0 ] ;then 
        command="$command -u $USID";
        if [ ! -z $UNIQUE_USID ] && [  $UNIQUE_USID == "false" ] ;then 
            command="$command -o";
        fi;
    fi;
    if [ ! -z $__GID__ ] ;then 
        command="$command -g $__GID__";
    fi;
    if [ $globalVar == "true" ] ;then 
        echo "useradd $command $__NAME__";
        useradd $command $__NAME__;
        if [ $? -eq 0 ]; then echo "SUCCESS";
            if [ ! -z "$COMMENTS" ] ; then echo "usermod -c \""$COMMENTS"\" $__NAME__";
                usermod -c "$COMMENTS" $__NAME__; 
            fi;
        fi;
    fi;
fi;
unset bar COMMENTS HOME_DIR PGROUP grp EXP_DATE SKEL_DIR UNIQUE_USID __NAME__ __UID__ CREATE_HOME_DIR;
unset USER_SHELL USID CREATE_USER_GROUP INACTIVE SECONDARYGROUP command globalVar name;
unset defaultHomeBaseDir homedir checkHomeBaseDir grp defaultPriGroup __GID__;