PageRenderTime 78ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2006 Google. All Rights Reserved.
  4. #
  5. # Uninstalls the "MacFUSE Core.pkg".
  6. INSTALL_VOLUME="/"
  7. LOG_SYSLOG=1
  8. LOG_STDOUT=1
  9. function log() {
  10. local msg="$1"
  11. if [ $LOG_SYSLOG -eq 1 ]
  12. then
  13. syslog -l Notice -s "MacFUSE Uninstaller: $msg"
  14. fi
  15. if [ $LOG_STDOUT -eq 1 ]
  16. then
  17. echo "MacFUSE Uninstaller: $msg"
  18. fi
  19. }
  20. PACKAGE_RECEIPT="$INSTALL_VOLUME/Library/Receipts/MacFUSE Core.pkg"
  21. OUTER_PACKAGE_RECEIPT="$INSTALL_VOLUME/Library/Receipts/MacFUSE.pkg"
  22. BOMFILE="$PACKAGE_RECEIPT/Contents/Archive.bom"
  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).
  28. function 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"/./System/Library/Filesystems/fusefs.fs | \
  42. "$INSTALL_VOLUME"/./System/Library/Filesystems/fusefs.fs/* | \
  43. "$INSTALL_VOLUME"/./Library/Frameworks/MacFUSE.framework | \
  44. "$INSTALL_VOLUME"/./Library/Frameworks/MacFUSE.framework/* | \
  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. return 0; # Not allowed!
  54. }
  55. # Remove the given file if it seems "safe" to do so.
  56. function remove_file() {
  57. local path="$1"
  58. is_safe_prefix "$path"
  59. local allow=$?
  60. if [ $allow -ne 1 ]
  61. then
  62. # We ignore this file, which is fine.
  63. log "Ignoring file '$path'"
  64. return 0;
  65. fi
  66. if [ \( ! -e "$path" \) -a \( ! -L "$path" \) ]
  67. then
  68. # No longer exists
  69. log "Skipping file: '$path' since it no longer exists."
  70. return 0;
  71. fi
  72. if [ \( ! -f "$path" \) -a \( ! -L "$path" \) ]
  73. then
  74. # This is no longer a file?
  75. log "Skipping file: '$path' since it is no longer a file or symlink?"
  76. return 1;
  77. fi
  78. log "Removing file: '$path'"
  79. rm -f "$path"
  80. }
  81. # Remove the given directory if it seems "safe" to do so. This will only remove
  82. # empty directories.
  83. function remove_dir() {
  84. local path="$1"
  85. is_safe_prefix "$path"
  86. local allow=$?
  87. if [ $allow -ne 1 ]
  88. then
  89. # We ignore this directory.
  90. log "Ignoring dir: '$path'"
  91. return 0;
  92. fi
  93. if [ ! -e "$path" ]
  94. then
  95. # No longer exists
  96. log "Skipping dir: '$path' since it no longer exists."
  97. return 0;
  98. fi
  99. if [ ! -d "$path" ]
  100. then
  101. # Not a directory?
  102. log "Skipping dir: '$path' since it is either gone or no longer a dir."
  103. return 1;
  104. fi
  105. log "Removing dir: '$path'"
  106. rmdir "$path"
  107. }
  108. # Forcefully remove the given directory tree. This is "rm -rf", so use this routine with caution!
  109. function remove_tree() {
  110. local path="$1"
  111. is_safe_prefix "$path"
  112. local allow=$?
  113. if [ $allow -ne 1 ]
  114. then
  115. # We ignore this tree.
  116. log "Ignoring tree: '$path'"
  117. return 0;
  118. fi
  119. if [ ! -e "$path" ]
  120. then
  121. # No longer exists
  122. log "Skipping tree: '$path' since it no longer exists."
  123. return 0;
  124. fi
  125. if [ ! -d "$path" ]
  126. then
  127. # Not a directory?
  128. log "Skipping tree: '$path' since it is not a directory."
  129. return 1;
  130. fi
  131. log "Removing tree: '$path'"
  132. rm -rf "$path"
  133. }
  134. ### MAIN
  135. # Set to 1 if at any point it looks like the uninstall did not proceed
  136. # smoothly. If IS_BOTCHED_UNINSTALL then we don't remove the Receipt.
  137. IS_BOTCHED_UNINSTALL=0
  138. # Do they want quiet mode?
  139. if [ "$1" = "-q" ]
  140. then
  141. LOG_STDOUT=0
  142. fi
  143. # Make sure this script runs as root
  144. if [ "$EUID" -ne 0 ]
  145. then
  146. log "Sudoing..."
  147. sudo $0 "$@"
  148. exit $?
  149. fi
  150. # Make sure the INSTALL_VOLUME is ok.
  151. if [ ! -d "$INSTALL_VOLUME" ]; then
  152. log "Install volume '$INSTALL_VOLUME' is not a directory."
  153. exit 2
  154. fi
  155. # Make sure that MacFUSE Core is installed and the Archive.bom is present.
  156. if [ ! -d "$PACKAGE_RECEIPT" ]
  157. then
  158. log "It appears that MacFUSE Core is not installed."
  159. exit 3
  160. fi
  161. if [ ! -f "$BOMFILE" ]
  162. then
  163. log "Can't find the Archive.bom for MacFUSE Core package."
  164. exit 4
  165. fi
  166. # 1. Try to unload the kext if possible. Best effort, so ignore errors.
  167. kextunload -b com.google.filesystems.fusefs > /dev/null 2>&1
  168. # 2. Remove files and symlinks
  169. OLD_IFS="$IFS"
  170. IFS=$'\n'
  171. for x in `/usr/bin/lsbom -slf "$BOMFILE"`
  172. do
  173. remove_file "$INSTALL_VOLUME/$x"
  174. if [ $? -ne 0 ]
  175. then
  176. IS_BOTCHED_UNINSTALL=1
  177. fi
  178. done
  179. IFS="$OLD_IFS"
  180. # 3. Best effort remove autoinstaller
  181. remove_file "$INSTALL_VOLUME/./System/Library/Filesystems/fusefs.fs/Support/autoinstall-macfuse-core"
  182. # 4. Remove the directories
  183. OLD_IFS="$IFS"
  184. IFS=$'\n'
  185. for x in `/usr/bin/lsbom -sd "$BOMFILE" | /usr/bin/sort -r`
  186. do
  187. remove_dir "$INSTALL_VOLUME/$x"
  188. if [ $? -ne 0 ]
  189. then
  190. IS_BOTCHED_UNINSTALL=1
  191. fi
  192. done
  193. IFS="$OLD_IFS"
  194. # 5. Remove the Receipt.
  195. if [ $IS_BOTCHED_UNINSTALL -eq 0 ]
  196. then
  197. remove_tree "$PACKAGE_RECEIPT"
  198. if [ $? -ne 0 ]
  199. then
  200. IS_BOTCHED_UNINSTALL=1
  201. fi
  202. # Best effort removal of MacFUSE.pkg
  203. remove_tree "$OUTER_PACKAGE_RECEIPT"
  204. fi
  205. exit $IS_BOTCHED_UNINSTALL