| OLD | NEW |
| 1 #!/bin/bash -p | 1 #!/bin/bash -p |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # usage: keystone_install.sh update_dmg_mount_point | 7 # usage: keystone_install.sh update_dmg_mount_point |
| 8 # | 8 # |
| 9 # Called by the Keystone system to update the installed application with a new | 9 # Called by the Keystone system to update the installed application with a new |
| 10 # version from a disk image. | 10 # version from a disk image. |
| 11 # | 11 # |
| 12 # Environment variables: | 12 # Environment variables: |
| 13 # GOOGLE_CHROME_UPDATER_DEBUG | 13 # GOOGLE_CHROME_UPDATER_DEBUG |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 (ln -fhs "${target}" "${temp_link}" && \ | 220 (ln -fhs "${target}" "${temp_link}" && \ |
| 221 chmod -h 755 "${temp_link}" && \ | 221 chmod -h 755 "${temp_link}" && \ |
| 222 mv -f "${temp_link}" "${symlink_dir}/") || true | 222 mv -f "${temp_link}" "${symlink_dir}/") || true |
| 223 rm -rf "${temp_link_dir}" | 223 rm -rf "${temp_link_dir}" |
| 224 fi | 224 fi |
| 225 | 225 |
| 226 return 0 | 226 return 0 |
| 227 } | 227 } |
| 228 | 228 |
| 229 # ensure_writable_symlinks_recursive calls ensure_writable_symlink for every | 229 # ensure_writable_symlinks_recursive calls ensure_writable_symlink for every |
| 230 # symbolic link in |directory|, recursivley. | 230 # symbolic link in |directory|, recursively. |
| 231 # | 231 # |
| 232 # In some very weird and rare cases, it is possible to wind up with a user | 232 # In some very weird and rare cases, it is possible to wind up with a user |
| 233 # installation that contains symbolic links that the user does not have write | 233 # installation that contains symbolic links that the user does not have write |
| 234 # permission over. More on how that might happen later. | 234 # permission over. More on how that might happen later. |
| 235 # | 235 # |
| 236 # If a weird and rare case like this is observed, rsync will exit with an | 236 # If a weird and rare case like this is observed, rsync will exit with an |
| 237 # error when attempting to update the times on these symbolic links. rsync | 237 # error when attempting to update the times on these symbolic links. rsync |
| 238 # may not be intelligent enough to try creating a new symbolic link in these | 238 # may not be intelligent enough to try creating a new symbolic link in these |
| 239 # cases, but this script can be. | 239 # cases, but this script can be. |
| 240 # | 240 # |
| 241 # The problem occurs when an administrative user first drag-installs the | 241 # The problem occurs when an administrative user first drag-installs the |
| 242 # application to /Applications, resulting in the program's user being set to | 242 # application to /Applications, resulting in the program's user being set to |
| 243 # the user's own ID. If, subsequently, a .pkg package is installed over that, | 243 # the user's own ID. If, subsequently, a .pkg package is installed over that, |
| 244 # the existing directory ownership will be preserved, but file ownership will | 244 # the existing directory ownership will be preserved, but file ownership will |
| 245 # be changed to whateer is specified by the package, typically root. This | 245 # be changed to whatever is specified by the package, typically root. This |
| 246 # applies to symbolic links as well. On a subsequent update, rsync will be | 246 # applies to symbolic links as well. On a subsequent update, rsync will be |
| 247 # able to copy the new files into place, because the user still has permission | 247 # able to copy the new files into place, because the user still has permission |
| 248 # to write to the directories. If the symbolic link targets are not changing, | 248 # to write to the directories. If the symbolic link targets are not changing, |
| 249 # though, rsync will not replace them, and they will remain owned by root. | 249 # though, rsync will not replace them, and they will remain owned by root. |
| 250 # The user will not have permission to update the time on the symbolic links, | 250 # The user will not have permission to update the time on the symbolic links, |
| 251 # resulting in an rsync error. | 251 # resulting in an rsync error. |
| 252 ensure_writable_symlinks_recursive() { | 252 ensure_writable_symlinks_recursive() { |
| 253 local directory="${1}" | 253 local directory="${1}" |
| 254 | 254 |
| 255 # This fix-up is not necessary when running as root, because root will | 255 # This fix-up is not necessary when running as root, because root will |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 note "installed_app_plist_path = ${installed_app_plist_path}" | 665 note "installed_app_plist_path = ${installed_app_plist_path}" |
| 666 local old_version_app | 666 local old_version_app |
| 667 old_version_app="$(defaults read "${installed_app_plist}" \ | 667 old_version_app="$(defaults read "${installed_app_plist}" \ |
| 668 "${APP_VERSION_KEY}" || true)" | 668 "${APP_VERSION_KEY}" || true)" |
| 669 note "old_version_app = ${old_version_app}" | 669 note "old_version_app = ${old_version_app}" |
| 670 | 670 |
| 671 # old_version_app is not required, because it won't be present in skeleton | 671 # old_version_app is not required, because it won't be present in skeleton |
| 672 # bootstrap installations, which just have an empty .app directory. Only | 672 # bootstrap installations, which just have an empty .app directory. Only |
| 673 # require it when doing a patch update, and use it to validate that the | 673 # require it when doing a patch update, and use it to validate that the |
| 674 # patch applies to the old installed version. By definition, skeleton | 674 # patch applies to the old installed version. By definition, skeleton |
| 675 # bootstraps can't be installed with patch udpates. They require the full | 675 # bootstraps can't be installed with patch updates. They require the full |
| 676 # application on the disk image. | 676 # application on the disk image. |
| 677 if [[ -n "${is_patch}" ]]; then | 677 if [[ -n "${is_patch}" ]]; then |
| 678 if [[ -z "${old_version_app}" ]]; then | 678 if [[ -z "${old_version_app}" ]]; then |
| 679 err "old_version_app required for patch" | 679 err "old_version_app required for patch" |
| 680 exit 6 | 680 exit 6 |
| 681 elif [[ "${old_version_app}" != "${update_version_app_old}" ]]; then | 681 elif [[ "${old_version_app}" != "${update_version_app_old}" ]]; then |
| 682 err "this patch does not apply to the installed version" | 682 err "this patch does not apply to the installed version" |
| 683 exit 6 | 683 exit 6 |
| 684 fi | 684 fi |
| 685 fi | 685 fi |
| (...skipping 21 matching lines...) Expand all Loading... |
| 707 | 707 |
| 708 ensure_writable_symlinks_recursive "${installed_app}" | 708 ensure_writable_symlinks_recursive "${installed_app}" |
| 709 | 709 |
| 710 # By copying to ${installed_app}, the existing application name will be | 710 # By copying to ${installed_app}, the existing application name will be |
| 711 # preserved, if the user has renamed the application on disk. Respecting | 711 # preserved, if the user has renamed the application on disk. Respecting |
| 712 # the user's changes is friendly. | 712 # the user's changes is friendly. |
| 713 | 713 |
| 714 # Make sure that ${installed_versions_dir} exists, so that it can receive | 714 # Make sure that ${installed_versions_dir} exists, so that it can receive |
| 715 # the versioned directory. It may not exist if updating from an older | 715 # the versioned directory. It may not exist if updating from an older |
| 716 # version that did not use the versioned layout on disk. Later, during the | 716 # version that did not use the versioned layout on disk. Later, during the |
| 717 # rsync to copy the applciation directory, the mode bits and timestamp on | 717 # rsync to copy the application directory, the mode bits and timestamp on |
| 718 # ${installed_versions_dir} will be set to conform to whatever is present in | 718 # ${installed_versions_dir} will be set to conform to whatever is present in |
| 719 # the update. | 719 # the update. |
| 720 # | 720 # |
| 721 # ${installed_app} is guaranteed to exist at this point, but | 721 # ${installed_app} is guaranteed to exist at this point, but |
| 722 # ${installed_app}/${CONTENTS_DIR} may not if things are severely broken or | 722 # ${installed_app}/${CONTENTS_DIR} may not if things are severely broken or |
| 723 # if this update is actually an initial installation from a Keystone | 723 # if this update is actually an initial installation from a Keystone |
| 724 # skeleton bootstrap. The mkdir creates ${installed_app}/${CONTENTS_DIR} if | 724 # skeleton bootstrap. The mkdir creates ${installed_app}/${CONTENTS_DIR} if |
| 725 # it doesn't exist; its mode bits will be fixed up in a subsequent rsync. | 725 # it doesn't exist; its mode bits will be fixed up in a subsequent rsync. |
| 726 note "creating installed_versions_dir" | 726 note "creating installed_versions_dir" |
| 727 if ! mkdir -p "${installed_versions_dir}"; then | 727 if ! mkdir -p "${installed_versions_dir}"; then |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 # (obviously) and the version that was just replaced, and to use ps and lsof | 1053 # (obviously) and the version that was just replaced, and to use ps and lsof |
| 1054 # to see if it looks like any processes are currently using any other old | 1054 # to see if it looks like any processes are currently using any other old |
| 1055 # directories. Directories not in use are removed. Old versioned | 1055 # directories. Directories not in use are removed. Old versioned |
| 1056 # directories that are in use are left alone so as to not interfere with | 1056 # directories that are in use are left alone so as to not interfere with |
| 1057 # running processes. These directories can be cleaned up by this script on | 1057 # running processes. These directories can be cleaned up by this script on |
| 1058 # future updates. | 1058 # future updates. |
| 1059 # | 1059 # |
| 1060 # To determine which directories are in use, both ps and lsof are used. | 1060 # To determine which directories are in use, both ps and lsof are used. |
| 1061 # Each approach has limitations. | 1061 # Each approach has limitations. |
| 1062 # | 1062 # |
| 1063 # The ps check looks for processes within the verisoned directory. Only | 1063 # The ps check looks for processes within the versioned directory. Only |
| 1064 # helper processes, such as renderers, are within the versioned directory. | 1064 # helper processes, such as renderers, are within the versioned directory. |
| 1065 # Browser processes are not, so the ps check will not find them, and will | 1065 # Browser processes are not, so the ps check will not find them, and will |
| 1066 # assume that a versioned directory is not in use if a browser is open | 1066 # assume that a versioned directory is not in use if a browser is open |
| 1067 # without any windows. The ps mechanism can also only detect processes | 1067 # without any windows. The ps mechanism can also only detect processes |
| 1068 # running on the system that is performing the update. If network shares | 1068 # running on the system that is performing the update. If network shares |
| 1069 # are involved, all bets are off. | 1069 # are involved, all bets are off. |
| 1070 # | 1070 # |
| 1071 # The lsof check looks to see what processes have the framework dylib open. | 1071 # The lsof check looks to see what processes have the framework dylib open. |
| 1072 # Browser processes will have their versioned framework dylib open, so this | 1072 # Browser processes will have their versioned framework dylib open, so this |
| 1073 # check is able to catch browsers even if there are no associated helper | 1073 # check is able to catch browsers even if there are no associated helper |
| 1074 # processes. Like the ps check, the lsof check is limited to processes on | 1074 # processes. Like the ps check, the lsof check is limited to processes on |
| 1075 # the system that is performing the update. Finally, unless running as | 1075 # the system that is performing the update. Finally, unless running as |
| 1076 # root, the lsof check can only find processes running as the effective user | 1076 # root, the lsof check can only find processes running as the effective user |
| 1077 # performing the update. | 1077 # performing the update. |
| 1078 # | 1078 # |
| 1079 # These limitations are motiviations to additionally preserve the versioned | 1079 # These limitations are motivations to additionally preserve the versioned |
| 1080 # directory corresponding to the version that was just replaced. | 1080 # directory corresponding to the version that was just replaced. |
| 1081 note "cleaning up old versioned directories" | 1081 note "cleaning up old versioned directories" |
| 1082 | 1082 |
| 1083 local versioned_dir | 1083 local versioned_dir |
| 1084 for versioned_dir in "${installed_versions_dir}/"*; do | 1084 for versioned_dir in "${installed_versions_dir}/"*; do |
| 1085 note "versioned_dir = ${versioned_dir}" | 1085 note "versioned_dir = ${versioned_dir}" |
| 1086 if [[ "${versioned_dir}" = "${new_versioned_dir}" ]] || \ | 1086 if [[ "${versioned_dir}" = "${new_versioned_dir}" ]] || \ |
| 1087 [[ "${versioned_dir}" = "${old_versioned_dir}" ]]; then | 1087 [[ "${versioned_dir}" = "${old_versioned_dir}" ]]; then |
| 1088 # This is the versioned directory corresponding to the update that was | 1088 # This is the versioned directory corresponding to the update that was |
| 1089 # just applied or the version that was previously in use. Leave it | 1089 # just applied or the version that was previously in use. Leave it |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 | 1224 |
| 1225 # Check "less than" instead of "not equal to" in case Keystone ever changes to | 1225 # Check "less than" instead of "not equal to" in case Keystone ever changes to |
| 1226 # pass more arguments. | 1226 # pass more arguments. |
| 1227 if [[ ${#} -lt 1 ]]; then | 1227 if [[ ${#} -lt 1 ]]; then |
| 1228 usage | 1228 usage |
| 1229 exit 2 | 1229 exit 2 |
| 1230 fi | 1230 fi |
| 1231 | 1231 |
| 1232 main "${@}" | 1232 main "${@}" |
| 1233 exit ${?} | 1233 exit ${?} |
| OLD | NEW |