#! /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 /NextApps/Mail.app/) then
    echo must be able to write into /NextApps/Mail.app/
    exit 1
endif
if (! -w /NextApps/Mail.app/English.lproj/) then
    echo it would be nice to be able to write into /NextApps/Mail.app/English.lproj/
endif
if (! -e /NextApps/Mail.app/MailFetch-0) then
    echo PriorityMailFetch 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 /NextApps/Mail.app/.MailFetch-backup | grep -i -s charles_oei
    set whatStatus = $status
    set stockRestoreError=0
    if ((-e /NextApps/Mail.app/.MailFetch-backup) && ($whatStatus)) then
	if (-e /NextApps/Mail.app/English.lproj/.info-backup.nib)
	    mv /NextApps/Mail.app/English.lproj/.info-backup.nib \
		/NextApps/Mail.app/English.lproj/info.nib >& /dev/null
	    mv /NextApps/Mail.app/English.lproj/info-0.nib /tmp/.info-0.nib.$$
	else
	    mv /NextApps/Mail.app/English.lproj/info-0.nib \
		/NextApps/Mail.app/English.lproj/info.nib >& /dev/null
	endif
	chmod 444 /NextApps/Mail.app/English.lproj/info.nib
	mv /NextApps/Mail.app/MailFetch /tmp/.mailFetch.$$
	mv /NextApps/Mail.app/.MailFetch-backup /NextApps/Mail.app/MailFetch
	/etc/chown 0.0 /NextApps/Mail.app/MailFetch \
	    /NextApps/Mail.app/English.lproj/info.nib
	chmod 555 /NextApps/Mail.app/MailFetch
	echo /NextApps/Mail.app/MailFetch is restored to stock 2.0 conditions
    else
	echo 'cannot restore /NextApps/Mail.app/MailFetch'
	echo 'get a fresh one from a stock 2.0 release disk'
	echo 'make sure the permissions are at least...'
	echo '[# /bin/chmod 555 /NextApps/Mail.app/MailFetch ]'
	echo ''
	set stockRestoreError=1
    endif
    if ($stockRestoreError) exit 1
    echo proper restoration from stock 2.0 configuration successful
    exit 0
endif
if (! -e /NextApps/Mail.app/.MailFetch-backup) then
    ln /NextApps/Mail.app/MailFetch-0 /NextApps/Mail.app/.MailFetch-backup
endif
if (! -e /NextApps/Mail.app/English.lproj/.info-backup.nib) then
    ln /NextApps/Mail.app/English.lproj/info-0.nib \
	/NextApps/Mail.app/English.lproj/.info-backup.nib
endif
mv /NextApps/Mail.app/MailFetch-0 /NextApps/Mail.app/MailFetch
mv /NextApps/Mail.app/English.lproj/info-0.nib \
    /NextApps/Mail.app/English.lproj/info.nib >& /dev/null
/etc/chown 0.0 /NextApps/Mail.app/MailFetch \
    /NextApps/Mail.app/English.lproj/info.nib
chmod 444 /NextApps/Mail.app/English.lproj/info.nib
chmod 555 /NextApps/Mail.app/MailFetch
echo PriorityMailFetch is removed
exit 0
