#!/bin/sh
changemod ()
{
if [ -d $filepath ]; then
cd $filepath
for var in `ls -tr`
do
changefilemod $var
done
return 0
else
if [ -f $filepath ]; then
changefilemod $filepath
return $?
else
return -1
fi
fi
}
changefilemod()
{
filename="$1"
if [ -n $filename -a $filename != "chmod.sh" ]; then
chmod $mode $filename
return 0
else
return -1
fi
}
handelfilepath()
{
if [ -z $filepath ] || [ $filepath = "null" ]; then
filepath=`pwd`
fi
}
handelmode()
{
if [ -z $mode ]; then
mode="744"
fi
}
checkparams()
{
paramnumber=$1
if [ $paramnumber -eq 1 ];then
echo "your params is error you can user this shell like this ./chmod.sh or ./chmod null 774 "
return -1
else
return 0
fi
}
#################################################################
#main
#################################################################
filepath=$1
mode=$2
checkparams $#
if [ $? -ne 0 ];then
exit 1
fi
handelfilepath
handelmode
changemod
resultCode=$?
if [ $resultCode -eq "0" ]; then
echo "change mode ok"
else
echo "change mode fail....."
fi