linux下svn中限制上传文件大小的hooks
Bash
#!/bin/bash
# PRE-COMMIT HOOK
export.UTF-8
REPOS="$1"
TXN="$2"
SVNLOOK="/usr/bin/svnlook"
files=`$SVNLOOK changed -t $TXN $REPOS|awk '{print $2}'`
for f in $files
do
##这里可以加入判断路径
if [[ $f =~ *test* ]]
then
file_size=`$SVNLOOK cat -t $TXN $REPOS $f | wc -c`
file_type=`echo ${f##*.}`
echo "file_size:$file_size file_type:$file_type">>/root/svn.txt
case $file_type in
"jpg"|"png"|"wdp")
if [ $file_size -gt 1024 ]
then
echo "New file $f is too large,please check it!" 1>&2
exit 2
fi
;;
"pak")
if [ $filesize -gt 102400 ]
then
echo "New file $f is too large,please check it!" 1>&2
exit 2
fi
;;
esac
fi
done
exit 0