| 9870 | } cli_install_activation_t; |
| 9871 | |
| 9872 | static int cli_install_activate(void *opaque) { |
| 9873 | cli_install_activation_t *activation = opaque; |
| 9874 | if (!activation || !activation->bin_target || !activation->bin_dir || !activation->home || |
| 9875 | !activation->shell_rc) { |
| 9876 | return CLI_TRUE; |
| 9877 | } |
| 9878 | char previous_managed_binary[CLI_BUF_1K] = {0}; |
| 9879 | bool previous_managed_binary_exact = cbm_detect_self_path( |
| 9880 | previous_managed_binary, sizeof(previous_managed_binary), activation->home); |
| 9881 | if (activation->copy_binary) { |
| 9882 | if (activation->dry_run) { |
| 9883 | printf("Would install binary -> %s\n\n", activation->bin_target); |
| 9884 | } |
| 9885 | } |
| 9886 | if (!activation->dry_run && !activation->binary_transaction && activation->prepared_candidate) { |
| 9887 | if (!cbm_mkdir_p(activation->bin_dir, CLI_OCTAL_PERM)) { |
| 9888 | (void)fprintf(stderr, "error: cannot create install directory %s\n", |
| 9889 | activation->bin_dir); |
| 9890 | return CLI_TRUE; |
| 9891 | } |
| 9892 | cbm_activation_transaction_status_t stage_status = cbm_activation_transaction_stage_file( |
| 9893 | activation->bin_target, activation->prepared_candidate, |
| 9894 | &activation->binary_transaction); |
| 9895 | cli_binary_validator_t restaged_validator = {{0}}; |
| 9896 | if (stage_status != CBM_ACTIVATION_TRANSACTION_OK || !activation->binary_transaction || |
| 9897 | !cli_activation_transaction_expected_build(activation->binary_transaction, |
| 9898 | &restaged_validator) || |
| 9899 | !activation->has_binary_validator || |
| 9900 | strcmp(restaged_validator.fingerprint, activation->binary_validator.fingerprint) != 0) { |
| 9901 | (void)fprintf(stderr, "error: verified install candidate could not be " |
| 9902 | "re-staged on the target filesystem\n"); |
| 9903 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9904 | "install_transaction_restaging_cleanup"); |
| 9905 | return CLI_TRUE; |
| 9906 | } |
| 9907 | } |
| 9908 | if (!activation->dry_run && activation->binary_transaction) { |
| 9909 | if (cli_activation_transaction_commit_validated( |
| 9910 | activation->binary_transaction, |
| 9911 | activation->has_binary_validator ? &activation->binary_validator : NULL, |
| 9912 | CLI_OCTAL_PERM) != CLI_OK) { |
| 9913 | cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction, |
| 9914 | "install_transaction_publish_recovery"); |
| 9915 | (void)fprintf(stderr, "error: failed to publish the staged binary to %s\n", |
| 9916 | activation->bin_target); |
| 9917 | return CLI_TRUE; |
| 9918 | } |
| 9919 | printf("Installed binary -> %s\n\n", activation->bin_target); |
| 9920 | } |
| 9921 | /* Config and PATH refreshes are install mutations too. Keep them in this |
| 9922 | * callback so the startup lock covers the complete filesystem window, |
| 9923 | * including same-binary and non-force installs. */ |
| 9924 | int agent_config_rc = CLI_OK; |
| 9925 | if (!activation->skip_config) { |
| 9926 | agent_config_rc = cbm_install_agent_configs_with_previous( |
| 9927 | activation->home, activation->bin_target, |
| 9928 | previous_managed_binary_exact ? previous_managed_binary : NULL, activation->force, |
| 9929 | activation->dry_run); |
no test coverage detected