Skip to content

Instantly share code, notes, and snippets.

@frankiejarrett
Last active July 9, 2016 15:00
Show Gist options
  • Select an option

  • Save frankiejarrett/6fc0b7540c120e0cca6355124971d09f to your computer and use it in GitHub Desktop.

Select an option

Save frankiejarrett/6fc0b7540c120e0cca6355124971d09f to your computer and use it in GitHub Desktop.
Keep a plugin version between two sites in sync.
#!/bin/bash
#
# Keep a plugin version between two sites in sync.
# If one host has a newer version, the other will
# be updated to match.
#
# EXAMPLE
# plugin_version_sync.sh <plugin> <host-1> <host-2>
PLUGIN=$1
HOST_1=$2
HOST_2=$3
HOST_1_VER=$(wp plugin get $PLUGIN --field=version --ssh=$HOST_1)
HOST_2_VER=$(wp plugin get $PLUGIN --field=version --ssh=$HOST_2)
function version {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}
if [ $(version $HOST_1_VER) -gt $(version $HOST_2_VER) ]; then
echo -e "$HOST_1 has a newer version of \"$PLUGIN\" than $HOST_2"
echo -e "Updating \"$PLUGIN\" on $HOST_2 from $HOST_2_VER to $HOST_1_VER"
wp plugin update $PLUGIN --version=$HOST_1_VER --ssh=$HOST_2
elif [ $(version $HOST_1_VER) -lt $(version $HOST_2_VER) ]; then
echo -e "$HOST_2 has a newer version of \"$PLUGIN\" than $HOST_1"
echo -e "Updating \"$PLUGIN\" on $HOST_1 from $HOST_1_VER to $HOST_2_VER"
wp plugin update $PLUGIN --version=$HOST_2_VER --ssh=$HOST_1
else
echo -e "$PLUGIN (v$HOST_1_VER) is identical on both hosts"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment