#! /bin/sh
# preinst script for Xymon

set -e

case "$1" in
    install|upgrade)
	# stop the client when the server is installed
	invoke-rc.d xymon stop || true
	if test "$2" && dpkg --compare-versions "$2" lt 4.2.0.dfsg-2 &&
			test -d /var/lib/xymon/www ; then
		if test -e /etc/logrotate.d/xymon-client && ! test -e /etc/logrotate.d/xymon-client.dpkg-old ; then
			mv /etc/logrotate.d/xymon-client /etc/logrotate.d/xymon-client.dpkg-old
		fi
		# we want to replace directories with symlinks, prod dpkg to do it
		move_dir () {
			test -d "$1" || return
			test -h "$1" && return
			test -e "$1.dpkg-old" && return
			mv "$1" "$1.dpkg-old"
		}
		cd /var/lib/xymon/www
		move_dir gifs
		move_dir help
		move_dir menu
	fi
	#446982
	if test "$2" && dpkg --compare-versions "$2" ge 4.2.0.dfsg-1 &&
			dpkg --compare-versions "$2" lt 4.2.0.dfsg-6 ; then
		chown root:root /tmp
		chmod 1777 /tmp
	fi
	;;
esac

#DEBHELPER#

exit 0
