#! /bin/sh

# This is the cygwin preremove script, to be installed in /etc/preremove/Macaulay2.sh
# and to be renamed to /etc/preremove/Macaulay2.sh.done after completion

# This script will be run in a hostile environment by setup.exe, and there is no way
# to test it in advance in the same environment.

cd @prefix@/share/info
for p in @PACKAGES@
do install-info --remove $p.info dir
done

STARTFILE=@prefix@/share/emacs/site-lisp/site-start.el
REGEX="^\(load \"M2-init\.el\" t\)$"
REGEX2="^(load \"M2-init\.el\" t)$"
if [ -f "$STARTFILE" ] && egrep -q "$REGEX" "$STARTFILE"
then i=1
     while true
     do if ln "$STARTFILE" "$STARTFILE".bak.$i 2>/dev/null
	then break
	else i=`expr $i + 1`
	fi
	if [ $i -gt 100 ]
	then echo failed to make backup file for "$STARTFILE" >&2
	     exit 1
	fi
     done
     sed "/$REGEX2/d" <"$STARTFILE" >"$STARTFILE".tmp.$$
     rm "$STARTFILE"
     ln "$STARTFILE".tmp.$$ "$STARTFILE"
     rm "$STARTFILE".tmp.$$
fi
