Created
January 9, 2012 01:51
-
-
Save acidprime/1580537 to your computer and use it in GitHub Desktop.
Fix Home Permissions Example
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 | |
# Runtime configuration | |
export SCHOOL_SITE="$(/bin/hostname -s | | |
/usr/bin/sed 's/ap.s0.//g' | /usr/bin/tr '[:lower:]' '[:upper:]')" | |
# Overrides for sites | |
if [ "$SCHOOL_SITE" = "SSC" ] ; then | |
export SCHOOL_SITE=TSD | |
fi | |
if [ "$SCHOOL_SITE" = "ADMIN" ] ; then | |
export SCHOOL_SITE=DO | |
fi | |
if [ "$SCHOOL_SITE" = "TC" ] ; then | |
export SCHOOL_SITE=TSD | |
fi | |
if [ "$SCHOOL_SITE" = "MEC" ] ; then | |
export SCHOOL_SITE=TSD | |
fi | |
# Command Declarations | |
export sudo="/usr/bin/sudo" | |
export chown="/usr/sbin/chown" | |
export chmod="/bin/chmod" | |
export basename="/usr/bin/basename" | |
export id="/usr/bin/id" | |
export logger="/usr/bin/logger" | |
updateOwnerShip(){ | |
declare USER_NAME="$1" USER_HOME="$2" | |
if [ -d "$USER_HOME" ] ; then | |
if $id "$USER_NAME" &>/dev/null ; then | |
echo "Changing ownership for $USER_HOME to be owned via POSIX by $USER_NAME" | |
$chown -R "$USER_NAME":'TSD\domain admins' "$USER_HOME" | |
echo "Setting default permissions for $USER_HOME" | |
$chmod -R 755 "$USER_HOME" | |
echo "Removing and Re-adding ACLs $USER_NAME for $USER_HOME" | |
$chmod -R -a "$USER_NAME allow list,add_file,search,delete,add_subdirectory,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" "$USER_HOME" 2>/dev/null | |
$chmod -R +a "$USER_NAME allow list,add_file,search,delete,add_subdirectory,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" "$USER_HOME" | |
$chmod -R -a 'TSD\domain admins:allow:list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown,file_inherit,directory_inherit' "$USER_HOME" 2>/dev/null | |
$chmod -R +a 'TSD\domain admins:allow:list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown,file_inherit,directory_inherit' "$USER_HOME" | |
else | |
echo "User: $USER_NAME does not exist but has ~@:$USER_HOME" | |
fi | |
fi | |
} # END updateOwnerShip() | |
export SHARE_NAME="/Volumes/Storage/Staff" | |
# Process Staff | |
echo "Processing $SHARE_NAME" | |
if [ -d "$SHARE_NAME" ] ; then | |
OLDIFS="$IFS" | |
IFS=$'\n' | |
for USER_HOME in "$SHARE_NAME"/* ; do | |
export USER_NAME="$($basename "$USER_HOME")" | |
echo "Processing: $USER_NAME with home: $USER_HOME" | |
updateOwnerShip "$USER_NAME" "$USER_HOME" | |
done | |
IFS="$OLDIFS" | |
else | |
echo "No Folder Found: $SHARE_NAME" | |
fi | |
# Process Students | |
export SHARE_NAME="/Volumes/Storage/Students" | |
echo "Processing $SHARE_NAME" | |
if [ -d "$SHARE_NAME" ] ; then | |
OLDIFS="$IFS" | |
IFS=$'\n' | |
for USER_HOME in "$SHARE_NAME"/*/* ; do | |
export USER_NAME="$($basename "$USER_HOME")" | |
echo "Processing: $USER_NAME with home: $USER_HOME" | |
updateOwnerShip "$USER_NAME" "$USER_HOME" | |
done | |
IFS="$OLDIFS" | |
else | |
echo "No Folder Found: $SHARE_NAME" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment