# HG changeset patch # User John Schneiderman # Date 1268805540 0 # Node ID 1009f603958e89c9796987d2df050e61eb9a24c7 # Parent 3cdee66547d0db635205afece13b804b359ba3a8 Enhancement: processes directories and file names that contain spaces. Bug fix: directories did not have permissions changed. diff -r 3cdee66547d0 -r 1009f603958e ufpm.sh --- a/ufpm.sh Wed Mar 10 08:34:59 2010 +0000 +++ b/ufpm.sh Wed Mar 17 05:59:00 2010 +0000 @@ -124,7 +124,7 @@ if [ \( "$ENABLE_USER" = "true" \) -a \( "$fileUser" != "$user" \) ] then #Change the owner of the file - chown $user "$filePath/$filename" + chown $user "${filePath}${filename}" if [ $? -ne 0 ] then return 1 @@ -133,7 +133,7 @@ if [ \( "$ENABLE_GROUP" = "true" \) -a \( "$fileGroup" != "$group" \) ] then #Change the group owner of the file - chgrp $group "$filePath/$filename" + chgrp $group "${filePath}${filename}" if [ $? -ne 0 ] then return 1 @@ -144,12 +144,22 @@ then # File permissions need to be changed if [ \( "$IS_VERBOSE" = "true" \) ] then - printf "Changing %s to %d\n" "$filename" "$permissions" + if [ -z $filename ] + then + printf "Changing %s to %d\n" "$filePath" "$permissions" + else + printf "Changing %s to %d\n" "$filename" "$permissions" + fi fi - chmod $permissions "$filePath/$filename" + chmod $permissions "${filePath}${filename}" elif [ \( "$IS_VERBOSE" = "true" \) ] then - printf "Determined %s already is %d\n" "$filename" "$permissions" + if [ -z $filename ] + then + printf "Determined %s already is %d\n" "$filePath" "$permissions" + else + printf "Determined %s already is %d\n" "$filename" "$permissions" + fi fi if [ $? -eq 0 ] @@ -170,16 +180,17 @@ local path=$1 local file=$2 - if [ ! -e "$path/$file" ] + if [ ! -e "${path}${file}" ] then #Assumed to have been a temp file + printf "Must have been a temporary file: %s%s\n" "$path" "$file" return 0 - elif [ -h "$path/$file" ] + elif [ -h "$path$file" ] then #File is a symbolic link return 0 - elif [ -S "$path/$file" ] + elif [ -S "$path$file" ] then #File is a socket return 0 - elif [ -f "$path/$file" ] + elif [ -f "$path$file" ] then #Change permissions of a file if [[ "$path" = *tmp* ]] then #Don't change temporary files @@ -207,7 +218,7 @@ else #Normal file changePermissions "$path" "$file" "$filePermissions" fi - elif [ -d "$path/$file" ] + elif [ -d "$path$file" ] then #Change permissions of a directory if [[ "$file" = .* ]] then #Hidden directory @@ -216,7 +227,7 @@ changePermissions "$path" "$file" "$directoryPermissions" fi else - printf "*** %s/%s is neither a file nor a directory! Doing nothing. ***\n" "$path" "$file" + printf "*** %s%s is neither a file nor a directory! Doing nothing. ***\n" "$path" "$file" return 1 fi return 0 @@ -234,7 +245,7 @@ local file=$2 local result="EMPTY" - result=`file -b $path/$file` + result=`file -b $path$file` if [[ $result = *script* ]] then FUNCTION_RESULT="script" @@ -322,7 +333,7 @@ fi printf "$script is setting the file permissions...\n" -### TODO need to parse directory structure into a temporary file and parse by reading that file +IFS=$'\n' for File in `ls --almost-all --recursive --escape /home/${user}/` do if [[ "$File" = *: ]] @@ -332,9 +343,9 @@ then printf "Examining directory %s\n" "$Path" fi - continue + modifyFileTypePermissions "$Path" "" else - modifyFileTypePermissions "$Path" "$File" + modifyFileTypePermissions "$Path/" "${File//\\}" fi done printf "$script is done setting permissions.\n"