
# 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 <http://www.gnu.org/copyleft/gpl.txt>.
# 
# 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 (LICENSE file in archive) for more details.
#
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# A bourne shell function used by rcf; a very secure, fast, and complete
# firewall for linux <http://jsmoriss.mvlan.net/linux/rcf.html>.
#
# In the upgrade from RCF 5.2 to 5.2.1 the contrib directory for
# firewall modules was removed. 
# This little script checks whether a module in the old (deprecated)
# contrib directory is in use or not (by checking if there's a link to
# it). If so, it copies the module to the common directory and creates
# a new link to it.
#
# Because of the use of find (with the -type parameter), this will not
# work on most LRP distro's. :-(
#
#-----------------------------------------------------------------------
# FUNCTION
#-----------------------------------------------------------------------

Contrib_Migration() {

if [ -d "$PREFIX/modules/contrib" ]
then
	echo "Moving modules from the (deprecated) contrib directory..."

	for k in block-remote-ports online-games port-forwarding services
	do
		for j in public private
		do
			if cd "$PREFIX/modules/contrib/$k" 2>/dev/null
			then
				for i in *
				do
					if [ "`find \"../../$j/$k/$i\" -type l 2>/dev/null`" ]
					then
						echo " Found module $j/$k/$i in use"
						cd "../../$j/$k"
						echo "  Copying module from contrib to common"
						cp "../../contrib/$k/$i" "../../common/$k"
						echo "  Creating new link"
						rm -f "./$i"
						ln -s "../../common/$k/$i"
					fi
				done
				rmdir "$PREFIX/modules/contrib/$k" 2>/dev/null
			fi
		done
	done
	unset i j k
	rmdir "$PREFIX/modules/contrib" 2>/dev/null
fi

}
