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