Mercurial > ufpm
changeset 4:1009f603958e
Enhancement: processes directories and file names that contain spaces.
Bug fix: directories did not have permissions changed.
author | John Schneiderman <JohnMS@CodeGNU.com> |
---|---|
date | Wed, 17 Mar 2010 05:59:00 +0000 |
parents | 3cdee66547d0 |
children | 94d705d506f9 |
files | ufpm.sh |
diffstat | 1 files changed, 26 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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"