Fixed permissions and other cleanup in Mac installer package
[ghc-hetmet.git] / distrib / MacOS / installer-scripts / Uninstaller
1 #!/bin/sh
2
3 # Uninstaller script for GHC.framework 
4 # (currently only for system volume installations)
5
6 INSTALL_DEST=/Library/Frameworks
7 INSTALL_BASE=/
8 if [ ${INSTALL_BASE} = / ]; then
9   INSTALL_BIN=/usr/bin
10 else
11   INSTALL_BIN=${INSTALL_BASE}/bin
12 fi
13
14 if [ ! -x ${INSTALL_DEST}/GHC.framework ]; then
15   echo "${INSTALL_DEST}/GHC.framework does not exit"
16   exit 1
17 fi
18
19 if [ ${USER} != root ]; then
20   echo "GHC.framework installer must be run with admin privileges"
21   echo "Prefix command by 'sudo'"
22   exit 1
23 fi
24
25 VERSIONS=(`ls ${INSTALL_DEST}/GHC.framework/Versions`)
26 NO_VERSIONS=${#VERSIONS[@]}
27
28 if [ ${VERSIONS[${NO_VERSIONS}-1]} != Current ]; then
29   echo "Fatal error: last version should be Current"
30   echo "Found versions: ${VERSIONS[@]}"
31   exit 1
32 fi
33 CURRENT_PHYS=`cd /Library/Frameworks/GHC.framework/Versions/Current; pwd -P`
34 CURRENT=`basename ${CURRENT_PHYS}`
35
36 if [ ${NO_VERSIONS} -ne 2 ]; then
37   echo "Multiple versions of GHC.framework are currently installed."
38   echo "This uninstaller removes GHC.framework entirely and should only"
39   echo "be used if there is exactly one version."
40   echo
41   echo "To remove individual old versions, simply delete the directory"
42   echo "${INSTALL_DEST}/GHC.framework/Versions/VERSION_TO_REMOVE"
43   echo
44   echo "Found versions: ${VERSIONS[@]}(= ${CURRENT})"
45   exit 1
46 fi
47
48 echo "Removing symbolic links into GHC.framework"
49 for thisfile in `ls ${INSTALL_BIN}`; do
50   if ls -l ${INSTALL_BIN}/${thisfile} | grep -q GHC.framework/Versions; then
51     rm -f ${INSTALL_BIN}/${thisfile}
52   fi
53 done
54
55 echo "Removing ${INSTALL_DEST}/GHC.framework"
56 rm -rf ${INSTALL_DEST}/GHC.framework
57
58 echo "Removing package recipt"
59 rm -f /Library/Receipts/boms/org.haskell.glasgowHaskellCompiler.ghc.pkg.bom
60
61 echo "${INSTALL_DEST}/GHC.framework has been purged!"