#! /bin/csh -f
# C. Oei
set path = ( /usr/ucb /bin /usr/bin )
if (`/usr/ucb/whoami` != 'root') then
    echo must be root
    exit 1
endif
if (! -w /usr/lib/) then
    echo must be able to write into /usr/lib/
    exit 1
endif
if (! -e /usr/lib/sendmail-0) then
    echo PrioritySendmail does not seem to be installed
    echo -n 'shall I try to restore preInstallation configuration (put it back to stock configuration)? (y/n) [n] '
    set x = $<
    if ($x != 'y') exit 1
    what /usr/lib/.sendmail-backup | grep -i -s charles_oei
    set whatStatus = $status
    set stockRestoreError=0
    if ((-e /usr/lib/.sendmail-backup) && ($whatStatus)) then
	rm /usr/lib/sendmail
	mv /usr/lib/.sendmail-backup /usr/lib/sendmail
	/etc/chown 0.0 /usr/lib/sendmail
	chmod 4551 /usr/lib/sendmail
	echo /usr/lib/sendmail is restored to stock 2.0 conditions
    else
	echo 'cannot restore /usr/lib/sendmail'
	echo 'get a fresh one from a stock 2.0 release disk'
	echo 'install w/ the following permissions...'
	echo '	-r-sr-x--x root wheel 81920 Nov 11 17:55 /usr/lib/sendmail*'
	echo '[# /etc/chown 0.0 /usr/lib/sendmail ]'
	echo '[# /bin/chmod 4551 /usr/lib/sendmail ]'
	set stockRestoreError=1
    endif
    if ($stockRestoreError) exit 1
    echo proper restoration from stock 2.0 configuration successful
    exit 0
endif
if (! -e /usr/lib/.sendmail-backup) then
    ln /usr/lib/sendmail-0 /usr/lib/.sendmail-backup >& /dev/null ###
endif
mv /usr/lib/sendmail-0 /usr/lib/sendmail >& /dev/null ###
/etc/chown 0.0 /usr/lib/sendmail
chmod 4551 /usr/lib/sendmail
echo PrioritySendmail is removed
exit 0
