PageRenderTime 27ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/osxfuse/osxfuse
Shell | 281 lines | 212 code | 30 blank | 39 comment | 32 complexity | b8db394edd557e7d5388be35b9e8f97e 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 "OSXFUSE 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/bin/* | \
  33. "$INSTALL_VOLUME"/./usr/local/lib/* | \
  34. "$INSTALL_VOLUME"/./usr/local/include/* | \
  35. "$INSTALL_VOLUME"/./Library/Extensions/osxfusefs.kext | \
  36. "$INSTALL_VOLUME"/./Library/Extensions/osxfusefs.kext/* | \
  37. "$INSTALL_VOLUME"/./Library/Filesystems/osxfusefs.fs | \
  38. "$INSTALL_VOLUME"/./Library/Filesystems/osxfusefs.fs/* | \
  39. "$INSTALL_VOLUME"/./Library/Frameworks/OSXFUSE.framework | \
  40. "$INSTALL_VOLUME"/./Library/Frameworks/OSXFUSE.framework/* | \
  41. "$INSTALL_VOLUME"/./Library/Application\ Support/Developer/Shared/Xcode/Project\ Templates/* | \
  42. "$INSTALL_VOLUME"/Library/Receipts/OSXFUSE.pkg | \
  43. "$INSTALL_VOLUME"/Library/Receipts/OSXFUSE.pkg/* | \
  44. "$INSTALL_VOLUME"/Library/Receipts/OSXFUSECore.pkg | \
  45. "$INSTALL_VOLUME"/Library/Receipts/OSXFUSECore.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. 9*)
  150. BOMFILE_CORE="$INSTALL_VOLUME/Library/Receipts/boms/com.github.osxfuse.pkg.Core.bom"
  151. BOMFILE_PREFPANE="$INSTALL_VOLUME/Library/Receipts/boms/com.github.osxfuse.pkg.PrefPane.bom"
  152. BOMFILE_MACFUSE="$INSTALL_VOLUME/Library/Receipts/boms/com.google.macfuse.core.bom"
  153. ;;
  154. 10*|11*)
  155. BOMFILE_CORE="$INSTALL_VOLUME/var/db/receipts/com.github.osxfuse.pkg.Core.bom"
  156. BOMFILE_PREFPANE="$INSTALL_VOLUME/var/db/receipts/com.github.osxfuse.pkg.PrefPane.bom"
  157. BOMFILE_MACFUSE="$INSTALL_VOLUME/var/db/receipts/com.google.macfuse.core.bom"
  158. ;;
  159. esac
  160. # Make sure the INSTALL_VOLUME is ok.
  161. if [ ! -d "$INSTALL_VOLUME" ]; then
  162. log "Install volume '$INSTALL_VOLUME' is not a directory."
  163. exit 2
  164. fi
  165. # Make sure that OSXFUSE Core is installed and the bom file is present.
  166. /usr/sbin/pkgutil --pkg-info com.github.osxfuse.pkg.Core > /dev/null 2>&1
  167. if [ $? -ne 0 ]
  168. then
  169. log "It appears that OSXFUSE Core is not installed."
  170. exit 3
  171. fi
  172. if [ ! -f "$BOMFILE_CORE" ]
  173. then
  174. log "Can not find bom file for OSXFUSE Core package."
  175. exit 4
  176. fi
  177. # 1. Try to unload the kext if possible. Best effort, so ignore errors.
  178. kextunload -b com.github.osxfuse.filesystems.osxfusefs > /dev/null 2>&1
  179. # 2. Remove MacFUSE compatibility layer
  180. if [ -f "$BOMFILE_MACFUSE" ]
  181. then
  182. if /usr/bin/lsbom "$BOMFILE_MACFUSE" | grep libmacfuse > /dev/null
  183. then
  184. `dirname "$0"`/uninstall-macfuse-core.sh
  185. fi
  186. fi
  187. # 3. Remove files and symlinks
  188. OLD_IFS="$IFS"
  189. IFS=$'\n'
  190. for x in `/usr/bin/lsbom -slf "$BOMFILE_CORE"`
  191. do
  192. remove_file "$INSTALL_VOLUME/$x"
  193. if [ $? -ne 0 ]
  194. then
  195. IS_BOTCHED_UNINSTALL=1
  196. fi
  197. done
  198. if [ -e "$BOMFILE_PREFPANE" ]
  199. then
  200. for x in `/usr/bin/lsbom -slf "$BOMFILE_PREFPANE"`
  201. do
  202. remove_file "$INSTALL_VOLUME/$x"
  203. if [ $? -ne 0 ]
  204. then
  205. IS_BOTCHED_UNINSTALL=1
  206. fi
  207. done
  208. fi
  209. IFS="$OLD_IFS"
  210. # 4. Remove autoinstaller
  211. remove_file "$INSTALL_VOLUME/./Library/Filesystems/osxfusefs.fs/Support/autoinstall-osxfuse-core"
  212. # 5. Remove the directories
  213. OLD_IFS="$IFS"
  214. IFS=$'\n'
  215. for x in `/usr/bin/lsbom -sd "$BOMFILE_CORE" | /usr/bin/sort -r`
  216. do
  217. remove_dir "$INSTALL_VOLUME/$x"
  218. if [ $? -ne 0 ]
  219. then
  220. IS_BOTCHED_UNINSTALL=1
  221. fi
  222. done
  223. for x in `/usr/bin/lsbom -sd "$BOMFILE_PREFPANE" | /usr/bin/sort -r`
  224. do
  225. remove_dir "$INSTALL_VOLUME/$x"
  226. if [ $? -ne 0 ]
  227. then
  228. IS_BOTCHED_UNINSTALL=1
  229. fi
  230. done
  231. IFS="$OLD_IFS"
  232. # 6. Remove the Receipt.
  233. if [ $IS_BOTCHED_UNINSTALL -eq 0 ]
  234. then
  235. /usr/sbin/pkgutil --forget com.github.osxfuse.pkg.Core
  236. if [ $? -ne 0 ]
  237. then
  238. IS_BOTCHED_UNINSTALL=1
  239. fi
  240. if [ -e "$BOMFILE_PREFPANE" ]
  241. then
  242. /usr/sbin/pkgutil --forget com.github.osxfuse.pkg.PrefPane
  243. if [ $? -ne 0 ]
  244. then
  245. IS_BOTCHED_UNINSTALL=1
  246. fi
  247. fi
  248. # Best effort remove of OSXFUSE.pkg.
  249. /usr/sbin/pkgutil --forget com.github.osxfuse.pkg.OSXFUSE
  250. fi
  251. exit $IS_BOTCHED_UNINSTALL