PageRenderTime 81ms CodeModel.GetById 69ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

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

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