| 10900 | } cli_install_activation_t; |
| 10901 | |
| 10902 | static int cli_install_activate(void *opaque) { |
| 10903 | cli_install_activation_t *activation = opaque; |
| 10904 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 10905 | !activation->shell_rc) { |
| 10906 | return CLI_TRUE; |
| 10907 | } |
| 10908 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 10909 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 10910 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 10911 | if (activation->copy_binary) { |
| 10912 | if (activation->dry_run) { |
| 10913 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 10914 | } |
| 10915 | } |
| 10916 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 10917 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 10918 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 10919 | activation->bin_dir); |
| 10920 | return CLI_TRUE; |
| 10921 | } |
| 10922 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 10923 | activation->bin_target, activation->prepared_candidate, |
| 10924 | &activation->binary_transaction); |
| 10925 | cli_binary_validator_t restaged_validator = {{0}}; |
| 10926 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 10927 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 10928 | &restaged_validator) || |
| 10929 | !activation->has_binary_validator || |
| 10930 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 10931 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 10932 | "re-staged on the target filesystem\n"); |
| 10933 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 10934 | "install_transaction_restaging_cleanup"); |
| 10935 | return CLI_TRUE; |
| 10936 | } |
| 10937 | } |
| 10938 | if (!activation->dry_run && activation->binary_transaction) { |
| 10939 | if (cli_activation_transaction_commit_validated( |
| 10940 | activation->binary_transaction, |
| 10941 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 10942 | CLI_OCTAL_PERM) != CLI_OK) { |
| 10943 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 10944 | "install_transaction_publish_recovery"); |
| 10945 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 10946 | activation->bin_target); |
| 10947 | return CLI_TRUE; |
| 10948 | } |
| 10949 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 10950 | } |
| 10951 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 10952 | * callback so the startup lock covers the complete filesystem window, |
| 10953 | * including same-binary and non-force installs. */ |
| 10954 | int agent_config_rc = CLI_OK; |
| 10955 | if (!activation->skip_config) { |
| 10956 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 10957 | activation->home, activation->bin_target, |
| 10958 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 10959 | activation->dry_run); |
no test coverage detected