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