Skip to content

Commit

Permalink
feat(vip-go-mu-plugins): script to update MU plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Aug 12, 2024
1 parent e60e7c3 commit bb5c58d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
3 changes: 2 additions & 1 deletion features/src/vip-go-mu-plugins/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"id": "vip-go-mu-plugins",
"name": "VIP Go MU Plugins",
"version": "2.1.0",
"version": "2.2.0",
"description": "Installs VIP Go MU Plugins into the Dev Environment",
"documentationURL": "https://github.com/Automattic/vip-codespaces/tree/trunk/features/src/vip-go-mu-plugins",
"options": {
"enabled": {
"type": "boolean",
Expand Down
15 changes: 4 additions & 11 deletions features/src/vip-go-mu-plugins/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,11 @@ if [ "${ENABLED}" != "false" ]; then
esac

install -D -d -m 0755 -o "${_REMOTE_USER}" -g "${_REMOTE_USER}" /wp/wp-content/mu-plugins
install -d -m 0755 -o root -g root /etc/vip-go-mu-plugins
install -m 0755 -o root -g root update-mu-plugins /usr/local/bin/update-mu-plugins

git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/Automattic/vip-go-mu-plugins.git /tmp/mu-plugins --branch "${BRANCH}" --single-branch -j4
git clone --depth=1 https://github.com/Automattic/vip-go-mu-plugins-ext.git /tmp/mu-plugins-ext --single-branch
if [ "${DEVELOPMENT_MODE}" != 'true' ]; then
rsync -a /tmp/mu-plugins/ /tmp/mu-plugins-ext/ /wp/wp-content/mu-plugins --exclude-from="/tmp/mu-plugins/.dockerignore" --exclude-from="/tmp/mu-plugins-ext/.dockerignore"
find /wp/wp-content/mu-plugins \( -name .svn -o -name .github -o -name ".git*" \) -type d -exec rm -rfv {} \; 2> /dev/null
else
rsync -a /tmp/mu-plugins/ /tmp/mu-plugins-ext/ /wp/wp-content/mu-plugins
fi

rm -rf /tmp/mu-plugins /tmp/mu-plugins-ext
touch /etc/vip-go-mu-plugins/.rsyncignore

chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /wp/wp-content/mu-plugins
update-mu-plugins "${BRANCH}" "${DEVELOPMENT_MODE}"
echo 'Done!'
fi
43 changes: 43 additions & 0 deletions features/src/vip-go-mu-plugins/update-mu-plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

set -e

PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin

BRANCH="${1:-develop}"
DEVELOPMENT_MODE="${2:-false}"

if [ ! -d /wp/wp-content/mu-plugins ]; then
echo "No mu-plugins directory found, aborting."
exit 1
fi

DIR_UID="$(stat -c %u /wp/wp-content/mu-plugins)"
DIR_GID="$(stat -c %g /wp/wp-content/mu-plugins)"
MY_UID="$(id -u)"
MY_GID="$(id -g)"

if [ "${MY_UID}" -ne 0 ]; then
if [ "${MY_UID}" -ne "${DIR_UID}" ] || [ "${MY_GID}" -ne "${DIR_GID}" ]; then
echo "You must be root to change the owner of the mu-plugins directory."
exit 1
fi
fi

TEMP_DIR="$(mktemp -d)"

trap 'rm -rf "${TEMP_DIR}"' EXIT INT TERM

git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/Automattic/vip-go-mu-plugins.git "${TEMP_DIR}/mu-plugins" --branch "${BRANCH}" --single-branch -j4
git clone --depth=1 https://github.com/Automattic/vip-go-mu-plugins-ext.git "${TEMP_DIR}/mu-plugins-ext" --single-branch

if [ "${DEVELOPMENT_MODE}" != 'true' ]; then
rsync -a --delete "${TEMP_DIR}/mu-plugins/" "${TEMP_DIR}/mu-plugins-ext/" /wp/wp-content/mu-plugins --exclude-from="${TEMP_DIR}/mu-plugins/.dockerignore" --exclude-from="${TEMP_DIR}/mu-plugins-ext/.dockerignore" --exclude-from=/etc/vip-go-mu-plugins/.rsyncignore
find /wp/wp-content/mu-plugins \( -name .svn -o -name .github -o -name ".git*" \) -type d -exec rm -rfv {} \; 2> /dev/null
else
rsync -a --delete "${TEMP_DIR}/mu-plugins/" "${TEMP_DIR}/mu-plugins-ext/" /wp/wp-content/mu-plugins --exclude-from=/etc/vip-go-mu-plugins/.rsyncignore
fi

if [ "${MY_UID}" -eq 0 ]; then
chown -R "${DIR_UID}:${DIR_GID}" /wp/wp-content/mu-plugins
fi

0 comments on commit bb5c58d

Please sign in to comment.