diff --git a/features/src/wordpress/devcontainer-feature.json b/features/src/wordpress/devcontainer-feature.json index 9fa1550f..847eb04a 100644 --- a/features/src/wordpress/devcontainer-feature.json +++ b/features/src/wordpress/devcontainer-feature.json @@ -2,12 +2,10 @@ "id": "wordpress", "name": "WordPress", "description": "Sets up WordPress into the Dev Environment", - "version": "2.6.1", + "version": "2.6.2", "documentationURL": "https://github.com/Automattic/vip-codespaces/tree/trunk/features/src/wordpress", "containerEnv": { - "WP_CLI_CONFIG_PATH": "/etc/wp-cli/wp-cli.yaml", - "WP_CLI_ALLOW_ROOT": "1", - "COMPOSER_ALLOW_SUPERUSER": "1" + "WP_CLI_CONFIG_PATH": "/etc/wp-cli/wp-cli.yaml" }, "updateContentCommand": "/usr/local/bin/wordpress-update-content.sh", "postCreateCommand": "/usr/local/bin/wordpress-post-create.sh", diff --git a/features/src/wordpress/setup-wordpress.sh b/features/src/wordpress/setup-wordpress.sh index af80d5fa..22c9bc69 100755 --- a/features/src/wordpress/setup-wordpress.sh +++ b/features/src/wordpress/setup-wordpress.sh @@ -41,6 +41,10 @@ fi MY_UID="$(id -u)" MY_GID="$(id -g)" +if [ 0 -eq "${MY_UID}" ]; then + export WP_CLI_ALLOW_ROOT=1 +fi + if [ -n "${RepositoryName}" ]; then base=/workspaces/${RepositoryName} else @@ -50,25 +54,32 @@ fi for i in client-mu-plugins images languages plugins themes; do if [ -e "${base}/${i}" ]; then sudo rm -rf "/wp/wp-content/${i}" - sudo ln -sf "${base}/${i}" "/wp/wp-content/${i}" fi done if [ -e "${base}/vip-config" ]; then - sudo rm -rf "/wp/vip-config" - sudo ln -sf "${base}/vip-config" "/wp/vip-config" + sudo rm -rf /wp/vip-config +fi + +sudo chown -R "${MY_UID}:${MY_GID}" /wp + +for i in client-mu-plugins images languages plugins themes; do + if [ -e "${base}/${i}" ]; then + ln -sf "${base}/${i}" "/wp/wp-content/${i}" + fi +done + +if [ -e "${base}/vip-config" ]; then + ln -sf "${base}/vip-config" "/wp/vip-config" fi -if [ -n "${WP_PERSIST_UPLOADS}" ]; then +if [ -n "${WP_PERSIST_UPLOADS}" ] && [ -d /workspaces ]; then sudo install -d -o "${MY_UID}" -g "${MY_GID}" -m 0755 /workspaces/uploads - sudo install -d -o "${MY_UID}" -g "${MY_GID}" -m 0755 /wp/wp-content ln -sf /workspaces/uploads /wp/wp-content/uploads else - sudo install -d -o "${MY_UID}" -g "${MY_GID}" -m 0755 /wp/wp-content/uploads + install -d -m 0755 /wp/wp-content/uploads fi -sudo install -d -o "${MY_UID}" -g "${MY_GID}" /wp/config /wp/log - export WP_USERNAME="wordpress" export WP_PASSWORD="wordpress" export WP_DATABASE="wordpress" @@ -110,8 +121,9 @@ fi echo "GRANT ALL ON ${WP_DATABASE}.* TO 'netapp'@'localhost';" } | mysql -h "${db_host}" -u "${db_admin_user}" +wp cache flush --skip-plugins --skip-themes echo "Checking for WordPress installation..." -if ! wp core is-installed >/dev/null 2>&1; then +if ! wp core is-installed --skip-plugins --skip-themes >/dev/null 2>&1; then echo "No installation found, installing WordPress..." wp db clean --yes 2> /dev/null @@ -152,11 +164,11 @@ if ! wp core is-installed >/dev/null 2>&1; then run-parts /var/lib/wordpress/postinstall.d else - echo "WordPress already installed" + echo "WordPress is already installed" fi if [ ! -f "${HOME}/.local/share/vip-codespaces/login/010-wplogin.sh" ]; then - install -D -d -m 0755 -o "${MY_UID}" -g "${MY_GID}" "${HOME}/.local/share/vip-codespaces/login" + install -D -d -m 0755 "${HOME}/.local/share/vip-codespaces/login" export WP_URL="${wp_url}" # shellcheck disable=SC2016 envsubst '$WP_URL' < /usr/share/wordpress/010-wplogin.tpl > "${HOME}/.local/share/vip-codespaces/login/010-wplogin.sh" diff --git a/features/src/wordpress/wordpress-post-create.sh b/features/src/wordpress/wordpress-post-create.sh index 498f7fff..771f177a 100755 --- a/features/src/wordpress/wordpress-post-create.sh +++ b/features/src/wordpress/wordpress-post-create.sh @@ -1,6 +1,12 @@ #!/bin/sh + if [ -f composer.json ] && [ -x /usr/local/bin/composer ]; then + MY_UID="$(id -un)" + if [ 0 -eq "${MY_UID}" ]; then + export COMPOSER_ALLOW_SUPERUSER=1 + fi + /usr/local/bin/composer install -n || true fi diff --git a/features/src/wordpress/wordpress-update-content.sh b/features/src/wordpress/wordpress-update-content.sh index e0997a5b..3740675e 100755 --- a/features/src/wordpress/wordpress-update-content.sh +++ b/features/src/wordpress/wordpress-update-content.sh @@ -1,10 +1,15 @@ #!/bin/sh if [ -f composer.json ] && [ -x /usr/local/bin/composer ]; then + MY_UID="$(id -un)" + if [ 0 -eq "${MY_UID}" ]; then + export COMPOSER_ALLOW_SUPERUSER=1 + fi + /usr/local/bin/composer install -n || true fi -if [ -f package.json ] && hash npm > /dev/null 2>&1; then +if [ -f package.json ] && hash npm >/dev/null 2>&1; then if [ ! -d node_modules ] && [ -f package-lock.json ]; then npm ci else