@@ -19,10 +19,72 @@ source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.
1919# Start Main Script
2020
2121# WP-CLI
22- cd /usr/local/src
22+ cd /usr/local/src || { echo " Error: Failed to change directory to /usr/local/src " >&2 ; exit 1 ; }
2323curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
2424chmod +x wp-cli.phar
2525sudo mv wp-cli.phar /usr/local/bin/wp
26+ WP_CLI_BIN=" /usr/local/bin/wp"
27+
28+ configure_wp_cli_package_fetching () {
29+ export COMPOSER_ALLOW_SUPERUSER=1
30+ export COMPOSER_HOME=" ${COMPOSER_HOME:-/ tmp/ enginescript-composer} "
31+ mkdir -p " ${COMPOSER_HOME} " || { echo " Error: Failed to create Composer home at ${COMPOSER_HOME} " >&2 ; exit 1; }
32+
33+ # shellcheck disable=SC2016
34+ php -r '
35+ $composerHome = rtrim($argv[1] ?? "", "/");
36+ if ($composerHome === "") {
37+ fwrite(STDERR, "Error: Composer home was not provided\n");
38+ exit(1);
39+ }
40+ $file = $composerHome . "/config.json";
41+ $config = [];
42+ if (is_file($file)) {
43+ $contents = file_get_contents($file);
44+ if ($contents !== false && trim($contents) !== "") {
45+ $decoded = json_decode($contents, true);
46+ if (!is_array($decoded)) {
47+ fwrite(STDERR, "Error: Invalid Composer config JSON at {$file}\n");
48+ exit(1);
49+ }
50+ $config = $decoded;
51+ }
52+ }
53+ if (!isset($config["config"]) || !is_array($config["config"])) {
54+ $config["config"] = [];
55+ }
56+ $config["config"]["github-protocols"] = ["https"];
57+ $config["config"]["use-github-api"] = false;
58+ $json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
59+ if ($json === false || file_put_contents($file, $json . PHP_EOL) === false) {
60+ fwrite(STDERR, "Error: Failed to write Composer config at {$file}\n");
61+ exit(1);
62+ }
63+ ' " ${COMPOSER_HOME} " || exit 1
64+
65+ local git_config_count=0
66+ if [[ " ${GIT_CONFIG_COUNT:- } " =~ ^[0-9]+$ ]]; then
67+ git_config_count=" ${GIT_CONFIG_COUNT} "
68+ fi
69+
70+ export GIT_CONFIG_COUNT=$(( git_config_count + 2 ))
71+ export " GIT_CONFIG_KEY_${git_config_count} =url.https://github.com/.insteadOf"
72+ export " GIT_CONFIG_VALUE_${git_config_count} =git@github.com:"
73+
74+ local next_git_config=$(( git_config_count + 1 ))
75+ export " GIT_CONFIG_KEY_${next_git_config} =url.https://github.com/.insteadOf"
76+ export " GIT_CONFIG_VALUE_${next_git_config} =ssh://git@github.com/"
77+ }
78+
79+ install_wp_cli_package () {
80+ local package=" $1 "
81+
82+ if ! " ${WP_CLI_BIN} " package install " ${package} " --allow-root; then
83+ echo " Error: Failed to install WP-CLI package ${package} ." >&2
84+ exit 1
85+ fi
86+ }
87+
2688mkdir -p /tmp/wp-cli-phar
2789chown -R www-data:www-data /tmp/wp-cli-phar
2890chmod 775 /tmp/wp-cli-phar
@@ -31,8 +93,9 @@ chown -R www-data:www-data ~/.wp-cli/cache
3193chmod 775 ~ /.wp-cli/cache
3294
3395# Install WP-CLI Extensions
34- wp package install pantheon-systems/wp_launch_check:@stable --allow-root
35- wp package install wp-cli/doctor-command:@stable --allow-root
96+ configure_wp_cli_package_fetching
97+ install_wp_cli_package " pantheon-systems/wp_launch_check:@stable"
98+ install_wp_cli_package " wp-cli/doctor-command:2.3.1"
3699
37100echo " "
38101echo " "
0 commit comments