Skip to content

Instantly share code, notes, and snippets.

@julienXX
Created July 21, 2009 13:23
Show Gist options
  • Save julienXX/151325 to your computer and use it in GitHub Desktop.
Save julienXX/151325 to your computer and use it in GitHub Desktop.
Script for LDAP user creation + skeleton
#!/bin/bash
#fx-useradd uid "first name" "last name"
PATH='/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin'
SKEL_PATH="/homes/skeleton"
usage() {
cat <<EOT
Usage: ${CMD} login first_name last_name
Creates a new account and associated group in the LDAP directory. Put first name into double quotes if composed.
Exemple :
${CMD} jddupont "Jean Daniel" Dupont
EOT
exit 1
}
if [ $# -ne 3 ]; then
usage
fi
[[ $(mountpoint /homes > /dev/null) -ne 0 ]] && echo -e "ERROR : NFS mount problem. Homes aren't mounted." && exit 1
#creates user in LDAP
# + creates home directory
# + passwd.
smbldap-useradd -a -m -N "$2" -S "$3" -E fx.bat -D "U:" -F '\\server\profiles' -P $1
#Creates home & profile
chown -R $1.root /homes/"$1"
mkdir /srv/profiles/"$1"
chown $1 /srv/profiles/"$1"
chmod 700 /srv/profiles/"$1"
### SKEL COPY ###
HOME_DIR="/homes/$1"
#Escaping '/' in SKELPATH
SED_SKEL_PATH=$(echo $SKEL_PATH |sed -e "s/\//\\\\\//g")
#creates directories
find $SKEL_PATH -mindepth 1 -type d | sed "s/$SED_SKEL_PATH\///g" | while read DIR ; do
mkdir $HOME_DIR/$DIR
done
#creates links
for FILE in $(find $SKEL_PATH -type f | sed "s/$SED_SKEL_PATH\///g") ; do
ln -fs ${SKEL_PATH}/${FILE} ${HOME_DIR}/${FILE}
done
# converts absolute symlinks into relatives
symlinks -cr $HOME_DIR > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment