#!/bin/bash
#
# BulkChmod - to change recursively permissions for files/directories
# Copyright (C) 2008-2009 Samuele ~redShadow~ Santi - http://hackzine.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
VERSION=0.2
DMOD=755
FMOD=644
WPATH=""
CNORMAL="\033[0m"
CBOLD="\033[1;37m"
function lic_intro(){
echo "BulkChmod $VERSION - Copyright (C) 2008-2009 Samuele ~redShadow~ Santi"
echo "http://hackzine.org - http://svn.hackzine.org/misc/scripts/"
echo "This program comes with ABSOLUTELY NO WARRANTY"
echo "This is free software, and you are welcome to redistribute it"
echo "under certain conditions; type '$0 --license' for details."
}
function license(){
echo "BulkChmod - to change recursively permissions for files/directories"
echo "Copyright (C) 2008-2009 Samuele ~redShadow~ Santi - http://hackzine.org"
echo ""
echo "This program is free software: you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation, either version 3 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program. If not, see ."
}
function usage(){
echo -e "${CNORMAL}
--------------------------------------------------------------------------------
${CBOLD}BulkChmod${CNORMAL} - recursive chmoder
--------------------------------------------------------------------------------
${CBOLD}USAGE${CNORMAL}
$0
$0 [[[] ] ]
${CBOLD}COMMANDS${CNORMAL}
--help, -h
Show this help
--license, -l
Show the license
--version, -V
Show the version
${CBOLD}MODES${CNORMAL}
Changes Permission recursively on files/directories.
defines mode to be set for directories
defines mode to be set for files
The modes are the same accepted by chmod(1).
If they're not set, defaults to 755 for directories and 644 for files.
The third parameter, could be used to specify a path while
different to current directory.
${CBOLD}AUTHOR${CNORMAL}
~redShadow~
http://www.hackzine.org
${CBOLD}LICENSE${CNORMAL}
Copyright (C) 2008-2009
This is free software, and you are welcome to redistribute it
under certain conditions; type '$@ --license' for details.
";
}
# HELP
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
usage "$0"
exit
fi
# LICENSE
if [ "$1" == "--license" ] || [ "$1" == "-l" ]; then
license "$0"
exit
fi
# VERSION
if [ "$1" == "--version" ] || [ "$1" == "-V" ]; then
lic_intro "$0"
exit
fi
# Read arguments
if [ "$1" != "" ]; then
DMOD="$1"
fi
shift
if [ "$1" != "" ]; then
FMOD="$1"
fi
shift
# all remainig arguments are used as paths
# WPATH=$@
# CHMOD 'em
echo "Changing modes (${DMOD} for dirs, ${FMOD} for files)."
for C_PATH in "$@"; do
printf "%-40s" " $C_PATH "
find "$C_PATH" -type d -exec chmod $DMOD {} \;
find "$C_PATH" -type f -exec chmod $FMOD {} \;
echo " [ DONE ]"
done
exit 0