| 9256 | } cli_install_activation_t; |
| 9257 | |
| 9258 | static int cli_install_activate(void *opaque) { |
| 9259 | cli_install_activation_t *activation = opaque; |
| 9260 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 9261 | !activation->shell_rc) { |
| 9262 | return CLI_TRUE; |
| 9263 | } |
| 9264 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 9265 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 9266 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 9267 | if (activation->copy_binary) { |
| 9268 | if (activation->dry_run) { |
| 9269 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 9270 | } |
| 9271 | } |
| 9272 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 9273 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 9274 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 9275 | activation->bin_dir); |
| 9276 | return CLI_TRUE; |
| 9277 | } |
| 9278 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 9279 | activation->bin_target, activation->prepared_candidate, |
| 9280 | &activation->binary_transaction); |
| 9281 | cli_binary_validator_t restaged_validator = {{0}}; |
| 9282 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 9283 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 9284 | &restaged_validator) || |
| 9285 | !activation->has_binary_validator || |
| 9286 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 9287 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 9288 | "re-staged on the target filesystem\n"); |
| 9289 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9290 | "install_transaction_restaging_cleanup"); |
| 9291 | return CLI_TRUE; |
| 9292 | } |
| 9293 | } |
| 9294 | if (!activation->dry_run && activation->binary_transaction) { |
| 9295 | if (cli_activation_transaction_commit_validated( |
| 9296 | activation->binary_transaction, |
| 9297 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 9298 | CLI_OCTAL_PERM) != CLI_OK) { |
| 9299 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9300 | "install_transaction_publish_recovery"); |
| 9301 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 9302 | activation->bin_target); |
| 9303 | return CLI_TRUE; |
| 9304 | } |
| 9305 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 9306 | } |
| 9307 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 9308 | * callback so the startup lock covers the complete filesystem window, |
| 9309 | * including same-binary and non-force installs. */ |
| 9310 | int agent_config_rc = CLI_OK; |
| 9311 | if (!activation->skip_config) { |
| 9312 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 9313 | activation->home, activation->bin_target, |
| 9314 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 9315 | activation->dry_run); |
no test coverage detected