FIxing problem with spaces in file/directory names.
This commit is contained in:
parent
9e60c2e4c2
commit
1d6ef2a17f
1 changed files with 26 additions and 15 deletions
|
@ -3,7 +3,7 @@
|
|||
# Script checking the right permissions for software installations:
|
||||
# Ordinary files must at least have permissions 664 and directories 755.
|
||||
#
|
||||
# Copyright (c) 2010-2015 Christoph Niethammer <niethammer@hlrs.de>
|
||||
# Copyright (c) 2010-2016 Christoph Niethammer <niethammer@hlrs.de>
|
||||
#
|
||||
|
||||
declare -r APP_NAME="${0##*/}"
|
||||
|
@ -46,10 +46,11 @@ function die {
|
|||
|
||||
function file_add_perm() {
|
||||
local perm=$1
|
||||
local oldperm=$(stat -c %a $file)
|
||||
local filename=$2
|
||||
shift
|
||||
local filename="$@"
|
||||
local oldperm=$(stat -c '%a' "${filename[@]}")
|
||||
local newperm="$(( ${oldperm:0:1} | ${perm:0:1} ))$(( ${oldperm:1:1} | ${perm:1:1} ))$(( ${oldperm:2:1} | ${perm:2:1} ))"
|
||||
chmod $newperm $filename
|
||||
chmod $newperm "${filename[@]}"
|
||||
}
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
|
@ -88,42 +89,52 @@ for arg in $@; do
|
|||
esac
|
||||
done
|
||||
|
||||
declare -a WRONG_DIRS
|
||||
declare -a WRONG_FILES
|
||||
echo "# Searching for directories which do not match '$DIR_PERMS' ..."
|
||||
WRONG_DIRS=(`find $SEARCH_DIRS -type d ! -perm $DIR_PERMS -print`)
|
||||
echo "# Searching for files which do not match at least '$FILE_PERMS' ..."
|
||||
WRONG_FILES=(`find $SEARCH_DIRS -type f ! -perm -$FILE_PERMS -print`)
|
||||
while IFS= read -r -d '' n; do
|
||||
WRONG_DIRS+=( $n )
|
||||
done < <(find $SEARCH_DIRS -type d ! -perm $DIR_PERMS -print0)
|
||||
|
||||
echo "# Searching for files which do not match at least '$FILE_PERMS' ..."
|
||||
while IFS= read -r -d '' n; do
|
||||
WRONG_FILES+=( "$n" )
|
||||
done < <(find $SEARCH_DIRS -type f ! -perm -$FILE_PERMS -print0)
|
||||
for (( i=1; i <= ${#WRONG_FILES[@]}; i++ ))
|
||||
do
|
||||
echo ${WRONG_FILES[$i]}
|
||||
done
|
||||
|
||||
if [[ $PRINT_DIRS -eq 1 ]]; then
|
||||
echo "# ** directories with wrong permissions:"
|
||||
for dir in ${WRONG_DIRS[@]}; do
|
||||
for dir in "${WRONG_DIRS[@]}"; do
|
||||
if [[ $FIX_PERMISSIONS -eq 1 ]]; then
|
||||
echo -en "$dir\t\t$(stat -c "%a" $dir)"
|
||||
if chmod $DIR_PERMS $dir ; then
|
||||
echo -en "$dir\t\t"$(stat -c '%a' "$dir")
|
||||
if chmod $DIR_PERMS "$dir" ; then
|
||||
NUM_FIXED_DIR_PERMISSIONS=$(($NUM_DIRD_FILE_PERMISSIONS + 1))
|
||||
echo " ... (fixed)"
|
||||
else
|
||||
echo " ... (not fixed)"
|
||||
fi
|
||||
else
|
||||
echo -e "$dir\t\t$(stat -c "%a" $dir)"
|
||||
echo -e "$dir\t\t$(stat -c '%a' \"$dir\")"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $PRINT_FILES -eq 1 ]]; then
|
||||
echo "# ** files with wrong permissions:"
|
||||
for file in ${WRONG_FILES[@]}; do
|
||||
for file in "${WRONG_FILES[@]}"; do
|
||||
if [[ $FIX_PERMISSIONS -eq 1 ]]; then
|
||||
echo -en "'$file'\t\t$(stat -c "%a" $file)"
|
||||
if file_add_perm $FILE_PERMS $file ; then
|
||||
echo -en "$file\t\t"$(stat -c '%a' "$file")
|
||||
if file_add_perm $FILE_PERMS "$file" ; then
|
||||
NUM_FIXED_FILE_PERMISSIONS=$(($NUM_FIXED_FILE_PERMISSIONS + 1))
|
||||
echo " ... (fixed)"
|
||||
else
|
||||
echo " ... (not fixed)"
|
||||
fi
|
||||
else
|
||||
echo -e "$file\t\t$(stat -c "%a" $file)"
|
||||
echo -e "$file\t\t$(stat -c '%a' \"$file\")"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue