| 9306 | } cli_install_activation_t; |
| 9307 | |
| 9308 | static int cli_install_activate(void *opaque) { |
| 9309 | cli_install_activation_t *activation = opaque; |
| 9310 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 9311 | !activation->shell_rc) { |
| 9312 | return CLI_TRUE; |
| 9313 | } |
| 9314 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 9315 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 9316 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 9317 | if (activation->copy_binary) { |
| 9318 | if (activation->dry_run) { |
| 9319 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 9320 | } |
| 9321 | } |
| 9322 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 9323 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 9324 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 9325 | activation->bin_dir); |
| 9326 | return CLI_TRUE; |
| 9327 | } |
| 9328 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 9329 | activation->bin_target, activation->prepared_candidate, |
| 9330 | &activation->binary_transaction); |
| 9331 | cli_binary_validator_t restaged_validator = {{0}}; |
| 9332 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 9333 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 9334 | &restaged_validator) || |
| 9335 | !activation->has_binary_validator || |
| 9336 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 9337 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 9338 | "re-staged on the target filesystem\n"); |
| 9339 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9340 | "install_transaction_restaging_cleanup"); |
| 9341 | return CLI_TRUE; |
| 9342 | } |
| 9343 | } |
| 9344 | if (!activation->dry_run && activation->binary_transaction) { |
| 9345 | if (cli_activation_transaction_commit_validated( |
| 9346 | activation->binary_transaction, |
| 9347 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 9348 | CLI_OCTAL_PERM) != CLI_OK) { |
| 9349 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9350 | "install_transaction_publish_recovery"); |
| 9351 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 9352 | activation->bin_target); |
| 9353 | return CLI_TRUE; |
| 9354 | } |
| 9355 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 9356 | } |
| 9357 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 9358 | * callback so the startup lock covers the complete filesystem window, |
| 9359 | * including same-binary and non-force installs. */ |
| 9360 | int agent_config_rc = CLI_OK; |
| 9361 | if (!activation->skip_config) { |
| 9362 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 9363 | activation->home, activation->bin_target, |
| 9364 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 9365 | activation->dry_run); |
no test coverage detected