Commit 92d3ab87 authored by Sandeep Kadam's avatar Sandeep Kadam

Microsite deployment scripts optimizations

parent 1764af90
......@@ -7,33 +7,27 @@ set -u;
# determine root of repo
ROOT=$(cd $(dirname ${0})/.. 2>/dev/null && pwd -P);
cd ${ROOT};
## set environment & common variables
source ${ROOT}/common_config.sh ${1:-invalid};
# set default variables
declare -a file_name_array;
FILES=./microsites/*.txt
HTACCESS_PREFIX_PATH="/";
function usage {
echo "Deploy VF microsite to virtual machines"
echo "Deploy Script for VF microsites to virtual machines"
echo "";
echo "Usage: $0 <dev|stage|prod>";
echo "";
exit 1;
}
# check which environment to deploy to
case "${1:-invalid}" in
dev) ENVIRONMENT=dev ;;
stage) ENVIRONMENT=stage ;;
prod) ENVIRONMENT=prod ;;
*) usage ;;
esac;
# set environment variables
set -a; source ${ROOT}/.env; set +a;
# check which environment to deploy to
case "${ENVIRONMENT:-invalid}" in
dev) SERVER="${DEV_SERVER}"; MASTER_SERVER="${DEV_SERVER%% *}"; ;;
stage) SERVER="${STAGE_SERVER}"; MASTER_SERVER="${STAGE_SERVER%% *}"; ;;
prod) SERVER="${PROD_SERVER}"; MASTER_SERVER="${PROD_SERVER%% *}"; ;;
*) SERVER="" && usage ;;
esac;
# Validate if we have correct required parameters to execute the script.
if [ -z "${1: }" ]; then
usage;
exit 1
fi
# check we have a list of servers to deploy to
[ -z "${SERVER}" ] && echo "No server specified, cannot continue." && exit 1;
......@@ -41,10 +35,18 @@ esac;
# check site has been built
[ ! -d "${LOCAL_CORE_PATH}" ] && echo "Site must be built first, cannot continue" && exit 1;
file_name_array1=();
declare -a file_name_array;
FILES=./microsites/*.txt
HTACCESS_PREFIX_PATH="/";
###### TODO(sandeep): - Add below commmit checks once we deploy to stage & prod ######
# Check if the last commit consist of 'bin' changes or not
# If there are bin changes then it needs to deploy on all microsites else only deploy specific site.
# FULL_DEPLOY=1 -- means deploy all sites
#[ -z "$(git diff-tree --name-only HEAD^ | grep -E 'bin')" ] && FULL_DEPLOY=0 || FULL_DEPLOY=1
# if 'FULL_DEPLOY=0' then check what are the changes or which specific site changes
#if [ $FULL_DEPLOY = "0" ]; then
# LIST_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD^ | grep "txt");
# echo $LIST_FILES;
#fi
# run deployment
for _SERVER in ${SERVER};
......@@ -77,56 +79,14 @@ do
# Step 1 - Create site folders
# Create microsite folder
case "$site_theme" in
EMBL)
# EMBL Theme
MICROSITE_PATH=${EMBL_DOMAIN_ROOT}/_$site_folder_name;
MICROSITE_SYM_PATH=${EMBL_DOMAIN_ROOT}/$site_folder_name;
MICROSITE_FOLDER_NAME=${EMBL_FOLDER_NAME}.$site_folder_name;
HTACCESS_PREFIX_PATH="/${EMBL_DOMAIN_NAME#*/}/$site_folder_name/";
if [ "${ENVIRONMENT}" = 'prod' ] ; then
MICROSITE_SITE_URL="http://${EMBL_DOMAIN_NAME}/$site_folder_name";
else
MICROSITE_SITE_URL="http://$ENVIRONMENT.${EMBL_DOMAIN_NAME}/$site_folder_name";
fi
;;
EBI-SERVICE)
# EBI Service Theme
MICROSITE_PATH=${EBI_SERVICE_DOMAIN_ROOT}/_$site_folder_name;
MICROSITE_SYM_PATH=${EBI_SERVICE_DOMAIN_ROOT}/$site_folder_name;
MICROSITE_FOLDER_NAME=${EBI_SERVICE_FOLDER_NAME}.$site_folder_name;
HTACCESS_PREFIX_PATH="/${EBI_SERVICE_DOMAIN_NAME#*/}/$site_folder_name/";
# Set microsite URL
if [ "${ENVIRONMENT}" = 'prod' ] ; then
MICROSITE_SITE_URL="http://${EBI_SERVICE_DOMAIN_NAME}/$site_folder_name";
elif [ "${ENVIRONMENT}" = 'dev' ] ; then
MICROSITE_SITE_URL="http://wwwdev.${EBI_SERVICE_DOMAIN_NAME}/$site_folder_name";
else
MICROSITE_SITE_URL="http://$ENVIRONMENT.${EBI_SERVICE_DOMAIN_NAME}/$site_folder_name";
fi
;;
EBI-RESEARCH)
# EBI Research Theme
MICROSITE_PATH=${EBI_RESEARCH_DOMAIN_ROOT}/_$site_folder_name;
MICROSITE_SYM_PATH=${EBI_RESEARCH_DOMAIN_ROOT}/$site_folder_name;
MICROSITE_FOLDER_NAME=${EBI_RESEARCH_FOLDER_NAME}.$site_folder_name;
HTACCESS_PREFIX_PATH="/${EBI_RESEARCH_DOMAIN_NAME#*/}/$site_folder_name/";
# Set microsite URL
if [ "${ENVIRONMENT}" = 'prod' ] ; then
MICROSITE_SITE_URL="http://${EBI_RESEARCH_DOMAIN_NAME}/$site_folder_name";
elif [ "${ENVIRONMENT}" = 'dev' ] ; then
MICROSITE_SITE_URL="http://wwwdev.${EBI_RESEARCH_DOMAIN_NAME}/$site_folder_name";
else
MICROSITE_SITE_URL="http://$ENVIRONMENT.${EBI_RESEARCH_DOMAIN_NAME}/$site_folder_name";
fi
;;
*)
exit 1;
;;
esac;
# Get microsite folder & set microsite related variables
microsite_deploy_data=($(microsite_deploy_profile_data "$site_theme" "$site_folder_name"));
MICROSITE_PATH="${microsite_deploy_data[0]}";
MICROSITE_SYM_PATH="${microsite_deploy_data[1]}";
MICROSITE_FOLDER_NAME="${microsite_deploy_data[2]}";
HTACCESS_PREFIX_PATH="${microsite_deploy_data[3]}";
MICROSITE_SITE_URL="${microsite_deploy_data[9]}";
### Check if a directory does not exist ###
if [ ! -d "${MICROSITE_PATH}" ]
......@@ -153,8 +113,7 @@ do
NFS_TEMP_SRC=/nfs/public/rw/webdevel/projects/drupal/tmp/${ENVIRONMENT}/${DEPLOY_INSTANCE}/${MICROSITE_FOLDER_NAME}
NFS_WP_SETTINGS_SRC=/nfs/public/rw/webdevel/projects/drupal/settings.php.d/${ENVIRONMENT}/${DEPLOY_INSTANCE}/${MICROSITE_FOLDER_NAME}/wp-config.php
ssh ${SSH_OWNER}@${_SERVER} "mkdir -pv ${NFS_SQLDUMP_SRC}";
ssh ${SSH_APACHE}@${_SERVER} "mkdir -pv ${NFS_TEMP_SRC}";
ssh ${SSH_OWNER}@${_SERVER} "mkdir -pv ${NFS_SQLDUMP_SRC} && mkdir -pv ${NFS_TEMP_SRC}";
# create symlinks
ssh ${SSH_OWNER}@${_SERVER} "rm -rf ${MICROSITE_PATH}/${RELATIVE_FILES_SRC} || true; ln -svf ${NFS_FILES_SRC} ${MICROSITE_PATH}/${RELATIVE_FILES_SRC}";
......@@ -173,52 +132,53 @@ do
# create files-uploads symlink
ssh ${SSH_OWNER}@${_SERVER} "chmod u+w ${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT} || true";
ssh ${SSH_OWNER}@${_SERVER} "rm -rf ${MICROSITE_PATH}/${USER_FILES} || true";
ssh ${SSH_OWNER}@${_SERVER} "ln -svf ${USER_FILES_SYMLINK} ${MICROSITE_PATH}/${USER_FILES}";
ssh ${SSH_OWNER}@${_SERVER} "rm -rf ${MICROSITE_PATH}/${USER_FILES} || true; ln -svf ${USER_FILES_SYMLINK} ${MICROSITE_PATH}/${USER_FILES}";
# ensure no write permissions for group or other
ssh ${SSH_OWNER}@${_SERVER} "chmod -R go-w ${MICROSITE_PATH}";
# Create symlink of site folder (_sitename) to (sitename) to follow apache redirect rule
ssh ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}; rm -rf ${MICROSITE_SYM_PATH} || true; ln -svf _$site_folder_name/${RELATIVE_DOCUMENT_ROOT} ${MICROSITE_SYM_PATH}";
echo "Folder/NFS setup completed for site :- $site_title";
echo "Update URL in wp-config for site :- $site_title";
ssh ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}/ && sed -E -i'' '/(WP_HOME|WP_SITEURL)/d' ${RELATIVE_SETTINGS_SRC}/wp-config.php && cd ${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT} && ~/bin/wp config set WP_HOME '${MICROSITE_SITE_URL}' && ~/bin/wp config set WP_SITEURL '${MICROSITE_SITE_URL}'";
# Overwrite the site url in wp-config.php file
ssh ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}/ && sed -E -i'' '/(WP_HOME|WP_SITEURL)/d' ${RELATIVE_SETTINGS_SRC}/wp-config.php && ~/bin/wp --path=${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT} config set WP_HOME '${MICROSITE_SITE_URL}' && ~/bin/wp --path=${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT} config set WP_SITEURL '${MICROSITE_SITE_URL}'";
echo "Create .htaccess file"
echo "
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On \
RewriteBase $HTACCESS_PREFIX_PATH
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ${HTACCESS_PREFIX_PATH}index.php [L]
</IfModule>
# END WordPress" | ssh ${SSH_OWNER}@${_SERVER} "cat > ${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT}/.htaccess"
# Run DB related command only on one server.
if [ "$_SERVER" = "$MASTER_SERVER" ]; then
# Call VF bootstrap process & run in background
# pass arguments as ENV, filename.txt
#ORI echo "$WP_SITE_ADMIN_PASSWORD" | ssh -tt ${SSH_OWNER}@${_SERVER} "read WP_SITE_ADMIN_PASSWORD; export WP_SITE_ADMIN_PASSWORD; cd ${MICROSITE_PATH}/ && bin/vf_bootstrap microsite_setup $ENVIRONMENT $f & echo $!"
##echo "$WP_SITE_ADMIN_PASSWORD" | ssh -tt ${SSH_OWNER}@${_SERVER} "read WP_SITE_ADMIN_PASSWORD; export WP_SITE_ADMIN_PASSWORD; cd ${MICROSITE_PATH}/ && sh bin/scripts/bgjob-microsites.sh start_bootstrap_process $_SERVER microsite_setup $ENVIRONMENT ${MICROSITE_PATH} $f"
ssh -f ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}/ && nohup bin/vf_bootstrap microsite_setup $ENVIRONMENT $f $_SERVER >> ${MICROSITE_DEBUG_LOG_FOLDER}/bootstrap_output_$site_folder_name.txt 2>&1 &"
# ReSet the Wordpress Admin user password
ssh ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT} && ~/bin/wp user update 1 --user_pass=\"$WP_SITE_ADMIN_PASSWORD\" --skip-email";
ssh -f ${SSH_OWNER}@${MASTER_SERVER} "export WP_SITE_ADMIN_PASSWORD="$WP_SITE_ADMIN_PASSWORD"; cd ${MICROSITE_PATH}/ && nohup bin/vf_bootstrap microsite_setup $ENVIRONMENT $f $_SERVER >> ${MICROSITE_DEBUG_LOG_FOLDER}/bootstrap_output_$site_folder_name.txt 2>&1 &"
fi
echo "Create .htaccess file"
echo "
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On \
RewriteBase $HTACCESS_PREFIX_PATH
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ${HTACCESS_PREFIX_PATH}index.php [L]
</IfModule>
# END WordPress" | ssh ${SSH_OWNER}@${_SERVER} "cat > ${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT}/.htaccess"
done #end of for $files loop
#copy settings, conf, cron, bin folders to nfs in HH datacentre
ssh ${SSH_OWNER}@ebi-cli '/nfs/public/rw/webdevel/projects/drupal/bin/rsync_dir_datacentres_owner';
#copy files, tmp folders to nfs in HH datacentre
ssh ${SSH_APACHE}@ebi-cli '/nfs/public/rw/webdevel/projects/drupal/bin/rsync_dir_datacentres_user';
sleep 5;
# Trigger background script to check the overall microsite deployment status & display the status
ssh -tt ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}/ && export TERM=xterm ;sh bin/scripts/bgjob_microsites.sh \"${file_name_array[@]}\""
# Step 5 - restart apache scripts
if [ "$_SERVER" = "$MASTER_SERVER" ]; then
# Trigger background script to check the overall microsite deployment status & display the status
ssh -tt ${SSH_OWNER}@${_SERVER} "cd ${MICROSITE_PATH}/ && export TERM=xterm; sh bin/scripts/bgjob-microsites.sh \"${file_name_array[@]}\""
fi
done;
......@@ -14,9 +14,9 @@ echo "== Started background deployment script process check =="
declare -a FILE_NAME_ARRAY=($1)
filename_array_length=${#FILE_NAME_ARRAY[@]};
red=$(tput setaf 1);
green=$(tput setaf 2);
norm=$(tput sgr0);
red="$(tput setaf 1)";
green="$(tput setaf 2)";
norm="$(tput sgr0)"
deploy_status_logfile=${DEPLOYMENT_LOG_MAIN_FOLDER}/${DEPLOYMENT_STATUS_LOGFILE}
......@@ -36,7 +36,7 @@ fi
log_count=$(wc -l < $deploy_status_logfile)
if [ "$log_count" -lt "$filename_array_length" ] ; then
echo ""
echo "Waiting for deployment to complete for all microsite(s)..."
echo "Waiting for deployment to complete for all ($filename_array_length) microsites..."
while true
do
log_count=$(wc -l < $deploy_status_logfile)
......@@ -57,7 +57,13 @@ echo "Deployment status Log file found"
if [ $log_count = $filename_array_length ] ; then
cat $deploy_status_logfile | sed -e "s/\(Failed*\)/${red}\1${norm}/g" -e "s/\(Success*\)/${green}\1${norm}/g";
fi
if grep -q "Failed" $deploy_status_logfile ; then echo "";echo >&2 "One or more microsite(s) deployment failed, marking build as failed; please check the logs in :- '${MICROSITE_DEBUG_LOG_FOLDER}'"; exit 1; fi
echo "";
echo "== Ended background deployment script process check =="
if grep -q "Failed" $deploy_status_logfile ; then
echo "";
echo >&2 "One or more microsite(s) deployment failed, marking build as ${red}failed${norm}; please check the logs in :- '${MICROSITE_DEBUG_LOG_FOLDER}'";
echo "";
exit 1;
fi
......@@ -7,26 +7,41 @@
/** Make sure that the WordPress bootstrap has run before continuing. */
echo dirname(__FILE__);
if (php_sapi_name() === "cli") {
parse_str($argv[1], $output);
$ROOT_PATH=$output['path'];
$ROOT_PATH=trim($argv[1]);
$ENV=trim($argv[2]);
}
echo " ==Params== " . $ROOT_PATH . " ==== " . $ENV;
if ( empty($ROOT_PATH) || empty($ENV) ) {
echo "Missing the required parameters of path & env, aborting the script";
return '';
}
echo " ==Path== " . $ROOT_PATH;
require($ROOT_PATH . '/wp-load.php');
if ($ENV == 'dev' || $ENV == 'stage') {
// Dev/Test Endpoint
$SAML_IDP_PATH = 'https://idp-test.embl.de';
}
else {
// Production Endpoint
$SAML_IDP_PATH = 'https://idp.embl.de';
}
$SAML_IDP_PATH = 'https://idp.embl.de';
$time_start = microtime(true);
update_option( 'onelogin_saml_enabled', 1);
update_option( 'onelogin_saml_idp_entityid', 'https://idp.embl.de/simplesaml/saml2/idp/metadata.php');
update_option( 'onelogin_saml_idp_sso', 'https://idp.embl.de/simplesaml/saml2/idp/SSOService.php');
update_option( 'onelogin_saml_idp_slo', 'https://idp.embl.de/simplesaml/saml2/idp/SingleLogoutService.php');
update_option( 'onelogin_saml_enabled', 'on');
update_option( 'onelogin_saml_idp_entityid', $SAML_IDP_PATH . '/simplesaml/saml2/idp/metadata.php');
update_option( 'onelogin_saml_idp_sso', $SAML_IDP_PATH . '/simplesaml/saml2/idp/SSOService.php');
update_option( 'onelogin_saml_idp_slo', $SAML_IDP_PATH . '/simplesaml/saml2/idp/SingleLogoutService.php');
update_option( 'onelogin_saml_idp_x509cert', 'MIIEBTCCAu2gAwIBAgIJANrwstaqr/RtMA0GCSqGSIb3DQEBCwUAMIGYMQswCQYDVQQGEwJERTEdMBsGA1UECAwUQmFkZW4tV8ODdWVydHRlbWJlcmcxEzARBgNVBAcMCkhlaWRlbGJlcmcxDTALBgNVBAoMBEVNQkwxFDASBgNVBAsMC0lUIFNlcnZpY2VzMRQwEgYDVQQDDAtpZHAuZW1ibC5kZTEaMBgGCSqGSIb3DQEJARYLaXRzLmVtYmwuZGUwHhcNMTUwODEwMTMwNjA5WhcNMjUwODA5MTMwNjA5WjCBmDELMAkGA1UEBhMCREUxHTAbBgNVBAgMFEJhZGVuLVfDg3VlcnR0ZW1iZXJnMRMwEQYDVQQHDApIZWlkZWxiZXJnMQ0wCwYDVQQKDARFTUJMMRQwEgYDVQQLDAtJVCBTZXJ2aWNlczEUMBIGA1UEAwwLaWRwLmVtYmwuZGUxGjAYBgkqhkiG9w0BCQEWC2l0cy5lbWJsLmRlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAohEeM2W6pQo8g4BGbUdBIxK7+Wx5DmfK7prHr/jrcFj9TwlpZ/wnI1eUOigRoQc3cSezPoAY2M5ut8SnIfQzQB89qluCtHiS0zX3Ekv8otnYHHInmmS5HqHmRjKa15C25CPp64WgAPPdDEps2RjbiYI0kcRUJxSEwNm7HrZBmyWaPG5PwMvJinh+ZqJTGPxeYYORkP99KWDEBM7b/7gYpKWcJlITzqz/0t4NNKtb8L8jm+komK6GzCH6QJACWtBtoybLVREgCIEo+RPflAG9LYWhTr8wBx1GeWnIeJ7eeeHIMw6bErwzcp23rcS26/kvBaRrFzimT59WlN3AKz8jkwIDAQABo1AwTjAdBgNVHQ4EFgQUMaXasbeE3nWSKM4taWMt8wJ7jjswHwYDVR0jBBgwFoAUMaXasbeE3nWSKM4taWMt8wJ7jjswDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAPjFfSf1uKZ7LlzkpY4MD+B8x+vvyWJVeejNDoSBKnIhfSQEe7G4yUyv7SiwmivqkUo/qq0Jqd2BeN269HHV+wsI3y7SBsNHEWWBmCAiUuxgkJzCTP2Vg3T9Wjm9aFroZrasELzOmsdaqTnsUcx4L/w1GjYMEYB0P15nYTHahMmx2Oag1IR0pMbQ//PSuUEFBJ7EfVg0PY4Bb3/NUa+MYOQgZEvbVKn2cFA64RgWsDKbYD4TkMnBefa5kB+9TKwA35Gs7JDSuVblqVlcVrEVXKK42ziCNJE7aIED0tonCwA6equoY0Kv5ADOk5d6k0nwmdECFh54LZZDB+Jzf7eguxw==');
update_option( 'onelogin_saml_autocreate', 1);
update_option( 'onelogin_saml_updateuser', 1);
update_option( 'onelogin_saml_forcelogin', 0);
update_option( 'onelogin_saml_slo', 1);
update_option( 'onelogin_saml_keep_local_login', 0);
update_option( 'onelogin_saml_autocreate', 'on');
update_option( 'onelogin_saml_updateuser', 'on');
update_option( 'onelogin_saml_forcelogin', '');
update_option( 'onelogin_saml_slo', 'on');
update_option( 'onelogin_saml_keep_local_login', '');
update_option( 'onelogin_saml_account_matcher', 'email');
update_option( 'onelogin_saml_alternative_acs', 0);
update_option( 'onelogin_saml_alternative_acs', '');
update_option( 'onelogin_saml_attr_mapping_username', 'mail');
update_option( 'onelogin_saml_attr_mapping_mail', 'mail');
update_option( 'onelogin_saml_attr_mapping_firstname', 'cn');
......@@ -38,32 +53,32 @@ update_option( 'onelogin_saml_role_mapping_editor', '');
update_option( 'onelogin_saml_role_mapping_author', '');
update_option( 'onelogin_saml_role_mapping_contributor', '');
update_option( 'onelogin_saml_role_mapping_subscriber', '');
update_option( 'onelogin_saml_role_mapping_multivalued_in_one_attribute_value', 0);
update_option( 'onelogin_saml_role_mapping_multivalued_in_one_attribute_value', '');
update_option( 'onelogin_saml_role_mapping_multivalued_pattern', '');
update_option( 'onelogin_saml_role_order_administrator', '');
update_option( 'onelogin_saml_role_order_editor', '');
update_option( 'onelogin_saml_role_order_author', '');
update_option( 'onelogin_saml_role_order_contributor', '');
update_option( 'onelogin_saml_role_order_subscriber', '');
update_option( 'onelogin_saml_customize_action_prevent_local_login', 0);
update_option( 'onelogin_saml_customize_action_prevent_reset_password', 1);
update_option( 'onelogin_saml_customize_action_prevent_change_password', 1);
update_option( 'onelogin_saml_customize_action_prevent_change_mail', 1);
update_option( 'onelogin_saml_customize_stay_in_wordpress_after_slo', 0);
update_option( 'onelogin_saml_customize_action_prevent_local_login', '');
update_option( 'onelogin_saml_customize_action_prevent_reset_password', 'on');
update_option( 'onelogin_saml_customize_action_prevent_change_password', 'on');
update_option( 'onelogin_saml_customize_action_prevent_change_mail', 'on');
update_option( 'onelogin_saml_customize_stay_in_wordpress_after_slo', '');
update_option( 'onelogin_saml_customize_links_user_registration', '');
update_option( 'onelogin_saml_customize_links_lost_password', '');
update_option( 'onelogin_saml_customize_links_saml_login', '');
update_option( 'onelogin_saml_advanced_settings_debug', 0);
update_option( 'onelogin_saml_advanced_settings_strict_mode', 0);
update_option( 'onelogin_saml_advanced_idp_lowercase_url_encoding', 0);
update_option( 'onelogin_saml_advanced_settings_nameid_encrypted', 0);
update_option( 'onelogin_saml_advanced_settings_authn_request_signed', 0);
update_option( 'onelogin_saml_advanced_settings_logout_request_signed', 0);
update_option( 'onelogin_saml_advanced_settings_logout_response_signed', 0);
update_option( 'onelogin_saml_advanced_settings_want_message_signed', 0);
update_option( 'onelogin_saml_advanced_settings_want_assertion_signed', 0);
update_option( 'onelogin_saml_advanced_settings_want_assertion_encrypted', 0);
update_option( 'onelogin_saml_advanced_settings_retrieve_parameters_from_server', 0);
update_option( 'onelogin_saml_advanced_settings_debug', '');
update_option( 'onelogin_saml_advanced_settings_strict_mode', '');
update_option( 'onelogin_saml_advanced_idp_lowercase_url_encoding', '');
update_option( 'onelogin_saml_advanced_settings_nameid_encrypted', '');
update_option( 'onelogin_saml_advanced_settings_authn_request_signed', '');
update_option( 'onelogin_saml_advanced_settings_logout_request_signed', '');
update_option( 'onelogin_saml_advanced_settings_logout_response_signed', '');
update_option( 'onelogin_saml_advanced_settings_want_message_signed', '');
update_option( 'onelogin_saml_advanced_settings_want_assertion_signed', '');
update_option( 'onelogin_saml_advanced_settings_want_assertion_encrypted', '');
update_option( 'onelogin_saml_advanced_settings_retrieve_parameters_from_server', '');
update_option( 'onelogin_saml_advanced_nameidformat', 'persistent');
update_option( 'onelogin_saml_advanced_requestedauthncontext', '');
update_option( 'onelogin_saml_advanced_settings_sp_x509cert', 'MIICUjCCAbugAwIBAgIJAJDgIp9KXqF+MA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVLMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQgQ29tcGFueSBMdGQwHhcNMTkwNjEwMTUyNjExWhcNMjQwNjA4MTUyNjExWjBCMQswCQYDVQQGEwJVSzEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBknF7q0Nz0F0qXddIrrjczEx4zqXmE75l7UojGt4x7MWJdqHhCZe9cMb2qlXHWKPJONVtfNEOtMSEnXpe9RAQMW2AmPK5THOjKe6+qaOGuHdzvAvLiatxLrTjL4mxt4fs0uSX4aixICm5QdNBccNJy4yVRQn65c8Fva8s55ZfAwIDAQABo1AwTjAdBgNVHQ4EFgQUGhlpKliBoBZ7xyQtlkxJUr/t/Z8wHwYDVR0jBBgwFoAUGhlpKliBoBZ7xyQtlkxJUr/t/Z8wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQCqzMr7uiKlHoJ9OZMwvsO8jSFl68JGoO67ATMaleLcPbz4Me7OFEXE135ryyT152RzgujZl75eGeNyHCQ+0/DhhTlHMcLOtnFjHp6/RLgQG7fnLs9r/twfO76OdrBGe8urLyRJh9r5ADK/2CGdAMiJ9PQ3vV2ghoVNMdOmrFLRZg==');
......
#!/bin/bash
# Script performs WordPress bootstrap process with default Visual Framework configuration to setup group microsites.
set -x;
set -e;
set -u;
......@@ -8,21 +10,20 @@ set -u;
ROOT=$(cd $(dirname ${0})/.. 2>/dev/null && pwd -P);
cd ${ROOT};
# set environment variables
set -a; source ${ROOT}/.env; set +a;
## set environment & common variables
source ${ROOT}/common_config.sh ${2:-invalid};
# Default variables values
DEPLOY_PATH=${VM_CORE_PATH}/${RELATIVE_DOCUMENT_ROOT};
THEME_HEADER=vf_ebi_global_header;
THEME_FOOTER=vf_ebi_global_footer;
home_page_id="";
site_title="";
site_folder_name="";
who_slug="";
site_theme="";
HTACCESS_PREFIX_PATH="/";
SERVER_NAME=${4:-foo}
# Generate random password
WP_SITE_ADMIN_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32);
echo "Password = $WP_SITE_ADMIN_PASSWORD";
function usage {
echo "VF Wordpress bootstrap & configuration deployment";
......@@ -43,36 +44,11 @@ function usage {
exit 1;
}
# check which environment to deploy to
case "${2:-invalid}" in
dev) ENVIRONMENT=dev ;;
stage) ENVIRONMENT=stage ;;
prod) ENVIRONMENT=prod ;;
*) usage ;;
esac;
# check which environment to deploy to
case "${ENVIRONMENT:-invalid}" in
dev)
VF_CDN_STYLESHEET="https://dev.assets.emblstatic.net/vf/v2.0.0-alpha.7/css/styles.css";
VF_CDN_JAVASCRIPT="https://dev.assets.emblstatic.net/vf/v2.0.0-alpha.7/scripts/scripts.js";
VF_API_URL="https://dev.beta.embl.org/api/v1/";
WP_SITE_URL=${DEV_SITE_URL}
;;
stage)
VF_CDN_STYLESHEET="https://dev.assets.emblstatic.net/vf/v2.0.0-alpha.7/css/styles.css";
VF_CDN_JAVASCRIPT="https://dev.assets.emblstatic.net/vf/v2.0.0-alpha.7/scripts/scripts.js";
VF_API_URL="https://dev.beta.embl.org/api/v1/";
WP_SITE_URL=${STAGE_SITE_URL}
;;
prod)
VF_CDN_STYLESHEET="https://dev.assets.emblstatic.net/vf/v2.0.0-alpha.7/css/styles.css";
VF_CDN_JAVASCRIPT="https://dev.assets.emblstatic.net/vf/v2.0.0-alpha.7/scripts/scripts.js";
VF_API_URL="https://dev.beta.embl.org/api/v1/";
WP_SITE_URL=${PROD_SITE_URL}
;;
*) VF_CDN_STYLESHEET="" VF_CDN_JAVASCRIPT="" VF_API_URL="" && usage ;;
esac;
# Validate if we have correct required parameters to execute the script.
if [ -z "${1: }" ] || [ -z "${2: }" ] || [ -z "${3: }" ]; then
usage;
exit 1
fi
# check we have a list of servers to deploy to
[ -z "${ENVIRONMENT}" ] && echo "No environment specified, cannot continue." && exit 1;
......@@ -102,67 +78,20 @@ if [ "$MICROSITE_FLAG" -eq "1" ] ; then
declare "$VARS=$(echo -e "$CONTENTS" | grep -E "^$VARS$DELIMITER" | cut -d"$DELIMITER" -f2)";
done;
# Create microsite folder & set microsite related variables
case "$site_theme" in
EMBL)
# EMBL Theme
MICROSITE_PATH=${EMBL_DOMAIN_ROOT}/_$site_folder_name;
MICROSITE_SYM_PATH=${EMBL_DOMAIN_ROOT}/$site_folder_name;
MICROSITE_FOLDER_NAME=${EMBL_FOLDER_NAME}.$site_folder_name;
SITE_TAGLINE='EMBL';
VF_THEME_COLOR='009f4d'; # EMBL Green
# Theme settings variables
THEME_HEADER=vf_global_header;
THEME_FOOTER=vf_global_footer;
# Set microsite URL
if [ "${ENVIRONMENT}" = 'prod' ] ; then
MICROSITE_SITE_URL="http://${EMBL_DOMAIN_NAME}/$site_folder_name";
else
MICROSITE_SITE_URL="http://$ENVIRONMENT.${EMBL_DOMAIN_NAME}/$site_folder_name";
fi
;;
EBI-SERVICE)
# EBI Service Theme
MICROSITE_PATH=${EBI_SERVICE_DOMAIN_ROOT}/_$site_folder_name;
MICROSITE_SYM_PATH=${EBI_SERVICE_DOMAIN_ROOT}/$site_folder_name;
MICROSITE_FOLDER_NAME=${EBI_SERVICE_FOLDER_NAME}.$site_folder_name;
SITE_TAGLINE='EMBL-EBI';
VF_THEME_COLOR='007c80'; # EMBL-EBI Petrol
# Theme settings variables
THEME_HEADER=vf_ebi_global_header;
THEME_FOOTER=vf_ebi_global_footer;
# Set microsite URL
if [ "${ENVIRONMENT}" = 'prod' ] ; then
MICROSITE_SITE_URL="http://${EBI_SERVICE_DOMAIN_NAME}/$site_folder_name";
elif [ "${ENVIRONMENT}" = 'dev' ] ; then
MICROSITE_SITE_URL="http://wwwdev.${EBI_SERVICE_DOMAIN_NAME}/$site_folder_name";
else
MICROSITE_SITE_URL="http://$ENVIRONMENT.${EBI_SERVICE_DOMAIN_NAME}/$site_folder_name";
fi
;;
EBI-RESEARCH)
# EBI Research Theme
MICROSITE_PATH=${EBI_RESEARCH_DOMAIN_ROOT}/_$site_folder_name;
MICROSITE_SYM_PATH=${EBI_RESEARCH_DOMAIN_ROOT}/$site_folder_name;
MICROSITE_FOLDER_NAME=${EBI_RESEARCH_FOLDER_NAME}.$site_folder_name;
SITE_TAGLINE='EMBL-EBI';
VF_THEME_COLOR='007c80'; # EMBL-EBI Petrol
# Theme settings variables
THEME_HEADER=vf_ebi_global_header;
THEME_FOOTER=vf_ebi_global_footer;
# Set microsite URL
if [ "${ENVIRONMENT}" = 'prod' ] ; then
MICROSITE_SITE_URL="http://${EBI_RESEARCH_DOMAIN_NAME}/$site_folder_name";
elif [ "${ENVIRONMENT}" = 'dev' ] ; then
MICROSITE_SITE_URL="http://wwwdev.${EBI_RESEARCH_DOMAIN_NAME}/$site_folder_name";
else
MICROSITE_SITE_URL="http://$ENVIRONMENT.${EBI_RESEARCH_DOMAIN_NAME}/$site_folder_name";
fi
;;
*)
exit 1;
;;
esac;
# Get microsite folder & set microsite related variables
microsite_deploy_data=($(microsite_deploy_profile_data "$site_theme" "$site_folder_name"));
MICROSITE_PATH="${microsite_deploy_data[0]}";
MICROSITE_SYM_PATH="${microsite_deploy_data[1]}";
MICROSITE_FOLDER_NAME="${microsite_deploy_data[2]}";
HTACCESS_PREFIX_PATH="${microsite_deploy_data[3]}";
SITE_TAGLINE="${microsite_deploy_data[4]}";
VF_THEME_COLOR="${microsite_deploy_data[5]}";
GA_TRACKING_CODE="${microsite_deploy_data[6]}";
# Theme settings variables
THEME_HEADER="${microsite_deploy_data[7]}";
THEME_FOOTER="${microsite_deploy_data[8]}";
MICROSITE_SITE_URL="${microsite_deploy_data[9]}";
# Define deploy path for microsite.
DEPLOY_PATH=${MICROSITE_PATH}/${RELATIVE_DOCUMENT_ROOT};
WP_SITE_TITLE=${site_title}
......@@ -247,9 +176,8 @@ if [ $(wp option get show_on_front) != 'page' ] ; then
# # Create some core pages
# Create home page - Create only if it doesn't exists.
if ! $(wp post list --post_type=page --fields=post_title | grep -qE "^Home"); then
home_page_id="$(wp post create --post_title='Home' --post_type=page --post_status=publish --porcelain)"
# Lock the homepage agianst further edits from non-admins
if ! $(wp post list --post_type=page --fields=post_title | grep -E "^Home"); then
home_page_id=$(wp post create --post_title='Home' --post_type=page --post_status=publish --porcelain);
wp post meta update $home_page_id vf_locked 1
wp post meta update $home_page_id _vf_locked field_vf_locked
wp option update page_on_front $home_page_id
......@@ -333,6 +261,7 @@ case "${COMMAND}" in
user-role-editor
vf-data-resources-block
embl-group-site-roles
ga-google-analytics
';
# Check if plugin is active, if not then activate plugins
......@@ -480,10 +409,8 @@ EOF
# Create Publications page - Create only if it doesn't exists.
if ! $(wp post list --post_type=page --fields=post_title | grep -qE "^Publications"); then
# Set the Gutenberg HTML content for the Publications page
publications_page_content="Publications coming soon...";
publications_page_id="$(wp post create --post_title='Publications' --post_type=page --post_status=publish --post_content="$publications_page_content" --porcelain)"
publications_page_id="$(wp post create --post_title='Publications' --post_type=page --post_status=publish --porcelain)"
wp menu item add-post primary $publications_page_id --title="Publications"
wp post meta update $publications_page_id _wp_page_template template-publications.php
......@@ -496,13 +423,12 @@ EOF
if ! $(wp post list --post_type=page --fields=post_title | grep -qE "^Blog"); then
blog_page_id="$(wp post create --post_title='Blog' --post_type=page --post_status=publish --porcelain)"
if ! $(wp menu item list primary --fields=title | grep -qE "^Blog"); then
wp menu item add-post primary $blog_page_id --title="Blog"
fi
wp post meta update $blog_page_id vf_locked 1
wp post meta update $blog_page_id _vf_locked field_vf_locked
wp option update page_for_posts $blog_page_id
if ! $(wp menu item list primary --fields=title | grep -qE "^Blog"); then
wp menu item add-post primary $blog_page_id --title="Blog"
fi
fi
......@@ -548,10 +474,21 @@ EOF
wp post update 1 --post_title="Welcome to your new group or team blog!" --post_content="$default_blog_post_content";
# Set the VF Theme Color if not set
if ! $(wp option pluck theme_mods_vf-themes vf_theme_color); then
wp option patch insert theme_mods_vf-themes vf_theme_color $VF_THEME_COLOR;
#db_theme_color_value="$(wp option pluck theme_mods_vf-themes vf_theme_color)"
if ! [[ `wp option pluck theme_mods_vf-themes vf_theme_color` ]] ; then
# if [ -n "$db_theme_color_value" ]; then
wp option patch insert theme_mods_vf-themes vf_theme_color "$VF_THEME_COLOR";
else
wp option patch update theme_mods_vf-themes vf_theme_color $VF_THEME_COLOR;
wp option patch update theme_mods_vf-themes vf_theme_color "$VF_THEME_COLOR";
fi
# Set the Google analytics settings
#db_ga_options_value="$(wp option pluck gap_options gap_id)"
#if [ ! "$db_ga_options_value" ]; then
if ! [[ `wp option pluck gap_options gap_id` ]] ; then
wp option add gap_options --format=json '{"gap_id":"'"$GA_TRACKING_CODE"'","gap_enable":"1","gap_anonymize":1,"gap_location":"header","admin_area":1}'
else
wp option update gap_options --format=json '{"gap_id":"'"$GA_TRACKING_CODE"'","gap_enable":"1","gap_anonymize":1,"gap_location":"header","admin_area":1}'
fi
;;
......@@ -570,6 +507,9 @@ if [ "$MICROSITE_FLAG" -eq "1" ] ; then
# Apply SAML Unique entity config
wp option set onelogin_saml_advanced_settings_sp_entity_id "${ENVIRONMENT}.$MICROSITE_FOLDER_NAME"
# Set default group_admin role (Generated by custom plugin) for any new register user
wp option set default_role "group_admin"
# Apply SAML config & other additional configs
PHP=`which php`;
$PHP -f ${MICROSITE_PATH}/bin/scripts/wp_vf_custom_code.php -- path=${DEPLOY_PATH}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment