Add upstream
This commit is contained in:
48
wp-content/plugins/jetpack/bin/build-asset-cdn-json.php
Normal file
48
wp-content/plugins/jetpack/bin/build-asset-cdn-json.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
// The repo root path.
|
||||
$path = dirname( dirname( __FILE__ ) ) . '/';
|
||||
|
||||
// Build an iterator over all files in the repo that match the regex in the RegexIterator.
|
||||
$directory = new RecursiveDirectoryIterator( $path );
|
||||
$iterator = new RecursiveIteratorIterator( $directory );
|
||||
$regex = new RegexIterator( $iterator, '/^.+\.(css|js)$/i', RecursiveRegexIterator::GET_MATCH );
|
||||
|
||||
$ignore_paths = array(
|
||||
'_inc/client/',
|
||||
'bin/',
|
||||
'docker/',
|
||||
'docs/',
|
||||
'extensions/',
|
||||
'logs/',
|
||||
'node_modules/',
|
||||
'tests/',
|
||||
'tools/',
|
||||
'vendor/',
|
||||
);
|
||||
|
||||
$manifest = array();
|
||||
foreach ( $regex as $path_to_file => $value ) {
|
||||
$path_from_repo_root = str_replace( $path, '', $path_to_file );
|
||||
|
||||
// Ignore top-level files.
|
||||
if ( false === strpos( $path_from_repo_root, '/' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore explicit ignore list.
|
||||
foreach ( $ignore_paths as $ignore_path ) {
|
||||
if ( 0 === strpos( $path_from_repo_root, $ignore_path ) ) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$manifest[] = $path_from_repo_root;
|
||||
}
|
||||
|
||||
$export = var_export( $manifest, true );
|
||||
|
||||
file_put_contents( $path . 'modules/photon-cdn/jetpack-manifest.php', "<?php
|
||||
// This file is autogenerated by bin/build-asset-cdn-json.php
|
||||
|
||||
\$assets = $export;\r\n" );
|
||||
68
wp-content/plugins/jetpack/bin/partner-cancel.sh
Normal file
68
wp-content/plugins/jetpack/bin/partner-cancel.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# cancel a the plan provided for the current site using the given partner keys
|
||||
|
||||
usage () {
|
||||
echo "Usage: partner-cancel.sh --partner_id=partner_id --partner_secret=partner_secret [--url=http://example.com] [--allow-root] [--partner-tracking-id]"
|
||||
}
|
||||
|
||||
GLOBAL_ARGS=""
|
||||
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
-c=* | --partner_id=* ) CLIENT_ID="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-s=* | --partner_secret=* ) CLIENT_SECRET="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-u=* | --url=* ) SITE_URL="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--partner-tracking-id=* ) PARTNER_TRACKING_ID="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--allow-root ) GLOBAL_ARGS="--allow-root"
|
||||
shift
|
||||
;;
|
||||
-h | --help ) usage
|
||||
exit
|
||||
;;
|
||||
* ) usage
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$CLIENT_ID" = "" ] || [ "$CLIENT_SECRET" = "" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# default API host that can be overridden
|
||||
if [ -z "$JETPACK_START_API_HOST" ]; then
|
||||
JETPACK_START_API_HOST='public-api.wordpress.com'
|
||||
fi
|
||||
|
||||
# fetch an access token using our client ID/secret
|
||||
ACCESS_TOKEN_JSON=$(curl https://$JETPACK_START_API_HOST/oauth2/token --silent --header "Host: public-api.wordpress.com" -d "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&scope=jetpack-partner")
|
||||
|
||||
# set URL arg for multisite compatibility
|
||||
if [ ! -z "$SITE_URL" ]; then
|
||||
GLOBAL_ARGS=" --url=$SITE_URL"
|
||||
fi
|
||||
|
||||
ADDITIONAL_ARGS=""
|
||||
if [ ! -z "$PARTNER_TRACKING_ID" ]; then
|
||||
ADDITIONAL_ARGS="$ADDITIONAL_ARGS --partner-tracking-id=$PARTNER_TRACKING_ID"
|
||||
fi
|
||||
|
||||
# Remove leading whitespace
|
||||
GLOBAL_ARGS=$(echo "$GLOBAL_ARGS" | xargs echo)
|
||||
|
||||
# Intentionally not quoting $GLOBAL_ARGS below so that words in the string are split
|
||||
|
||||
# silently ensure Jetpack is active
|
||||
wp $GLOBAL_ARGS plugin activate jetpack >/dev/null 2>&1
|
||||
|
||||
# cancel the partner plan
|
||||
wp $GLOBAL_ARGS jetpack partner_cancel "$ACCESS_TOKEN_JSON" $ADDITIONAL_ARGS
|
||||
253
wp-content/plugins/jetpack/bin/partner-provision.sh
Normal file
253
wp-content/plugins/jetpack/bin/partner-provision.sh
Normal file
@@ -0,0 +1,253 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# accepts: partner client ID and secret key, and some site info
|
||||
# executes wp-cli command to provision Jetpack site for given partner
|
||||
|
||||
usage () {
|
||||
echo 'Usage: partner-provision.sh \
|
||||
--partner_id=partner_id \
|
||||
--partner_secret=partner_secret \
|
||||
--user=wp_user_id \
|
||||
[--wp-cli-path=/usr/local/bin/wp]
|
||||
[--plan=plan_name] \
|
||||
[--onboarding=1] \
|
||||
[--wpcom_user_id=1234] \
|
||||
[--wpcom_user_email=wpcom_user_email] \
|
||||
[--url=http://example.com] \
|
||||
[--force_connect=1] \
|
||||
[--force_register=1] \
|
||||
[--allow-root] \
|
||||
[--partner-tracking-id=1] \
|
||||
[--ssh-host=example.com] \
|
||||
[--ssh-user=user_name] \
|
||||
[--ssh-pass=user_pass] \
|
||||
[--ssh-private-key=/path/to/private_key] \
|
||||
[--ssh-port=22] '
|
||||
}
|
||||
|
||||
# Note: this script should always be designed to keep wp-cli OPTIONAL
|
||||
# so that it can be run outside of the WordPress installation.
|
||||
WP_CLI_COMMAND="wp"
|
||||
WP_CLI_ARGS=""
|
||||
|
||||
# Default API host that can be overridden.
|
||||
if [ -z "$JETPACK_START_API_HOST" ]; then
|
||||
JETPACK_START_API_HOST='public-api.wordpress.com'
|
||||
fi
|
||||
|
||||
PROVISION_REQUEST_ARGS=""
|
||||
PROVISION_REQUEST_URL="https://$JETPACK_START_API_HOST/rest/v1.3/jpphp/provision"
|
||||
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
-c=* | --partner_id=* )
|
||||
CLIENT_ID="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-s=* | --partner_secret=* )
|
||||
CLIENT_SECRET="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-i=* | --user_id=* | --user=* )
|
||||
WP_USER="${i#*=}"
|
||||
WP_CLI_ARGS="$WP_CLI_ARGS --user=${i#*=}"
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form local_user=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-w=* | --wpcom_user_id=* )
|
||||
WPCOM_USER_ID=${i#*=}
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form wpcom_user_id=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-e=* | --wpcom_user_email=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form wpcom_user_email=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-p=* | --plan=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form plan=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-o=* | --onboarding=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form onboarding=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-u=* | --url=* )
|
||||
WP_CLI_ARGS="$WP_CLI_ARGS --url=${i#*=}"
|
||||
SITEURL="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--force_register=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form force_register=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--force_connect=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form force_connect=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--partner-tracking-id=* )
|
||||
PROVISION_REQUEST_URL="$PROVISION_REQUEST_URL?partner-tracking-id=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--ssh-host=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form ssh_host=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--ssh-user=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form ssh_user=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--ssh-pass=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form ssh_pass=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--ssh-private-key=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form ssh_private_key=<${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--ssh-port=* )
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form ssh_port=${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--allow-root )
|
||||
WP_CLI_ARGS="$WP_CLI_ARGS --allow-root"
|
||||
shift
|
||||
;;
|
||||
--wp-cli-path=* )
|
||||
WP_CLI_COMMAND="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
-h | --help )
|
||||
usage
|
||||
exit
|
||||
;;
|
||||
* )
|
||||
echo $(usage) >&2
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
WP_CLI_CHECK=$($WP_CLI_COMMAND --skip-plugins --skip-themes option get home 2>/dev/null)
|
||||
if [ -z "$WP_CLI_CHECK" ]; then
|
||||
WP_CLI_EXISTS=0
|
||||
else
|
||||
WP_CLI_EXISTS=1
|
||||
fi
|
||||
|
||||
if [ "$WP_CLI_EXISTS" -eq "1" ]; then
|
||||
WP_CLI_ARGS="$WP_CLI_ARGS --skip-themes --skip-plugins=$($WP_CLI_COMMAND plugin list --field=name | grep -v ^jetpack$ | tr '\n' ',')"
|
||||
fi
|
||||
|
||||
if [ "$CLIENT_ID" = "" ] || [ "$CLIENT_SECRET" = "" ] || [ "$WP_USER" = "" ]; then
|
||||
echo $(usage) >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
jetpack_shell_is_errored() {
|
||||
if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
JSON_ERROR=$( jetpack_echo_key_from_json "$1" error | xargs echo )
|
||||
|
||||
if [ -z "$JSON_ERROR" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
jetpack_is_wp_cli_error() {
|
||||
if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -z $( echo "$1" | grep Error:) ] || [ -z "$1" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
jetpack_echo_key_from_json() {
|
||||
if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo $1 | sed -n "s/.*\"$2\":\"\([^\"]*\)\".*/\1/p"
|
||||
}
|
||||
|
||||
# Fetch an access token using our client ID/secret.
|
||||
ACCESS_TOKEN_JSON=$(
|
||||
curl \
|
||||
--silent \
|
||||
--request POST \
|
||||
--url https://$JETPACK_START_API_HOST/oauth2/token \
|
||||
--header 'cache-control: no-cache' \
|
||||
--header 'content-type: multipart/form-data;' \
|
||||
--header "Host: public-api.wordpress.com" \
|
||||
--form client_id="$CLIENT_ID" \
|
||||
--form client_secret="$CLIENT_SECRET" \
|
||||
--form grant_type=client_credentials \
|
||||
--form scope=jetpack-partner
|
||||
)
|
||||
|
||||
if jetpack_shell_is_errored "$ACCESS_TOKEN_JSON"; then
|
||||
echo "$ACCESS_TOKEN_JSON" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ACCESS_TOKEN=$( jetpack_echo_key_from_json "$ACCESS_TOKEN_JSON" access_token | xargs echo )
|
||||
|
||||
# If we don't have an access token, we can't go further.
|
||||
if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" = "" ]; then
|
||||
echo "$ACCESS_TOKEN_JSON" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Silently ensure Jetpack is active
|
||||
# Intentionally not quoting $WP_CLI_ARGS so that words in the string are split
|
||||
if [ "$WP_CLI_EXISTS" -eq "1" ]; then
|
||||
$WP_CLI_COMMAND $WP_CLI_ARGS plugin activate jetpack >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ -z "$SITEURL" ] && [ "$WP_CLI_EXISTS" -eq "1" ]; then
|
||||
SITEURL=$( $WP_CLI_COMMAND $WP_CLI_ARGS option get siteurl | xargs echo )
|
||||
fi
|
||||
|
||||
PROVISION_REQUEST_ARGS="$PROVISION_REQUEST_ARGS --form siteurl=$SITEURL"
|
||||
|
||||
PROVISION_REQUEST=$(
|
||||
curl \
|
||||
--silent \
|
||||
--request POST \
|
||||
--url "$PROVISION_REQUEST_URL" \
|
||||
--header "authorization: Bearer $ACCESS_TOKEN" \
|
||||
--header "Host: public-api.wordpress.com" \
|
||||
--header 'cache-control: no-cache' \
|
||||
--header 'content-type: multipart/form-data;' \
|
||||
$PROVISION_REQUEST_ARGS
|
||||
)
|
||||
|
||||
if [ -z "$PROVISION_REQUEST" ]; then
|
||||
echo "{\"success\":false,\"error_code\":\"unknown_error\",\"error_message\":\"Empty response from server\"}" >&2
|
||||
fi
|
||||
|
||||
if jetpack_shell_is_errored "$PROVISION_REQUEST"; then
|
||||
echo "$PROVISION_REQUEST" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the access token for the Jetpack connection.
|
||||
ACCESS_TOKEN=$( jetpack_echo_key_from_json "$PROVISION_REQUEST" access_token | xargs echo )
|
||||
|
||||
# If we have an access token, set it and activate default modules!
|
||||
if [ ! -z "$ACCESS_TOKEN" ] && [ "$ACCESS_TOKEN" != "" ] && [ ! -z "$WPCOM_USER_ID" ] && [ "$WP_CLI_EXISTS" -eq "1" ]; then
|
||||
AUTHORIZE_RESULT=$( $WP_CLI_COMMAND $WP_CLI_ARGS jetpack authorize_user --token="$ACCESS_TOKEN" )
|
||||
if jetpack_is_wp_cli_error "$AUTHORIZE_RESULT"; then
|
||||
echo "{\"success\":false,\"error_code\":\"authorization_failure\",\"error_message\":\"$AUTHORIZE_RESULT\"}" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$PROVISION_REQUEST"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user