PageRenderTime 44ms CodeModel.GetById 31ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/core/10.5/packaging/macfuse-core/uninstall-macfuse-core.sh

http://macfuse.googlecode.com/
Shell | 271 lines | 203 code | 29 blank | 39 comment | 29 complexity | eb65b1211f579ee390350a43255b9067 MD5 | raw file
  1#!/bin/sh
  2#
  3# Copyright (C) 2006 Google. All Rights Reserved.
  4#
  5# Uninstalls the "MacFUSE Core.pkg".
  6
  7INSTALL_VOLUME="/"
  8
  9LOG_SYSLOG=1
 10LOG_STDOUT=1
 11function log() {
 12  local msg="$1"
 13  if [ $LOG_SYSLOG -eq 1 ]
 14  then
 15    syslog -l Notice -s "MacFUSE Uninstaller: $msg"
 16  fi
 17  if [ $LOG_STDOUT -eq 1 ]
 18  then
 19    echo "MacFUSE Uninstaller: $msg"
 20  fi
 21}
 22
 23# Check to make sure that operations (such as rm, rmdir) are relatively
 24# safe. This should only allow operations throught that would operate on
 25# stuff installed by MacFUSE.
 26#
 27# Ret: 1 (true) if the prefix is ok to use, otherwise 0 (false).
 28function is_safe_prefix() {
 29  local path="$1"
 30  case "$path" in
 31    "$INSTALL_VOLUME"/./usr/local/lib/pkgconfig)
 32      # We don't try to remove the pkgconfig directory.
 33      return 0;
 34      ;; 
 35    "$INSTALL_VOLUME"/./usr/local/bin/*                        |  \
 36    "$INSTALL_VOLUME"/./usr/local/lib/*                        |  \
 37    "$INSTALL_VOLUME"/./usr/local/include/*                    |  \
 38    "$INSTALL_VOLUME"/./Library/Extensions/fusefs.kext         |  \
 39    "$INSTALL_VOLUME"/./Library/Extensions/fusefs.kext/*       |  \
 40    "$INSTALL_VOLUME"/./Library/Filesystems/fusefs.fs          |  \
 41    "$INSTALL_VOLUME"/./Library/Filesystems/fusefs.fs/*        |  \
 42    "$INSTALL_VOLUME"/./Library/Frameworks/MacFUSE.framework   |  \
 43    "$INSTALL_VOLUME"/./Library/Frameworks/MacFUSE.framework/* |  \
 44    "$INSTALL_VOLUME"/./Library/Application\ Support/Developer/Shared/Xcode/Project\ Templates/* |  \
 45    "$INSTALL_VOLUME"/Library/Receipts/MacFUSE.pkg             |  \
 46    "$INSTALL_VOLUME"/Library/Receipts/MacFUSE.pkg/*           |  \
 47    "$INSTALL_VOLUME"/Library/Receipts/MacFUSE\ Core.pkg       |  \
 48    "$INSTALL_VOLUME"/Library/Receipts/MacFUSE\ Core.pkg/*)
 49      # These are all ok to process.
 50      return 1;
 51      ;;  
 52  esac
 53
 54  return 0;  # Not allowed!
 55}
 56
 57# Remove the given file if it seems "safe" to do so.
 58function remove_file() {
 59  local path="$1"
 60  is_safe_prefix "$path"
 61  local allow=$?
 62  if [ $allow -ne 1 ]
 63  then
 64    # We ignore this file, which is fine.
 65    log "Ignoring file '$path'"
 66    return 0;
 67  fi
 68
 69  if [ \( ! -e "$path" \) -a \( ! -L "$path" \) ]
 70  then
 71    # No longer exists
 72    log "Skipping file: '$path' since it no longer exists."
 73    return 0;
 74  fi
 75
 76  if [ \( ! -f "$path" \) -a \( ! -L "$path" \) ]
 77  then
 78    # This is no longer a file?
 79    log "Skipping file: '$path' since it is no longer a file or symlink?"
 80    return 1;
 81  fi
 82
 83  log "Removing file: '$path'"
 84  rm -f "$path"
 85}
 86
 87# Remove the given directory if it seems "safe" to do so. This will only remove
 88# empty directories.
 89function remove_dir() {
 90  local path="$1"
 91  is_safe_prefix "$path"
 92  local allow=$?
 93  if [ $allow -ne 1 ]
 94  then
 95    # We ignore this directory.
 96    log "Ignoring dir: '$path'"
 97    return 0;
 98  fi
 99
100  if [ ! -e "$path" ]
101  then
102    # No longer exists
103    log "Skipping dir: '$path' since it no longer exists."
104    return 0;
105  fi
106
107  if [ ! -d "$path" ]
108  then
109    # Not a directory?
110    log "Skipping dir: '$path' since it is either gone or no longer a dir."
111    return 1;
112  fi
113
114  log "Removing dir: '$path'"
115  rmdir "$path"
116}
117
118# Forcefully remove the given directory tree. This is "rm -rf", so use this routine with caution!
119function remove_tree() {
120  local path="$1"
121  is_safe_prefix "$path"
122  local allow=$?
123  if [ $allow -ne 1 ]
124  then
125    # We ignore this tree.
126    log "Ignoring tree: '$path'"
127    return 0;
128  fi
129
130  if [ ! -e "$path" ]
131  then
132    # No longer exists
133    log "Skipping tree: '$path' since it no longer exists."
134    return 0;
135  fi
136
137  if [ ! -d "$path" ]
138  then
139    # Not a directory?
140    log "Skipping tree: '$path' since it is not a directory."
141    return 1;
142  fi
143
144  log "Removing tree: '$path'"
145  rm -rf "$path"
146}
147
148### MAIN
149
150# Set to 1 if at any point it looks like the uninstall did not proceed
151# smoothly. If IS_BOTCHED_UNINSTALL then we don't remove the Receipt. 
152IS_BOTCHED_UNINSTALL=0
153
154# Do they want quiet mode?
155if [ "$1" = "-q" ]
156then
157  LOG_STDOUT=0
158fi
159
160# Make sure this script runs as root
161if [ "$EUID" -ne 0 ]
162then
163  log "Sudoing..."
164  sudo $0 "$@"
165  exit $?
166fi
167
168OS_RELEASE=`/usr/bin/uname -r`
169case "$OS_RELEASE" in 
170  8*)
171    log "Incorrect uninstall. Use the Tiger version please."
172    exit 1
173    ;;
174  9*)
175    PACKAGE_RECEIPT="$INSTALL_VOLUME/Library/Receipts/MacFUSE Core.pkg"
176    OUTER_PACKAGE_RECEIPT="$INSTALL_VOLUME/Library/Receipts/MacFUSE.pkg"
177    BOMFILE="$PACKAGE_RECEIPT/Contents/Archive.bom"
178    ;;
179  10*)
180     PACKAGE_RECEIPT=""
181     BOMFILE="$INSTALL_VOLUME/var/db/receipts/com.google.macfuse.core.bom"
182     ;;
183esac
184
185# Make sure the INSTALL_VOLUME is ok.
186if [ ! -d "$INSTALL_VOLUME" ]; then
187  log "Install volume '$INSTALL_VOLUME' is not a directory."
188  exit 2
189fi
190
191# Make sure that MacFUSE Core is installed and the Archive.bom is present.
192if [ ! -z "$PACKAGE_RECEIPT" ]
193then 
194  if [ ! -d "$PACKAGE_RECEIPT" ]
195  then
196    log "It appears that MacFUSE Core is not installed."
197    exit 3
198  fi
199else
200  /usr/sbin/pkgutil --pkg-info com.google.macfuse.core > /dev/null 2>&1
201  if [ $? -ne 0 ]
202  then
203    log "It appears that MacFUSE Core is not installed."
204    exit 3    
205  fi
206fi
207if [ ! -f "$BOMFILE" ]
208then
209  log "Can not find the Archive.bom for MacFUSE Core package."
210  exit 4
211fi
212
213# 1. Try to unload the kext if possible. Best effort, so ignore errors.
214kextunload -b com.google.filesystems.fusefs > /dev/null 2>&1
215
216# 2. Remove files and symlinks
217OLD_IFS="$IFS"
218IFS=$'\n'
219for x in `/usr/bin/lsbom -slf "$BOMFILE"` 
220do
221  remove_file "$INSTALL_VOLUME/$x"
222  if [ $? -ne 0 ]
223  then
224    IS_BOTCHED_UNINSTALL=1
225  fi
226done
227IFS="$OLD_IFS"
228
229# 3. Remove autoinstaller
230remove_file "$INSTALL_VOLUME/./Library/Filesystems/fusefs.fs/Support/autoinstall-macfuse-core"
231
232# 4. Remove the directories
233OLD_IFS="$IFS"
234IFS=$'\n'
235for x in `/usr/bin/lsbom -sd "$BOMFILE" | /usr/bin/sort -r`
236do
237  remove_dir "$INSTALL_VOLUME/$x"
238  if [ $? -ne 0 ]
239  then
240    IS_BOTCHED_UNINSTALL=1
241  fi
242done
243IFS="$OLD_IFS"
244
245# 5. Remove the Receipt.
246if [ $IS_BOTCHED_UNINSTALL -eq 0 ]
247then
248  if [ ! -z "$PACKAGE_RECEIPT" ]
249  then
250    remove_tree "$PACKAGE_RECEIPT"
251    if [ $? -ne 0 ]
252    then
253      IS_BOTCHED_UNINSTALL=1
254    fi
255    # Best effort remove of MacFUSE.pkg
256    if [ ! -z "$OUTER_PACKAGE_RECEIPT" ]
257    then
258      remove_tree "$OUTER_PACKAGE_RECEIPT"
259    fi
260  else 
261    /usr/sbin/pkgutil --forget com.google.macfuse.core
262    if [ $? -ne 0 ]
263    then
264      IS_BOTCHED_UNINSTALL=1
265    fi
266    # Best effort remove of MacFUSE.pkg.
267    /usr/sbin/pkgutil --forget com.google.macfuse
268  fi
269fi
270
271exit $IS_BOTCHED_UNINSTALL