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:
|
# Script checking the right permissions for software installations:
|
||||||
# Ordinary files must at least have permissions 664 and directories 755.
|
# 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##*/}"
|
declare -r APP_NAME="${0##*/}"
|
||||||
|
@ -46,10 +46,11 @@ function die {
|
||||||
|
|
||||||
function file_add_perm() {
|
function file_add_perm() {
|
||||||
local perm=$1
|
local perm=$1
|
||||||
local oldperm=$(stat -c %a $file)
|
shift
|
||||||
local filename=$2
|
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} ))"
|
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
|
if [ $# -lt 1 ]; then
|
||||||
|
@ -88,42 +89,52 @@ for arg in $@; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
declare -a WRONG_DIRS
|
||||||
|
declare -a WRONG_FILES
|
||||||
echo "# Searching for directories which do not match '$DIR_PERMS' ..."
|
echo "# Searching for directories which do not match '$DIR_PERMS' ..."
|
||||||
WRONG_DIRS=(`find $SEARCH_DIRS -type d ! -perm $DIR_PERMS -print`)
|
while IFS= read -r -d '' n; do
|
||||||
echo "# Searching for files which do not match at least '$FILE_PERMS' ..."
|
WRONG_DIRS+=( $n )
|
||||||
WRONG_FILES=(`find $SEARCH_DIRS -type f ! -perm -$FILE_PERMS -print`)
|
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
|
if [[ $PRINT_DIRS -eq 1 ]]; then
|
||||||
echo "# ** directories with wrong permissions:"
|
echo "# ** directories with wrong permissions:"
|
||||||
for dir in ${WRONG_DIRS[@]}; do
|
for dir in "${WRONG_DIRS[@]}"; do
|
||||||
if [[ $FIX_PERMISSIONS -eq 1 ]]; then
|
if [[ $FIX_PERMISSIONS -eq 1 ]]; then
|
||||||
echo -en "$dir\t\t$(stat -c "%a" $dir)"
|
echo -en "$dir\t\t"$(stat -c '%a' "$dir")
|
||||||
if chmod $DIR_PERMS $dir ; then
|
if chmod $DIR_PERMS "$dir" ; then
|
||||||
NUM_FIXED_DIR_PERMISSIONS=$(($NUM_DIRD_FILE_PERMISSIONS + 1))
|
NUM_FIXED_DIR_PERMISSIONS=$(($NUM_DIRD_FILE_PERMISSIONS + 1))
|
||||||
echo " ... (fixed)"
|
echo " ... (fixed)"
|
||||||
else
|
else
|
||||||
echo " ... (not fixed)"
|
echo " ... (not fixed)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "$dir\t\t$(stat -c "%a" $dir)"
|
echo -e "$dir\t\t$(stat -c '%a' \"$dir\")"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $PRINT_FILES -eq 1 ]]; then
|
if [[ $PRINT_FILES -eq 1 ]]; then
|
||||||
echo "# ** files with wrong permissions:"
|
echo "# ** files with wrong permissions:"
|
||||||
for file in ${WRONG_FILES[@]}; do
|
for file in "${WRONG_FILES[@]}"; do
|
||||||
if [[ $FIX_PERMISSIONS -eq 1 ]]; then
|
if [[ $FIX_PERMISSIONS -eq 1 ]]; then
|
||||||
echo -en "'$file'\t\t$(stat -c "%a" $file)"
|
echo -en "$file\t\t"$(stat -c '%a' "$file")
|
||||||
if file_add_perm $FILE_PERMS $file ; then
|
if file_add_perm $FILE_PERMS "$file" ; then
|
||||||
NUM_FIXED_FILE_PERMISSIONS=$(($NUM_FIXED_FILE_PERMISSIONS + 1))
|
NUM_FIXED_FILE_PERMISSIONS=$(($NUM_FIXED_FILE_PERMISSIONS + 1))
|
||||||
echo " ... (fixed)"
|
echo " ... (fixed)"
|
||||||
else
|
else
|
||||||
echo " ... (not fixed)"
|
echo " ... (not fixed)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "$file\t\t$(stat -c "%a" $file)"
|
echo -e "$file\t\t$(stat -c '%a' \"$file\")"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue