Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / mac / install.sh
blobe39e729b917c93c72036d282d1fa409ca164dd29
1 #!/bin/bash -p
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # Called by the application to install in a new location. Generally, this
8 # means that the application is running from a disk image and wants to be
9 # copied to /Applications. The application, when running from the disk image,
10 # will call this script to perform the copy.
12 # This script will be run as root if the application determines that it would
13 # not otherwise have permission to perform the copy.
15 # When running as root, this script will be invoked with the real user ID set
16 # to the user's ID, but the effective user ID set to 0 (root). bash -p is
17 # used on the first line to prevent bash from setting the effective user ID to
18 # the real user ID (dropping root privileges).
20 set -e
22 # This script may run as root, so be paranoid about things like ${PATH}.
23 export PATH="/usr/bin:/usr/sbin:/bin:/sbin"
25 # If running as root, output the pid to stdout before doing anything else.
26 # See chrome/browser/mac/authorization_util.h.
27 if [ ${EUID} -eq 0 ] ; then
28 echo "${$}"
31 if [ ${#} -ne 2 ] ; then
32 echo "usage: ${0} SRC DEST" >& 2
33 exit 2
36 SRC=${1}
37 DEST=${2}
39 # Make sure that SRC is an absolute path and that it exists.
40 if [ -z "${SRC}" ] || [ "${SRC:0:1}" != "/" ] || [ ! -d "${SRC}" ] ; then
41 echo "${0}: source ${SRC} sanity check failed" >& 2
42 exit 3
45 # Make sure that DEST is an absolute path and that it doesn't yet exist.
46 if [ -z "${DEST}" ] || [ "${DEST:0:1}" != "/" ] || [ -e "${DEST}" ] ; then
47 echo "${0}: destination ${DEST} sanity check failed" >& 2
48 exit 4
51 # Do the copy.
52 rsync -lrpt "${SRC}/" "${DEST}"
54 # The remaining steps are not considered critical.
55 set +e
57 # Notify LaunchServices.
58 CORESERVICES="/System/Library/Frameworks/CoreServices.framework"
59 LAUNCHSERVICES="${CORESERVICES}/Frameworks/LaunchServices.framework"
60 LSREGISTER="${LAUNCHSERVICES}/Support/lsregister"
61 "${LSREGISTER}" -f "${DEST}"
63 # If this script is not running as root and the application is installed
64 # somewhere under /Applications, try to make it writable by all admin users.
65 # This will allow other admin users to update the application from their own
66 # user Keystone instances even if the Keystone ticket is not promoted to
67 # system level.
69 # If the script is not running as root and the application is not installed
70 # under /Applications, it might not be in a system-wide location, and it
71 # probably won't be something that other users on the system are running, so
72 # err on the side of safety and don't make it group-writable.
74 # If this script is running as root, a Keystone ticket promotion is expected,
75 # and future updates can be expected to be applied as root, so
76 # admin-writeability is not a concern. Set the entire thing to be owned by
77 # root in that case, regardless of where it's installed, and drop any group
78 # and other write permission.
80 # If this script is running as a user that is not a member of the admin group,
81 # the chgrp operation will not succeed. Tolerate that case, because it's
82 # better than the alternative, which is to make the application
83 # world-writable.
84 CHMOD_MODE="a+rX,u+w,go-w"
85 if [ ${EUID} -ne 0 ] ; then
86 if [ "${DEST:0:14}" = "/Applications/" ] &&
87 chgrp -Rh admin "${DEST}" >& /dev/null ; then
88 CHMOD_MODE="a+rX,ug+w,o-w"
90 else
91 chown -Rh root:wheel "${DEST}" >& /dev/null
94 chmod -R "${CHMOD_MODE}" "${DEST}" >& /dev/null
96 # On the Mac, or at least on HFS+, symbolic link permissions are significant,
97 # but chmod -R and -h can't be used together. Do another pass to fix the
98 # permissions on any symbolic links.
99 find "${DEST}" -type l -exec chmod -h "${CHMOD_MODE}" {} + >& /dev/null
101 # Host OS version check, to be able to take advantage of features on newer
102 # systems and fall back to slow ways of doing things on older systems.
103 OS_VERSION=$(sw_vers -productVersion)
104 OS_MAJOR=$(sed -Ene 's/^([0-9]+).*/\1/p' <<< ${OS_VERSION})
105 OS_MINOR=$(sed -Ene 's/^([0-9]+)\.([0-9]+).*/\2/p' <<< ${OS_VERSION})
107 # Because this script is launched by the application itself, the installation
108 # process inherits the quarantine bit (LSFileQuarantineEnabled). Any files or
109 # directories created during the update will be quarantined in that case,
110 # which may cause Launch Services to display quarantine UI. That's bad,
111 # especially if it happens when the outer .app launches a quarantined inner
112 # helper. Since the user approved the application launch if quarantined, it
113 # it can be assumed that the installed copy should not be quarantined. Use
114 # xattr to drop the quarantine attribute.
115 QUARANTINE_ATTR=com.apple.quarantine
116 if [ ${OS_MAJOR} -gt 10 ] ||
117 ([ ${OS_MAJOR} -eq 10 ] && [ ${OS_MINOR} -ge 6 ]) ; then
118 # On 10.6, xattr supports -r for recursive operation.
119 xattr -d -r "${QUARANTINE_ATTR}" "${DEST}" >& /dev/null
120 else
121 # On earlier systems, xattr doesn't support -r, so run xattr via find.
122 find "${DEST}" -exec xattr -d "${QUARANTINE_ATTR}" {} + >& /dev/null
125 # Great success!
126 exit 0