PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/core/packaging/macfuse/Install_resources/postinstall

http://macfuse.googlecode.com/
#! | 203 lines | 183 code | 20 blank | 0 comment | 0 complexity | 636a49c834840fd3bef9471c580dc365 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2008 Google. All Rights Reserved.
  4. #
  5. INSTALL_LOG="/tmp/.macfuse-install.log"
  6. FORCE_EMBEDDED_FILE="/tmp/.macfuse-force-embedded"
  7. exec >> "$INSTALL_LOG" 2>&1
  8. PACKAGE_PATH=$1
  9. INSTALL_PATH=$2
  10. INSTALL_VOLUME=$3
  11. SYSTEM_ROOT=$4
  12. # Binaries we use
  13. RESOURCES="${PACKAGE_PATH}/Contents/Resources"
  14. AUTOINSTALLER_NAME="autoinstall-macfuse-core"
  15. AUTOINSTALLER="${RESOURCES}/${AUTOINSTALLER_NAME}"
  16. PATH="/bin:/usr/bin:/usr/sbin"; export PATH
  17. # Header
  18. echo ""
  19. echo -n "Running postflight: "
  20. date
  21. echo ""
  22. # Determine this .pkg's receipt location.
  23. PACKAGE_NAME=$(basename "$PACKAGE_PATH")
  24. if [ -z "$PACKAGE_NAME" ]
  25. then
  26. echo "Empty PACKAGE_NAME."
  27. exit 1
  28. fi
  29. FINAL_RECEIPT="${INSTALL_VOLUME}/Library/Receipts/${PACKAGE_NAME}"
  30. # Determine OS version MAJOR-MINOR that we are running on.
  31. OS_VERSION_PATH="${INSTALL_VOLUME}/System/Library/CoreServices/SystemVersion"
  32. OS_VERSION=$(/usr/bin/defaults read "$OS_VERSION_PATH" ProductVersion)
  33. if [ -z "$OS_VERSION" ]
  34. then
  35. # Unable to get OS X version from volume.
  36. exit 1
  37. fi
  38. OS_MAJOR=$(echo "$OS_VERSION" | awk -F. '{ print $1 }')
  39. OS_MINOR=$(echo "$OS_VERSION" | awk -F. '{ print $2 }')
  40. if [ \( -z "$OS_MAJOR" \) -o \( -z "$OS_MINOR" \) ]
  41. then
  42. # Unable to parse OS X version obtained from volume.
  43. exit 1
  44. fi
  45. CORE_NAME="MacFUSE Core.pkg"
  46. # Some third-party software releases have mis-packaged MacFUSE Core. If this
  47. # looks to be the case then we need to remove the improper receipt.
  48. if [ -d "$CORE_RECEIPT" ]
  49. then
  50. CORE_RECEIPT="${INSTALL_VOLUME}/Library/Receipts/${CORE_NAME}"
  51. CORE_RECEIPT_INFO="${CORE_RECEIPT}/Contents/Info"
  52. MACFUSE_BUNDLE_ID=$(defaults read "$CORE_RECEIPT_INFO" CFBundleIdentifier)
  53. if [ "$MACFUSE_BUNDLE_ID" != "com.google.macfuse.core" ]
  54. then
  55. echo "Removing broken MacFUSE Core receipt: $CORE_RECEIPT"
  56. # TODO: Should we also uninstall macfuse core?
  57. rm -rf "$CORE_RECEIPT"
  58. fi
  59. fi
  60. # Determine the appropriate embedded pkg for this platform.
  61. OS_MAJOR_MINOR="${OS_MAJOR}.${OS_MINOR}"
  62. EMBEDDED_PKG="${PACKAGE_PATH}/Contents/Resources/${OS_MAJOR_MINOR}/${CORE_NAME}"
  63. INSTALL_EMBEDDED_PKG=1 # Default to installing the embedded .pkg
  64. FAIL_IF_MISSING_EMBEDDED_PKG=1 # Default to fail if no embedded .pkg
  65. echo "Potential embedded package path: ${EMBEDDED_PKG}"
  66. # Use autoinstaller to see if there is a newer MacFUSE Core.
  67. NEW_VERSION=
  68. if [ -f "$FORCE_EMBEDDED_FILE" ]
  69. then
  70. # We are being forced to use the embedded package and not check for updates
  71. echo "Found $FORCE_EMBEDDED_FILE; skipping check for online updates"
  72. rm -f "$FORCE_EMBEDDED_FILE"
  73. else
  74. AUTOINSTALLER_OUTPUT=$("$AUTOINSTALLER" --list)
  75. AUTOINSTALLER_RC=$?
  76. echo "$AUTOINSTALLER_OUTPUT" # So that we can see in postflight log
  77. if [ $AUTOINSTALLER_RC -eq 0 ]
  78. then
  79. NEW_VERSION=$(unset Version; eval "$AUTOINSTALLER_OUTPUT" > /dev/null; echo "$Version")
  80. NEW_VERSION_STRING=${NEW_VERSION:-"None"}
  81. if [ "$NEW_VERSION_STRING" = "None" ]
  82. then
  83. FAIL_IF_MISSING_EMBEDDED_PKG=0
  84. fi
  85. echo "New version available: $NEW_VERSION_STRING"
  86. else
  87. echo "Unable to get data from autoinstaller about new versions."
  88. fi
  89. fi
  90. # If there is a newer version, we check if it is newer than what we have embedded
  91. # in this .pkg. If so, we run autoinstaller to start install of the new one.
  92. if [ "$NEW_VERSION" != "" ]
  93. then
  94. # Check to see if the new version is embedded in this .pkg
  95. EMBEDDED_INFO="${EMBEDDED_PKG}/Contents/Info"
  96. EMBEDDED_VERSION=$(defaults read "$EMBEDDED_INFO" CFBundleShortVersionString)
  97. if [ "$EMBEDDED_VERSION" != "$NEW_VERSION" ]
  98. then
  99. echo "Attempting to download and install version ${NEW_VERSION}."
  100. "$AUTOINSTALLER" --install -v
  101. if [ $? -eq 0 ]
  102. then
  103. echo "Successfully downloaded and installed updated version."
  104. INSTALL_EMBEDDED_PKG=0
  105. else
  106. echo "Failed to download and install new version."
  107. fi
  108. else
  109. echo "Embedded version is current."
  110. fi
  111. fi
  112. # If we need to install the embedded package then see if it actually exists.
  113. if [ $INSTALL_EMBEDDED_PKG -eq 1 ]
  114. then
  115. if [ ! -d "$EMBEDDED_PKG" ]
  116. then
  117. echo "Missing embedded pkg: ${EMBEDDED_PKG}"
  118. INSTALL_EMBEDDED_PKG=0
  119. if [ $FAIL_IF_MISSING_EMBEDDED_PKG -eq 1 ]
  120. then
  121. echo "Failure due to missing embedded pkg: ${EMBEDDED_PKG}"
  122. exit 1
  123. fi
  124. fi
  125. fi
  126. # Maybe try to install our embedded MacFUSE Core.pkg.
  127. if [ $INSTALL_EMBEDDED_PKG -eq 1 ]
  128. then
  129. echo "Attempting to install embedded package: ${EMBEDDED_PKG}"
  130. INSTALLER_OUTPUT=$(installer -pkg "$EMBEDDED_PKG" -target "$INSTALL_VOLUME")
  131. INSTALLER_RC=$?
  132. echo "$INSTALLER_OUTPUT" # So that we see it in our postflight log
  133. if [ $INSTALLER_RC -eq 0 ]
  134. then
  135. # Remove old autoinstaller bundle if it is still there.
  136. MACFUSE_SUPPORT="/Library/Filesystems/fusefs.fs/Support/"
  137. if [ $OS_MINOR -eq 4 ]
  138. then
  139. MACFUSE_SUPPORT="/System/${MACFUSE_SUPPORT}"
  140. fi
  141. MACFUSE_SUPPORT="${INSTALL_VOLUME}/${MACFUSE_SUPPORT}"
  142. if [ ! -d "$MACFUSE_SUPPORT" ]
  143. then
  144. echo "Unable to find Support directory: ${MACFUSE_SUPPORT}"
  145. exit 1
  146. fi
  147. # Remove the old autoinstaller bundle if necessary.
  148. rm -rf "${MACFUSE_SUPPORT}/MacFUSEAutoinstaller.bundle"
  149. # Copy the autoinstaller binary.
  150. # DISABLED: The autoinstaller binary is now installed as part of the outer pkg.
  151. # cp "$AUTOINSTALLER" "${MACFUSE_SUPPORT}/${AUTOINSTALLER_NAME}"
  152. # if [ $? -ne 0 ]
  153. # then
  154. # echo "Unable to copy autoinstaller bundle to Support directory."
  155. # exit 1
  156. # fi
  157. # chown -R root:wheel "${MACFUSE_SUPPORT}/${AUTOINSTALLER_NAME}"
  158. # if [ $? -ne 0 ]
  159. # then
  160. # echo "Unable to chown macfuse autoinstaller."
  161. # exit 1
  162. # fi
  163. else
  164. # If the install failed due to an existing newer version then it is OK.
  165. # TODO: This grep is sort of lame and dependent on installer (and lang?)
  166. echo "$INSTALLER_OUTPUT" | \
  167. grep "newer version of this software already exists" > /dev/null
  168. if [ $? -eq 0 ]
  169. then
  170. echo "Embedded package was older than what is already installed (status OK)."
  171. else
  172. echo "Failed to install $EMBEDDED_PKG"
  173. exit 1
  174. fi
  175. fi
  176. fi
  177. # Make Spotlight aware of debug symbols for libfuse and the Objective-C framework.
  178. # We do this for the user that is logged in at the console.
  179. sudo -u `stat -f %Su /dev/console` mdimport /Library/Frameworks/MacFUSE.framework/Resources/Debug/
  180. # Remove our receipt; MacFUSE.pkg doesn't have a payload.
  181. rm -rf "$FINAL_RECEIPT"
  182. ## Signal success
  183. exit 0