[Admin-ml] créer un user sur plusieurs machines en même temps

Olivier DUCROT odlists at easymac.fr
Lun 9 Nov 22:19:21 CET 2009


Tu peux faire comme dans nombre de paquets d'installation qui nécessitent un
utilisateur spécifique, tu fait un petit shell de post traitement qui
contient la création de l'utilisateur (4 lignes pour un utilisateur sans
trop d'options), tu distribues le paquet avec ARD et roule...

Comme exemple de paquet avec création d'utilisateur pour 10.3 & 10.4, il y a
l'installeur de posgreSQL.

Une autre solution, tu utilises DeployStudio, ou plutôt l'un des scripts
10.4/ds_add_local_users ds_add_user.sh et
10.5/ds_add_local_users/ds_add_local_user.sh  qui sont livrés avec :

#!/bin/sh

echo "ds_add_user.sh - v1.10 ("`date`")"

# IMPORTANT NOTE: the script ds_add_user.sh script located in the folder
DeployStudio.app/Contents/Resources/Scripts/
# is called by DeployStudio to create the user defined in the hosts
database.
# 

# Usage: ds_add_user $1 $2 $3 $4 [$5 $6 $7]
# $1 -> volume
# $2 -> realname
# $3 -> shortname
# $4 -> password
# $5 -> admin (YES/NO)
# $6 -> localization (English, French, etc...)
# $7 -> uidNumber

# create the default user
NIDB_FILE="/Volumes/${1}/var/db/netinfo/local.nidb"
USER_REALNAME=${2}
USER_SHORTNAME=${3}
USER_PASSWORD=${4}
USER_ADMIN=${5}
USER_LOCALE=${6}
USER_UID=${7}
USER_HOME="/Volumes/${1}/Users/${USER_SHORTNAME}"

if [ ! -e "${NIDB_FILE}" ]; then
  /usr/libexec/create_nidb local localhost "/Volumes/${1}"
fi

if [ -n "${USER_SHORTNAME}" ]; then
  SAME_UID="YES"
  if [ -n "${USER_UID}" ]; then
    SAME_UID=`nicl -raw "${NIDB_FILE}" -list users uid | awk '{ print
"+"$2"+" }' | grep "+${USER_UID}+"`
  fi
  if [ -n "${SAME_UID}" ]; then
    USER_UID=`nicl -raw "${NIDB_FILE}" -list users uid | awk '{ print $2 }'
| sort -n | tail -n 1`
    USER_UID=`expr ${USER_UID} + 1`
    if [ ${USER_UID} -le 501 ]; then
      USER_UID=501
    fi
  fi

  echo "  Creating group '${USER_SHORTNAME}' with gid=${USER_UID} !" 2>&1

  nicl -raw "${NIDB_FILE}" -delete groups/${USER_SHORTNAME} 2>/dev/null
  nicl -raw "${NIDB_FILE}" -create groups/${USER_SHORTNAME}

  nicl -raw "${NIDB_FILE}" -create groups/${USER_SHORTNAME} gid
"${USER_UID}"
  nicl -raw "${NIDB_FILE}" -create groups/${USER_SHORTNAME} passwd "*"

  echo "  Creating user '${USER_SHORTNAME}' with uid=${USER_UID} !" 2>&1

  nicl -raw "${NIDB_FILE}" -delete users/${USER_SHORTNAME} 2>/dev/null
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME}

  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} uid "${USER_UID}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} gid "${USER_UID}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} sharedDir
"Public"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} home
"/Users/${USER_SHORTNAME}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} shell "/bin/bash"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} _shadow_passwd ""
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} _writers_passwd
"${USER_SHORTNAME}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} _writers_hint
"${USER_SHORTNAME}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} _writers_picture
"${USER_SHORTNAME}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME}
_writers_tim_password "${USER_SHORTNAME}"
  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} _writers_realname
"${USER_SHORTNAME}"

  nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME}
authentication_authority ";basic;"
  if [ -n "${USER_REALNAME}" ]; then
    nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} realname
"${USER_REALNAME}"
  else
    nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} realname
"${USER_SHORTNAME}"
  fi

  if [ -n "${USER_PASSWORD}" ]; then
    nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} passwd `openssl
passwd -crypt ${USER_PASSWORD}`
  else
    nicl -raw "${NIDB_FILE}" -create users/${USER_SHORTNAME} passwd `openssl
passwd -crypt ${USER_SHORTNAME}`
  fi  

  if [ "_YES" == "_${USER_ADMIN}" ]; then
    echo "  Setting admin properties" 2>&1
    nicl -raw "${NIDB_FILE}" -append groups/admin users "${USER_SHORTNAME}"
    
    nicl -raw "${NIDB_FILE}" -delete users/root generateduid 2>/dev/null
    nicl -raw "${NIDB_FILE}" -delete users/root authentication_authority
2>/dev/null
    nicl -raw "${NIDB_FILE}" -delete users/root passwd 2>/dev/null
    nicl -raw "${NIDB_FILE}" -create users/root authentication_authority
";basic;"
    if [ ! "_" == "_${USER_PASSWORD}" ]; then
      nicl -raw "${NIDB_FILE}" -create users/root passwd `openssl passwd
-crypt ${USER_PASSWORD}`
    else
      nicl -raw "${NIDB_FILE}" -create users/root passwd `openssl passwd
-crypt ${USER_SHORTNAME}`
    fi  
  fi
  
  if [ -d  "/Volumes/${1}/Users" ]; then
    echo "  Creating local home directory" 2>&1
    if [ -d "/Volumes/${1}/System/Library/User
Template/${USER_LOCALE}.lproj" ]; then
        ditto --rsrc "/Volumes/${1}/System/Library/User
Template/${USER_LOCALE}.lproj" "${USER_HOME}"
    else
        ditto --rsrc "/Volumes/${1}/System/Library/User
Template/Non_localized" "${USER_HOME}"
    fi
    chown -R ${USER_UID}:${USER_UID} "${USER_HOME}"
  fi
fi



le 09/11/09 19:20, Proniewski Patrick à patrick.proniewski at univ-lyon2.fr a
écrit :

> On 9 nov. 09, at 18:52, Fabien COMBERNOUS wrote:
> 
>> en le créant à la ligne de commande, via ssh, avec identification
>> par clef.
> 
> 
> Le souci, c'est qu'apple ne fourni pas de adduser donc faut se fader
> toutes les spécificités à la main.
> 
> (jayce, par pitié, autorise les messages avec S/MIME, c'est ultra
> pénible de reposter à chaque fois parce qu'on oublie de désactiver la
> signature des messages...)
> 
> 
> Patrick PRONIEWSKI

La théorie, c¹est quand on sait tout mais que rien ne marche
La pratique, c¹est quand tout marche mais qu¹on ne sait pas pas pourquoi
Et l¹informatique, c¹est l¹union de la théorie et de la pratique : rien ne
marche et on sait pas pourquoi

         _________________________________________________________
         |                                                       |  
         |                                                       |  
      / )|                    Olivier DUCROT                     |( \
     / / |               ACSP, ACTC & ACSA 10.5                  | \ \
   _( (_ |                                                       | _) )_
  (((\ \>|_/->_______________________________________________<-\_|</ /)))
  (\\\\ \_/ /                                                 \ \_/ ////)
   \       /                                                   \       /
    \    _/                -----====+====------                 \_    /
    /   /                                                        \   \  
  






Plus d'informations sur la liste de diffusion Admin-ml