| 9705 | } cli_install_activation_t; |
| 9706 | |
| 9707 | static int cli_install_activate(void *opaque) { |
| 9708 | cli_install_activation_t *activation = opaque; |
| 9709 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 9710 | !activation->shell_rc) { |
| 9711 | return CLI_TRUE; |
| 9712 | } |
| 9713 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 9714 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 9715 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 9716 | if (activation->copy_binary) { |
| 9717 | if (activation->dry_run) { |
| 9718 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 9719 | } |
| 9720 | } |
| 9721 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 9722 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 9723 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 9724 | activation->bin_dir); |
| 9725 | return CLI_TRUE; |
| 9726 | } |
| 9727 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 9728 | activation->bin_target, activation->prepared_candidate, |
| 9729 | &activation->binary_transaction); |
| 9730 | cli_binary_validator_t restaged_validator = {{0}}; |
| 9731 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 9732 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 9733 | &restaged_validator) || |
| 9734 | !activation->has_binary_validator || |
| 9735 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 9736 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 9737 | "re-staged on the target filesystem\n"); |
| 9738 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9739 | "install_transaction_restaging_cleanup"); |
| 9740 | return CLI_TRUE; |
| 9741 | } |
| 9742 | } |
| 9743 | if (!activation->dry_run && activation->binary_transaction) { |
| 9744 | if (cli_activation_transaction_commit_validated( |
| 9745 | activation->binary_transaction, |
| 9746 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 9747 | CLI_OCTAL_PERM) != CLI_OK) { |
| 9748 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9749 | "install_transaction_publish_recovery"); |
| 9750 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 9751 | activation->bin_target); |
| 9752 | return CLI_TRUE; |
| 9753 | } |
| 9754 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 9755 | } |
| 9756 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 9757 | * callback so the startup lock covers the complete filesystem window, |
| 9758 | * including same-binary and non-force installs. */ |
| 9759 | int agent_config_rc = CLI_OK; |
| 9760 | if (!activation->skip_config) { |
| 9761 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 9762 | activation->home, activation->bin_target, |
| 9763 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 9764 | activation->dry_run); |
no test coverage detected