#!/bin/sh

# mozpluggerrc-sanitize 1.0.1.
# sanitize the mozpluggerrc script according to which plugin package
# is installed.
# (written by Giuseppe Ghib <ghibo@mandriva.com>).

cp -fp /etc/mozpluggerrc.default /etc/mozpluggerrc

# Acrobat Reader plugin nppdf.so handles
# "application/x-pdf" and "application/pdf" mime types.
if rpm --quiet -q acroread-nppdf || \
	[ -f "/usr/lib64/mozilla/plugins/nppdf.so" ]; then
	echo "Warning, due to a bug in acroread 5.0.X, using the nppdf.so plugin"
	echo "might lead to X process to consume 100% CPU. It's advised to remove"
	echo "acroread-nppdf RPM package or the nppdf.so file to let"
	echo "mozplugger handle acroread calls instead." 
	/usr/bin/disable_mozmimetypes /etc/mozpluggerrc \
		application/pdf application/x-pdf
	touch /usr/lib64/mozilla/plugins/mozplugger.so
fi

# Mplayerplugin supports mplayer playlists
if rpm --quiet -q mplayerplugin || \
	[ -f "/usr/lib64/mozilla/plugins/mplayerplug-in.so" ]; then
	/usr/bin/disable_mozmimetypes /etc/mozpluggerrc \
		application/x-drm-v2 \
		application/x-mplayer2 \
		application/x-ogg \
		application/x-quicktimeplayer \
		audio/ogg \
		audio/wav \
		audio/x-ms-wax \
		audio/x-ms-wma \
		audio/x-wav \
		video/anim \
		video/dl \
		video/fli \
		video/mp4 \
		video/mpeg \
		video/msvideo \
		video/quicktime \
		video/sgi-movie \
		video/x-anim \
		video/x-dl \
		video/x-fli \
		video/x-mpeg \
		video/x-mpeg2 \
		video/x-ms-asf \
		video/x-ms-asf-plugin \
		video/x-msvideo \
		video/x-ms-wm \
		video/x-ms-wmv \
		video/x-ms-wvx \
		image/x-macpaint \
		video/x-quicktime \
		video/x-sgi-movie
	touch /usr/lib64/mozilla/plugins/mozplugger.so
fi

# RealPlayer plugin supports only
# audio/x-pn-realaudio-plugin mime type
if rpm --quiet -q RealPlayer-rpnp || \
	[ -f "/usr/lib64/mozilla/plugins/nphelix.so" -o -f "/usr/lib64/mozilla/plugins/rpnp.so" ]; then
	/usr/bin/disable_mozmimetypes /etc/mozpluggerrc \
		audio/x-pn-realaudio-plugin
	touch /usr/lib64/mozilla/plugins/mozplugger.so
fi

# Check version of gv
if rpm --quiet -q gv; then
	GV_VERSION=`rpm -q --queryformat "%{VERSION}" gv | sed -e "s/\.//g"`
	if [ $GV_VERSION -ge 361 ]; then
		if grep -q  "gv -safer -quiet -antialias" /etc/mozpluggerrc; then
		        perl -pi -e "s/gv -safer -quiet -antialias/gv --safer --quiet --antialias/g" /etc/mozpluggerrc
		fi
	else
		if grep "gv --safer --quiet --antialias" /etc/mozpluggerrc; then
	        	perl -pi -e "s/gv --safer --quiet --antialias/gv -safer -quiet -antialias/g" /etc/mozpluggerrc
		fi
	fi
fi
