#!/bin/sh -e
# Preinst script for openvas-plugins
# (c) 2004-2007 Javier Fernández-Sanguino

PLUGINDIR=/var/lib/openvas/
OPLUGINDIR=/usr/lib/openvas/

# Basicly, check if there is anything 

[ ! -d $OPLUGINDIR ] && exit 0

echo -n "Moving plugins from $OPLUGINDIR to $PLUGINDIR..."
if [ ! -d $PLUGINDIR ] ; then
	mkdir -p $PLUGINDIR
	chown root:root $PLUGINDIR
	chmod 0766 $PLUGINDIR
fi

# Now, we don't care about descriptions, they will be regenerated
[ -d "$OPLUGINDIR/.desc" ] && rm -rf $OPLUGINDIR/.desc
[ ! -d "$PLUGINDIR/.desc" ] && mkdir $PLUGINDIR/.desc

find $OPLUGINDIR -maxdepth 1 -mindepth 1  | 
while read content; do
	base=`basename $content`
	if [ -e "$PLUGINDIR/$base" ]; then
		cp -a "$OPLUGINDIR/$base" $PLUGINDIR
		rm -rf "$OPLUGINDIR/$base"
	else
		mv "$OPLUGINDIR/$base" $PLUGINDIR
	fi
done
			

echo ".done"

#DEBHELPER#

exit 0
