| 9643 | } cli_install_activation_t; |
| 9644 | |
| 9645 | static int cli_install_activate(void *opaque) { |
| 9646 | cli_install_activation_t *activation = opaque; |
| 9647 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 9648 | !activation->shell_rc) { |
| 9649 | return CLI_TRUE; |
| 9650 | } |
| 9651 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 9652 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 9653 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 9654 | if (activation->copy_binary) { |
| 9655 | if (activation->dry_run) { |
| 9656 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 9657 | } |
| 9658 | } |
| 9659 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 9660 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 9661 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 9662 | activation->bin_dir); |
| 9663 | return CLI_TRUE; |
| 9664 | } |
| 9665 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 9666 | activation->bin_target, activation->prepared_candidate, |
| 9667 | &activation->binary_transaction); |
| 9668 | cli_binary_validator_t restaged_validator = {{0}}; |
| 9669 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 9670 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 9671 | &restaged_validator) || |
| 9672 | !activation->has_binary_validator || |
| 9673 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 9674 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 9675 | "re-staged on the target filesystem\n"); |
| 9676 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9677 | "install_transaction_restaging_cleanup"); |
| 9678 | return CLI_TRUE; |
| 9679 | } |
| 9680 | } |
| 9681 | if (!activation->dry_run && activation->binary_transaction) { |
| 9682 | if (cli_activation_transaction_commit_validated( |
| 9683 | activation->binary_transaction, |
| 9684 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 9685 | CLI_OCTAL_PERM) != CLI_OK) { |
| 9686 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9687 | "install_transaction_publish_recovery"); |
| 9688 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 9689 | activation->bin_target); |
| 9690 | return CLI_TRUE; |
| 9691 | } |
| 9692 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 9693 | } |
| 9694 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 9695 | * callback so the startup lock covers the complete filesystem window, |
| 9696 | * including same-binary and non-force installs. */ |
| 9697 | int agent_config_rc = CLI_OK; |
| 9698 | if (!activation->skip_config) { |
| 9699 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 9700 | activation->home, activation->bin_target, |
| 9701 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 9702 | activation->dry_run); |
no test coverage detected