PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/osxfuse/osxfuse
Shell | 224 lines | 162 code | 27 blank | 35 comment | 23 complexity | 4d8c67025a4a916411c03fffdb5a7140 MD5 | raw file
Possible License(s): BSD-3-Clause
  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 "OSXFUSE Uninstaller: $msg"
  14. fi
  15. if [ $LOG_STDOUT -eq 1 ]
  16. then
  17. echo "OSXFUSE 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 OSXFUSE.
  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/lib/* | \
  33. "$INSTALL_VOLUME"/./Library/Frameworks/MacFUSE.framework | \
  34. "$INSTALL_VOLUME"/./Library/Frameworks/MacFUSE.framework/* | \
  35. "$INSTALL_VOLUME"/Library/Receipts/OSXFUSEMacFUSE.pkg | \
  36. "$INSTALL_VOLUME"/Library/Receipts/OSXFUSEMacFUSE.pkg/*)
  37. # These are all ok to process.
  38. return 1;
  39. ;;
  40. esac
  41. return 0; # Not allowed!
  42. }
  43. # Remove the given file if it seems "safe" to do so.
  44. function remove_file() {
  45. local path="$1"
  46. is_safe_prefix "$path"
  47. local allow=$?
  48. if [ $allow -ne 1 ]
  49. then
  50. # We ignore this file, which is fine.
  51. log "Ignoring file '$path'"
  52. return 0;
  53. fi
  54. if [ \( ! -e "$path" \) -a \( ! -L "$path" \) ]
  55. then
  56. # No longer exists
  57. log "Skipping file: '$path' since it no longer exists."
  58. return 0;
  59. fi
  60. if [ \( ! -f "$path" \) -a \( ! -L "$path" \) ]
  61. then
  62. # This is no longer a file?
  63. log "Skipping file: '$path' since it is no longer a file or symlink?"
  64. return 1;
  65. fi
  66. log "Removing file: '$path'"
  67. rm -f "$path"
  68. }
  69. # Remove the given directory if it seems "safe" to do so. This will only remove
  70. # empty directories.
  71. function remove_dir() {
  72. local path="$1"
  73. is_safe_prefix "$path"
  74. local allow=$?
  75. if [ $allow -ne 1 ]
  76. then
  77. # We ignore this directory.
  78. log "Ignoring dir: '$path'"
  79. return 0;
  80. fi
  81. if [ ! -e "$path" ]
  82. then
  83. # No longer exists
  84. log "Skipping dir: '$path' since it no longer exists."
  85. return 0;
  86. fi
  87. if [ ! -d "$path" ]
  88. then
  89. # Not a directory?
  90. log "Skipping dir: '$path' since it is either gone or no longer a dir."
  91. return 1;
  92. fi
  93. log "Removing dir: '$path'"
  94. rmdir "$path"
  95. }
  96. # Forcefully remove the given directory tree. This is "rm -rf", so use this routine with caution!
  97. function remove_tree() {
  98. local path="$1"
  99. is_safe_prefix "$path"
  100. local allow=$?
  101. if [ $allow -ne 1 ]
  102. then
  103. # We ignore this tree.
  104. log "Ignoring tree: '$path'"
  105. return 0;
  106. fi
  107. if [ ! -e "$path" ]
  108. then
  109. # No longer exists
  110. log "Skipping tree: '$path' since it no longer exists."
  111. return 0;
  112. fi
  113. if [ ! -d "$path" ]
  114. then
  115. # Not a directory?
  116. log "Skipping tree: '$path' since it is not a directory."
  117. return 1;
  118. fi
  119. log "Removing tree: '$path'"
  120. rm -rf "$path"
  121. }
  122. ### MAIN
  123. # Set to 1 if at any point it looks like the uninstall did not proceed
  124. # smoothly. If IS_BOTCHED_UNINSTALL then we don't remove the Receipt.
  125. IS_BOTCHED_UNINSTALL=0
  126. # Do they want quiet mode?
  127. if [ "$1" = "-q" ]
  128. then
  129. LOG_STDOUT=0
  130. fi
  131. # Make sure this script runs as root
  132. if [ "$EUID" -ne 0 ]
  133. then
  134. log "Sudoing..."
  135. sudo $0 "$@"
  136. exit $?
  137. fi
  138. OS_RELEASE=`/usr/bin/uname -r`
  139. case "$OS_RELEASE" in
  140. 9*)
  141. BOMFILE="$INSTALL_VOLUME/Library/Receipts/boms/com.google.macfuse.core.bom"
  142. ;;
  143. 10*|11*)
  144. BOMFILE="$INSTALL_VOLUME/var/db/receipts/com.google.macfuse.core.bom"
  145. ;;
  146. esac
  147. # Make sure the INSTALL_VOLUME is ok.
  148. if [ ! -d "$INSTALL_VOLUME" ]; then
  149. log "Install volume '$INSTALL_VOLUME' is not a directory."
  150. exit 2
  151. fi
  152. # Make sure that OSXFUSE Core is installed and the Archive.bom is present.
  153. /usr/sbin/pkgutil --pkg-info com.google.macfuse.core > /dev/null 2>&1
  154. if [ $? -ne 0 ]
  155. then
  156. log "It appears that MacFUSE Core is not installed."
  157. exit 3
  158. fi
  159. if [ ! -f "$BOMFILE" ]
  160. then
  161. log "Can not find the bom file for MacFUSE Core package."
  162. exit 4
  163. fi
  164. # 2. Remove files and symlinks
  165. OLD_IFS="$IFS"
  166. IFS=$'\n'
  167. for x in `/usr/bin/lsbom -slf "$BOMFILE"`
  168. do
  169. remove_file "$INSTALL_VOLUME/$x"
  170. if [ $? -ne 0 ]
  171. then
  172. IS_BOTCHED_UNINSTALL=1
  173. fi
  174. done
  175. IFS="$OLD_IFS"
  176. # 4. Remove the directories
  177. OLD_IFS="$IFS"
  178. IFS=$'\n'
  179. for x in `/usr/bin/lsbom -sd "$BOMFILE" | /usr/bin/sort -r`
  180. do
  181. remove_dir "$INSTALL_VOLUME/$x"
  182. if [ $? -ne 0 ]
  183. then
  184. IS_BOTCHED_UNINSTALL=1
  185. fi
  186. done
  187. IFS="$OLD_IFS"
  188. # 5. Remove the Receipt.
  189. if [ $IS_BOTCHED_UNINSTALL -eq 0 ]
  190. then
  191. /usr/sbin/pkgutil --forget com.google.macfuse.core
  192. if [ $? -ne 0 ]
  193. then
  194. IS_BOTCHED_UNINSTALL=1
  195. fi
  196. fi
  197. exit $IS_BOTCHED_UNINSTALL