この付録では、プロビジョニング用にデフォルトの属性マッピングを編集するサンプル・スクリプトを示します。
「プロビジョニング用のカスタム属性の追加」に記載された手順のサンプル・スクリプトは次のとおりです:
これが、元のCreateNativeUser.txtスクリプトです。
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;
これが、新しく追加された__GID__属性を含むように更新されたCreateNativeUser.txtスクリプトです。更新された行は太字フォントで示されています。
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__;