| 9362 | } cli_install_activation_t; |
| 9363 | |
| 9364 | static int cli_install_activate(void *opaque) { |
| 9365 | cli_install_activation_t *activation = opaque; |
| 9366 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 9367 | !activation->shell_rc) { |
| 9368 | return CLI_TRUE; |
| 9369 | } |
| 9370 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 9371 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 9372 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 9373 | if (activation->copy_binary) { |
| 9374 | if (activation->dry_run) { |
| 9375 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 9376 | } |
| 9377 | } |
| 9378 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 9379 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 9380 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 9381 | activation->bin_dir); |
| 9382 | return CLI_TRUE; |
| 9383 | } |
| 9384 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 9385 | activation->bin_target, activation->prepared_candidate, |
| 9386 | &activation->binary_transaction); |
| 9387 | cli_binary_validator_t restaged_validator = {{0}}; |
| 9388 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 9389 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 9390 | &restaged_validator) || |
| 9391 | !activation->has_binary_validator || |
| 9392 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 9393 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 9394 | "re-staged on the target filesystem\n"); |
| 9395 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9396 | "install_transaction_restaging_cleanup"); |
| 9397 | return CLI_TRUE; |
| 9398 | } |
| 9399 | } |
| 9400 | if (!activation->dry_run && activation->binary_transaction) { |
| 9401 | if (cli_activation_transaction_commit_validated( |
| 9402 | activation->binary_transaction, |
| 9403 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 9404 | CLI_OCTAL_PERM) != CLI_OK) { |
| 9405 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9406 | "install_transaction_publish_recovery"); |
| 9407 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 9408 | activation->bin_target); |
| 9409 | return CLI_TRUE; |
| 9410 | } |
| 9411 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 9412 | } |
| 9413 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 9414 | * callback so the startup lock covers the complete filesystem window, |
| 9415 | * including same-binary and non-force installs. */ |
| 9416 | int agent_config_rc = CLI_OK; |
| 9417 | if (!activation->skip_config) { |
| 9418 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 9419 | activation->home, activation->bin_target, |
| 9420 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 9421 | activation->dry_run); |
no test coverage detected