OLD | NEW |
1 #!/bin/bash -p | 1 #!/bin/bash -p |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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. |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 381 |
382 # Returns 0 (true) if ksadmin supports --version-path and --version-key. | 382 # Returns 0 (true) if ksadmin supports --version-path and --version-key. |
383 ksadmin_supports_versionpath_versionkey() { | 383 ksadmin_supports_versionpath_versionkey() { |
384 # --version-path and --version-key were introduced in Keystone 1.0.9.2318. | 384 # --version-path and --version-key were introduced in Keystone 1.0.9.2318. |
385 is_ksadmin_version_ge 1.0.9.2318 | 385 is_ksadmin_version_ge 1.0.9.2318 |
386 | 386 |
387 # The return value of is_ksadmin_version_ge is used as this function's | 387 # The return value of is_ksadmin_version_ge is used as this function's |
388 # return value. | 388 # return value. |
389 } | 389 } |
390 | 390 |
| 391 # Runs "defaults read" to obtain the value of a key in a property list. As |
| 392 # with "defaults read", an absolute path to a plist is supplied, without the |
| 393 # ".plist" extension. |
| 394 # |
| 395 # As of Mac OS X 10.8, defaults (and NSUserDefaults and CFPreferences) |
| 396 # normally communicates with cfprefsd to read and write plists. Changes to a |
| 397 # plist file aren't necessarily reflected immediately via this API family when |
| 398 # not made through this API family, because cfprefsd may return cached data |
| 399 # from a former on-disk version of a plist file instead of reading the current |
| 400 # version from disk. The old behavior can be restored by setting the |
| 401 # __CFPREFERENCES_AVOID_DAEMON environment variable, although extreme care |
| 402 # should be used because portions of the system that use this API family |
| 403 # normally and thus use cfprefsd and its cache will become unsynchronized with |
| 404 # the on-disk state. |
| 405 # |
| 406 # This function is provided to set __CFPREFERENCES_AVOID_DAEMON when calling |
| 407 # "defaults read" and thus avoid cfprefsd and its on-disk cache, and is |
| 408 # intended only to be used to read values from Info.plist files, which are not |
| 409 # preferences. The use of "defaults" for this purpose has always been |
| 410 # questionable, but there's no better option to interact with plists from |
| 411 # shell scripts. Definitely don't use infoplist_read to read preference |
| 412 # plists. |
| 413 # |
| 414 # This function exists because the update process delivers new copies of |
| 415 # Info.plist files to the disk behind cfprefsd's back, and if cfprefsd becomes |
| 416 # aware of the original version of the file for any reason (such as this |
| 417 # script reading values from it via "defaults read"), the new version of the |
| 418 # file will not be immediately effective or visible via cfprefsd after the |
| 419 # update is applied. |
| 420 infoplist_read() { |
| 421 __CFPREFERENCES_AVOID_DAEMON=1 defaults read "${@}" |
| 422 } |
| 423 |
391 usage() { | 424 usage() { |
392 echo "usage: ${ME} update_dmg_mount_point" >& 2 | 425 echo "usage: ${ME} update_dmg_mount_point" >& 2 |
393 } | 426 } |
394 | 427 |
395 main() { | 428 main() { |
396 local update_dmg_mount_point="${1}" | 429 local update_dmg_mount_point="${1}" |
397 | 430 |
398 # Early steps are critical. Don't continue past any failure. | 431 # Early steps are critical. Don't continue past any failure. |
399 set -e | 432 set -e |
400 | 433 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 err "update_app must be a directory" | 564 err "update_app must be a directory" |
532 exit 2 | 565 exit 2 |
533 fi | 566 fi |
534 fi | 567 fi |
535 | 568 |
536 # Get some information about the update. | 569 # Get some information about the update. |
537 note "reading update values" | 570 note "reading update values" |
538 | 571 |
539 local update_app_plist="${update_app}/${APP_PLIST}" | 572 local update_app_plist="${update_app}/${APP_PLIST}" |
540 note "update_app_plist = ${update_app_plist}" | 573 note "update_app_plist = ${update_app_plist}" |
541 if ! update_version_app="$(defaults read "${update_app_plist}" \ | 574 if ! update_version_app="$(infoplist_read "${update_app_plist}" \ |
542 "${APP_VERSION_KEY}")" || | 575 "${APP_VERSION_KEY}")" || |
543 [[ -z "${update_version_app}" ]]; then | 576 [[ -z "${update_version_app}" ]]; then |
544 err "couldn't determine update_version_app" | 577 err "couldn't determine update_version_app" |
545 exit 2 | 578 exit 2 |
546 fi | 579 fi |
547 note "update_version_app = ${update_version_app}" | 580 note "update_version_app = ${update_version_app}" |
548 | 581 |
549 local update_ks_plist="${update_app_plist}" | 582 local update_ks_plist="${update_app_plist}" |
550 note "update_ks_plist = ${update_ks_plist}" | 583 note "update_ks_plist = ${update_ks_plist}" |
551 if ! update_version_ks="$(defaults read "${update_ks_plist}" \ | 584 if ! update_version_ks="$(infoplist_read "${update_ks_plist}" \ |
552 "${KS_VERSION_KEY}")" || | 585 "${KS_VERSION_KEY}")" || |
553 [[ -z "${update_version_ks}" ]]; then | 586 [[ -z "${update_version_ks}" ]]; then |
554 err "couldn't determine update_version_ks" | 587 err "couldn't determine update_version_ks" |
555 exit 2 | 588 exit 2 |
556 fi | 589 fi |
557 note "update_version_ks = ${update_version_ks}" | 590 note "update_version_ks = ${update_version_ks}" |
558 | 591 |
559 if ! product_id="$(defaults read "${update_ks_plist}" \ | 592 if ! product_id="$(infoplist_read "${update_ks_plist}" \ |
560 "${KS_PRODUCT_KEY}")" || | 593 "${KS_PRODUCT_KEY}")" || |
561 [[ -z "${product_id}" ]]; then | 594 [[ -z "${product_id}" ]]; then |
562 err "couldn't determine product_id" | 595 err "couldn't determine product_id" |
563 exit 2 | 596 exit 2 |
564 fi | 597 fi |
565 note "product_id = ${product_id}" | 598 note "product_id = ${product_id}" |
566 else # [[ -n "${is_patch}" ]] | 599 else # [[ -n "${is_patch}" ]] |
567 # Get some information about the update. | 600 # Get some information about the update. |
568 note "reading update values" | 601 note "reading update values" |
569 | 602 |
570 if ! update_version_app_old=$(<"${patch_dir}/old_app_version") || | 603 if ! update_version_app_old=$(<"${patch_dir}/old_app_version") || |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 # versioned directory. This will be used later, to avoid removing the | 718 # versioned directory. This will be used later, to avoid removing the |
686 # existing installed version's versioned directory in case anything is still | 719 # existing installed version's versioned directory in case anything is still |
687 # using it. | 720 # using it. |
688 note "reading install values" | 721 note "reading install values" |
689 | 722 |
690 local installed_app_plist="${installed_app}/${APP_PLIST}" | 723 local installed_app_plist="${installed_app}/${APP_PLIST}" |
691 note "installed_app_plist = ${installed_app_plist}" | 724 note "installed_app_plist = ${installed_app_plist}" |
692 local installed_app_plist_path="${installed_app_plist}.plist" | 725 local installed_app_plist_path="${installed_app_plist}.plist" |
693 note "installed_app_plist_path = ${installed_app_plist_path}" | 726 note "installed_app_plist_path = ${installed_app_plist_path}" |
694 local old_version_app | 727 local old_version_app |
695 old_version_app="$(defaults read "${installed_app_plist}" \ | 728 old_version_app="$(infoplist_read "${installed_app_plist}" \ |
696 "${APP_VERSION_KEY}" || true)" | 729 "${APP_VERSION_KEY}" || true)" |
697 note "old_version_app = ${old_version_app}" | 730 note "old_version_app = ${old_version_app}" |
698 | 731 |
699 # old_version_app is not required, because it won't be present in skeleton | 732 # old_version_app is not required, because it won't be present in skeleton |
700 # bootstrap installations, which just have an empty .app directory. Only | 733 # bootstrap installations, which just have an empty .app directory. Only |
701 # require it when doing a patch update, and use it to validate that the | 734 # require it when doing a patch update, and use it to validate that the |
702 # patch applies to the old installed version. By definition, skeleton | 735 # patch applies to the old installed version. By definition, skeleton |
703 # bootstraps can't be installed with patch updates. They require the full | 736 # bootstraps can't be installed with patch updates. They require the full |
704 # application on the disk image. | 737 # application on the disk image. |
705 if [[ -n "${is_patch}" ]]; then | 738 if [[ -n "${is_patch}" ]]; then |
706 if [[ -z "${old_version_app}" ]]; then | 739 if [[ -z "${old_version_app}" ]]; then |
(...skipping 14 matching lines...) Expand all Loading... |
721 if [[ -n "${old_version_app}" ]]; then | 754 if [[ -n "${old_version_app}" ]]; then |
722 old_versioned_dir="${installed_versions_dir}/${old_version_app}" | 755 old_versioned_dir="${installed_versions_dir}/${old_version_app}" |
723 fi | 756 fi |
724 note "old_versioned_dir = ${old_versioned_dir}" | 757 note "old_versioned_dir = ${old_versioned_dir}" |
725 | 758 |
726 # Collect the installed application's brand code, it will be used later. It | 759 # Collect the installed application's brand code, it will be used later. It |
727 # is not an error for the installed application to not have a brand code. | 760 # is not an error for the installed application to not have a brand code. |
728 local old_ks_plist="${installed_app_plist}" | 761 local old_ks_plist="${installed_app_plist}" |
729 note "old_ks_plist = ${old_ks_plist}" | 762 note "old_ks_plist = ${old_ks_plist}" |
730 local old_brand | 763 local old_brand |
731 old_brand="$(defaults read "${old_ks_plist}" \ | 764 old_brand="$(infoplist_read "${old_ks_plist}" \ |
732 "${KS_BRAND_KEY}" 2> /dev/null || | 765 "${KS_BRAND_KEY}" 2> /dev/null || |
733 true)" | 766 true)" |
734 note "old_brand = ${old_brand}" | 767 note "old_brand = ${old_brand}" |
735 | 768 |
736 ensure_writable_symlinks_recursive "${installed_app}" | 769 ensure_writable_symlinks_recursive "${installed_app}" |
737 | 770 |
738 # By copying to ${installed_app}, the existing application name will be | 771 # By copying to ${installed_app}, the existing application name will be |
739 # preserved, if the user has renamed the application on disk. Respecting | 772 # preserved, if the user has renamed the application on disk. Respecting |
740 # the user's changes is friendly. | 773 # the user's changes is friendly. |
741 | 774 |
742 # Make sure that ${installed_versions_dir} exists, so that it can receive | 775 # Make sure that ${installed_versions_dir} exists, so that it can receive |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 # is not considered a critical step, and if it fails, this script will not | 949 # is not considered a critical step, and if it fails, this script will not |
917 # exit. | 950 # exit. |
918 if [[ -n "${needs_touch}" ]]; then | 951 if [[ -n "${needs_touch}" ]]; then |
919 touch -cf "${installed_app}" || true | 952 touch -cf "${installed_app}" || true |
920 fi | 953 fi |
921 | 954 |
922 # Read the new values, such as the version. | 955 # Read the new values, such as the version. |
923 note "reading new values" | 956 note "reading new values" |
924 | 957 |
925 local new_version_app | 958 local new_version_app |
926 if ! new_version_app="$(defaults read "${installed_app_plist}" \ | 959 if ! new_version_app="$(infoplist_read "${installed_app_plist}" \ |
927 "${APP_VERSION_KEY}")" || | 960 "${APP_VERSION_KEY}")" || |
928 [[ -z "${new_version_app}" ]]; then | 961 [[ -z "${new_version_app}" ]]; then |
929 err "couldn't determine new_version_app" | 962 err "couldn't determine new_version_app" |
930 exit 9 | 963 exit 9 |
931 fi | 964 fi |
932 note "new_version_app = ${new_version_app}" | 965 note "new_version_app = ${new_version_app}" |
933 | 966 |
934 local new_versioned_dir="${installed_versions_dir}/${new_version_app}" | 967 local new_versioned_dir="${installed_versions_dir}/${new_version_app}" |
935 note "new_versioned_dir = ${new_versioned_dir}" | 968 note "new_versioned_dir = ${new_versioned_dir}" |
936 | 969 |
937 local new_ks_plist="${installed_app_plist}" | 970 local new_ks_plist="${installed_app_plist}" |
938 note "new_ks_plist = ${new_ks_plist}" | 971 note "new_ks_plist = ${new_ks_plist}" |
939 | 972 |
940 local new_version_ks | 973 local new_version_ks |
941 if ! new_version_ks="$(defaults read "${new_ks_plist}" \ | 974 if ! new_version_ks="$(infoplist_read "${new_ks_plist}" \ |
942 "${KS_VERSION_KEY}")" || | 975 "${KS_VERSION_KEY}")" || |
943 [[ -z "${new_version_ks}" ]]; then | 976 [[ -z "${new_version_ks}" ]]; then |
944 err "couldn't determine new_version_ks" | 977 err "couldn't determine new_version_ks" |
945 exit 9 | 978 exit 9 |
946 fi | 979 fi |
947 note "new_version_ks = ${new_version_ks}" | 980 note "new_version_ks = ${new_version_ks}" |
948 | 981 |
949 local update_url | 982 local update_url |
950 if ! update_url="$(defaults read "${new_ks_plist}" "${KS_URL_KEY}")" || | 983 if ! update_url="$(infoplist_read "${new_ks_plist}" "${KS_URL_KEY}")" || |
951 [[ -z "${update_url}" ]]; then | 984 [[ -z "${update_url}" ]]; then |
952 err "couldn't determine update_url" | 985 err "couldn't determine update_url" |
953 exit 9 | 986 exit 9 |
954 fi | 987 fi |
955 note "update_url = ${update_url}" | 988 note "update_url = ${update_url}" |
956 | 989 |
957 # The channel ID is optional. Suppress stderr to prevent Keystone from | 990 # The channel ID is optional. Suppress stderr to prevent Keystone from |
958 # seeing possible error output. | 991 # seeing possible error output. |
959 local channel | 992 local channel |
960 channel="$(defaults read "${new_ks_plist}" "${KS_CHANNEL_KEY}" 2> /dev/null || | 993 channel="$(infoplist_read "${new_ks_plist}" \ |
961 true)" | 994 "${KS_CHANNEL_KEY}" 2> /dev/null || true)" |
962 note "channel = ${channel}" | 995 note "channel = ${channel}" |
963 | 996 |
964 # Make sure that the update was successful by comparing the version found in | 997 # Make sure that the update was successful by comparing the version found in |
965 # the update with the version now on disk. | 998 # the update with the version now on disk. |
966 if [[ "${new_version_ks}" != "${update_version_ks}" ]]; then | 999 if [[ "${new_version_ks}" != "${update_version_ks}" ]]; then |
967 err "new_version_ks and update_version_ks do not match" | 1000 err "new_version_ks and update_version_ks do not match" |
968 exit 10 | 1001 exit 10 |
969 fi | 1002 fi |
970 | 1003 |
971 # Notify LaunchServices. This is not considered a critical step, and | 1004 # Notify LaunchServices. This is not considered a critical step, and |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 # Chrome, because the updater runs as root when on a system ticket, and root | 1317 # Chrome, because the updater runs as root when on a system ticket, and root |
1285 # can't access individual user Keychains. | 1318 # can't access individual user Keychains. |
1286 # | 1319 # |
1287 # Even if the reauthorization tool is launched, it doesn't necessarily try | 1320 # Even if the reauthorization tool is launched, it doesn't necessarily try |
1288 # to do anything. It will only attempt to perform a reauthorization if one | 1321 # to do anything. It will only attempt to perform a reauthorization if one |
1289 # hasn't yet been done at update time. | 1322 # hasn't yet been done at update time. |
1290 note "maybe reauthorizing Keychain" | 1323 note "maybe reauthorizing Keychain" |
1291 | 1324 |
1292 if [[ -z "${system_ticket}" ]]; then | 1325 if [[ -z "${system_ticket}" ]]; then |
1293 local new_bundleid_app | 1326 local new_bundleid_app |
1294 new_bundleid_app="$(defaults read "${installed_app_plist}" \ | 1327 new_bundleid_app="$(infoplist_read "${installed_app_plist}" \ |
1295 "${APP_BUNDLEID_KEY}" || true)" | 1328 "${APP_BUNDLEID_KEY}" || true)" |
1296 note "new_bundleid_app = ${new_bundleid_app}" | 1329 note "new_bundleid_app = ${new_bundleid_app}" |
1297 | 1330 |
1298 local keychain_reauthorize_dir="\ | 1331 local keychain_reauthorize_dir="\ |
1299 ${update_dmg_mount_point}/${KEYCHAIN_REAUTHORIZE_DIR}" | 1332 ${update_dmg_mount_point}/${KEYCHAIN_REAUTHORIZE_DIR}" |
1300 local keychain_reauthorize_path="\ | 1333 local keychain_reauthorize_path="\ |
1301 ${keychain_reauthorize_dir}/${new_bundleid_app}" | 1334 ${keychain_reauthorize_dir}/${new_bundleid_app}" |
1302 note "keychain_reauthorize_path = ${keychain_reauthorize_path}" | 1335 note "keychain_reauthorize_path = ${keychain_reauthorize_path}" |
1303 | 1336 |
1304 if [[ -x "${keychain_reauthorize_path}" ]]; then | 1337 if [[ -x "${keychain_reauthorize_path}" ]]; then |
1305 local framework_dir="${new_versioned_dir}/${FRAMEWORK_DIR}" | 1338 local framework_dir="${new_versioned_dir}/${FRAMEWORK_DIR}" |
(...skipping 19 matching lines...) Expand all Loading... |
1325 | 1358 |
1326 # Check "less than" instead of "not equal to" in case Keystone ever changes to | 1359 # Check "less than" instead of "not equal to" in case Keystone ever changes to |
1327 # pass more arguments. | 1360 # pass more arguments. |
1328 if [[ ${#} -lt 1 ]]; then | 1361 if [[ ${#} -lt 1 ]]; then |
1329 usage | 1362 usage |
1330 exit 2 | 1363 exit 2 |
1331 fi | 1364 fi |
1332 | 1365 |
1333 main "${@}" | 1366 main "${@}" |
1334 exit ${?} | 1367 exit ${?} |
OLD | NEW |