2011-02-12 03:55:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Script checking the right permissions for software installations:
|
|
|
|
# Ordinary files must at least have permissions 664 and directories 755.
|
|
|
|
#
|
2011-03-04 15:35:09 +00:00
|
|
|
# Christoph Niethammer <niethammer@hlrs.de> (C) 2010-2011
|
2011-02-12 03:55:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
declare -r APP_NAME="${0##*/}"
|
|
|
|
declare -r VERSION="0.8"
|
|
|
|
declare SEARCH_DIRS=
|
|
|
|
declare VERBOSE=0
|
|
|
|
declare PRINT_FILES=0
|
|
|
|
declare PRINT_DIRS=0
|
2012-03-06 09:50:10 +00:00
|
|
|
declare -r FILE_PERMS=664
|
|
|
|
declare -r DIR_PERMS=775
|
2011-02-12 03:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
function print_usage {
|
|
|
|
|
|
|
|
binary=`basename $0`
|
|
|
|
cat <<EOF
|
|
|
|
${APP_NAME}: (${VERSION})
|
|
|
|
|
2011-03-04 15:35:09 +00:00
|
|
|
Copyright (C) 2010-2011 Christoph Niethammer <niethammer@hlrs.de>
|
2011-02-12 03:55:14 +00:00
|
|
|
|
|
|
|
Usage: $APP_NAME DIR
|
|
|
|
|
|
|
|
-h, --help Print this usage
|
|
|
|
-v, --verbose Be more verbose (print list of found directories and files)
|
|
|
|
|
|
|
|
Checks permissions in the given directories. Permissions for files must be
|
|
|
|
at least set to 664 and for directories must be exactly 775.
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function die {
|
|
|
|
echo $1
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
for arg in $@; do
|
|
|
|
case $arg in
|
|
|
|
--help|-h)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--verbose|-v)
|
|
|
|
VERBOSE=1
|
|
|
|
PRINT_FILES=1
|
|
|
|
PRINT_DIRS=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [[ ! -d $arg ]]; then
|
|
|
|
echo "# Skipped $arg"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
SEARCH_DIRS+="${IFS}${arg}"
|
|
|
|
#echo "# Added $arg"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "# Searching for directories which do not match '$DIR_PERMS' ..."
|
2012-03-06 09:50:10 +00:00
|
|
|
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`)
|
2011-02-12 03:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
if [[ $PRINT_FILES -eq 1 ]]; then
|
|
|
|
echo "# ** directories with wrong permissions:"
|
|
|
|
for dir in ${WRONG_DIRS[@]}; do
|
2012-03-06 09:50:10 +00:00
|
|
|
echo -e "$dir\t\t$(stat -c "%a" $dir)"
|
2011-02-12 03:55:14 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "# ** files with wrong permissions:"
|
|
|
|
for file in ${WRONG_FILES[@]}; do
|
2012-03-06 09:50:10 +00:00
|
|
|
echo -e "$file\t\t$(stat -c "%a" $file)"
|
2011-02-12 03:55:14 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "#"
|
|
|
|
echo "# ------------------------------"
|
|
|
|
echo "# Summary:"
|
|
|
|
echo "# directories with wrong permissions: ${#WRONG_DIRS[@]}"
|
|
|
|
echo "# files with wrong permissions: ${#WRONG_FILES[@]}"
|
|
|
|
echo "# ------------------------------"
|
|
|
|
echo "#"
|
|
|
|
|
|
|
|
# clean up temporary files
|
|
|
|
#rm $WRONG_DIR_FILE
|
|
|
|
#rm $WRONG_FILES_FILE
|