Created
January 9, 2012 01:14
-
-
Save acidprime/1580398 to your computer and use it in GitHub Desktop.
Basic Example of Creating Digital Lockers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set -xv | |
declare -x DST_DIR="$1" | |
declare -x DS_DOMAIN='/Active Directory/All Domains' | |
declare -x GROUP_ATTR='GroupMembership' | |
declare -x GROUP_NAME='DPS\teachers.388-wgp.vc - elementary' | |
declare -x NT_DOMAIN="$(dscl "$DS_DOMAIN" -read / PrimaryNTDomain | | |
awk '{print $NF}')" | |
if [ "${#DST_DIR}" -eq 0 ] ; then | |
echo "You must specify a destination directory" | |
echo "$0 \"/path/to/directory\"" | |
exit 1 | |
fi | |
OLD_IFS="$IFS" | |
IFS=$'\n' | |
for GROUP_USER in $( | |
dscl "$DS_DOMAIN" -read /Groups/"$GROUP_NAME" "$GROUP_ATTR" | | |
sed 's/^ '$NT_DOMAIN'\\//g' | | |
sed 's/_/ /g' ) | |
do | |
let N++ | |
[ $N -eq 1 ] && continue | |
declare FIRST_NAME="$(echo $GROUP_USER | | |
awk '{print $1}')" | |
declare LAST_NAME="$(echo $GROUP_USER | | |
awk '{print $2}')" | |
declare FIRST_INIT="$(echo $FIRST_NAME | | |
awk 'BEGIN{FS=""}{print $1}' | | |
tr '[:lower:]' '[:upper:]')" | |
declare LAST_INIT="$(echo $LAST_NAME | | |
awk 'BEGIN{FS=""}{print $1}' | | |
tr '[:lower:]' '[:upper:]')" | |
declare LOWER_LAST_NAME="$( echo $LAST_NAME | sed s'/^.//g')" | |
declare FOLDER_NAME="$LAST_INIT$LOWER_LAST_NAME, $FIRST_INIT" | |
declare DST_PATH="$DST_DIR/$FOLDER_NAME" | |
echo "Creating Directory $DST_PATH ( $FIRST_NAME $LAST_NAME)" | |
if [ ! -d "$DST_PATH" ] ; then | |
mkdir -p "$DST_PATH/-->To $LAST_INIT$LOWER_LAST_NAME<--" | |
mkdir -p "$DST_PATH/From $LAST_INIT$LOWER_LAST_NAME" | |
chmod -R 555 "$DST_PATH" | |
chmod 755 "$DST_PATH/From $LAST_INIT$LOWER_LAST_NAME" | |
chmod 755 "$DST_PATH/-->To $LAST_INIT$LOWER_LAST_NAME<--" | |
chown -R www "$DST_PATH/" | |
else | |
echo "$GROUP_USER already has a folder" | |
if [ ! -d "$DST_PATH 2" ] ; then | |
echo "Creating directory with 2 appended" | |
mkdir -p "$DST_PATH 2/-->To $LAST_INIT$LOWER_LAST_NAME<--" | |
mkdir -p "$DST_PATH 2/From $LAST_INIT$LOWER_LAST_NAME" | |
chmod -R 555 "$DST_PATH 2/" | |
chmod 755 "$DST_PATH 2/-->To $LAST_INIT$LOWER_LAST_NAME<--" | |
chown -R www "$DST_PATH 2/" | |
fi | |
fi | |
done | |
echo "Processed $N users" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment