#!/bin/sh
#
# postinst script for the Debian GNU/Linux r-base-core package
# This version originally written by Douglas Bates <bates@stat.wisc.edu>

set -e

#DEBHELPER#
    
    
case "$1" in
    configure)
	#if [ -x /usr/bin/paperconf ]
	#then
	#    perl -pi -e \
	#    '$P=`/usr/bin/paperconf`,chop $P,s:a4:$P: if /{R_PAPERSIZE/' /usr/bin/R
	#fi
    
	# edd 19 June 2004  deal with papersize 
        # edd 22 June 2004  make that conditional on paperconf
	if [ -x /usr/bin/paperconf ]
	then
	    #Sysfile=`/etc/papersize`
	    #syspaper=`cat $Sysfile`
	    syspaper=`/usr/bin/paperconf`
	    #echo "Papersize in /etc is $syspaper"
	    Rfile=/etc/R/Renviron
	    rpaper=`grep ^R_PAPERSIZE $Rfile | cut -d"'" -f2`
	    #echo "Papersize in Renviron is $rpaper"
	    if [ "$syspaper" != "$rpaper" ] 
	    then
		echo "Changing R_PAPERSIZE from $rpaper with $syspaper"
		perl -p -i -e "s|\'$rpaper\'|\'$syspaper\'|"    "$Rfile"
	    fi
	fi
	

	if [ -x /usr/bin/update-menus ] 
	then 
	    update-menus 
	fi

	# edd 03 Apr 2003  cf Section 10.1.2 of Debian Policy
	if [ ! -e /usr/local/lib/R ]
	then
	    if mkdir /usr/local/lib/R 2>/dev/null
	    then 
		chown root:staff /usr/local/lib/R
		chmod 2775 /usr/local/lib/R
	    fi
	fi
	if [ ! -e /usr/local/lib/R/site-library ]
	then
	    if mkdir /usr/local/lib/R/site-library 2>/dev/null
	    then 
		chown root:staff /usr/local/lib/R/site-library
		chmod 2775 /usr/local/lib/R/site-library
	    fi
	fi
    ;;
    abort-upgrade|abort-remove|abort-deconfigure)
    ;;
    *)
	echo "postinst called with unknown argument \`$1'" >&2
    ;;
esac
