#!/bin/sh 
#Squeak plugin user run-able setup script
#Oct 10th, 2002 by John M McIntosh (johnmci@smalltalkconsulting.com
#Tested on os-x 10.1.5 and 10.2
# V1.0.1 Jan 2004, Changes for installation via disk image
# V1.0.2 Feb 25th 2004, ditto the NPSqueakStubCFM because of multiple volume machines

# Originally we installed Squeak into the User or Machine, or Network Preferences Directory
# After Jan 2004 we decide to optionally install in the Application Directory for the State of Maine
# This script attempts to figure out where the Squeakland files were installed,
# then corrects links for the Internet plugin folder, and the desktop.

# v 1.1  April 16th, 2007. JMM macintel, simplify
# V1.1.1 May 4th 2007, Handle case of user only, has no admin rights
# V1.2 June 27th 2008, MIR, remove squeakland completely, switch to etoys


# Remove desktop files

#rm -f ~/Desktop/My\ Squeak
rm -f ~/Desktop/Squeak\ 3.0
osascript -e 'tell application "Finder" to update Desktop'


# If in Applications folder then delete old version in Preference area if found

if [ -w /Applications/Squeakland ]; then
 rm -rf  /Applications/Squeakland
fi

if [ -w /Library/Preferences/Squeak/Internet/SqueakPlugin.image ]; then
  rm -rf  /Library/Preferences/Squeak
fi

if [ -w ~/Library/Internet\ Plug-Ins/NPSqueak.bundle ]; then
  rm -f ~/Library/Internet\ Plug-Ins/NPSqueak.bundle
  rm -f ~/Library/Internet\ Plug-Ins/NPSqueakStubCFM
fi
  
if [ -x ~/Library/Internet\ Plug-Ins/SqueakBrowserPlugin.plugin ]; then
  rm -rf ~/Library/Internet\ Plug-Ins/SqueakBrowserPlugin.plugin
fi

if [ -x ~/Library/Application\ Support/Squeakland/Squeakland.app ]; then
  rm -rf ~/Library/Application\ Support/Squeakland/Squeakland.app
fi

if [ -w ~/Library/Preferences/Squeak/Internet/SqueakPlugin.image ]; then
  squeakOldDeletePath=~/Library/Preferences/Squeak/Internet
  rm -rf ~/Library/Preferences/Squeak/Plugins
  rm -f "$squeakOldDeletePath/mpeg3Plugin"
  rm -rf "$squeakOldDeletePath/mpeg3Plugin.bundle"
  rm -rf "$squeakOldDeletePath/NPSqueak.bundle"
  rm -f "$squeakOldDeletePath/NPSqueakStubCFM"
  rm -f "$squeakOldDeletePath/NS-Squeak VM 3.0"
  rm -rf "$squeakOldDeletePath/prefs"
  rm -f "$squeakOldDeletePath/PrintJobPlugin"
  rm -rf "$squeakOldDeletePath/PrintJobPlugin.bundle"
  rm -f "$squeakOldDeletePath/SetupSqueakForUser.command"
  rm -rf "$squeakOldDeletePath/Squeak 3.0.app"
  rm -f "$squeakOldDeletePath/SqueakPlugin.image"
  rm -rf "$squeakOldDeletePath/KedamaPlugin.bundle"
  rm -rf "$squeakOldDeletePath/LocalePlugin.bundle"
fi

if [ -r /Library/Preferences/Squeak/Internet/SqueakPlugin.image ]; then
 osascript -e 'tell application "Terminal"' -e 'display dialog "Squeakland was found in the /Library/Preference Folder, that is an older version of Squeak and requires you to have your machine administrator to install this newer version of Squeak since you do not have the proper authorizations, click OK to terminate the install" buttons ["OK"]' -e 'end tell'        
 exit 8
fi

exit  0
