-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbootstrap.sh
executable file
·67 lines (57 loc) · 3.33 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set -euo pipefail
SECRETS=$(echo $VCAP_SERVICES | jq -r '.["user-provided"][] | select(.name == "secrets") | .credentials')
APP_NAME=$(echo $VCAP_APPLICATION | jq -r '.name')
APP_ROOT=$(dirname "${BASH_SOURCE[0]}")
S3_BUCKET=$(echo $VCAP_SERVICES | jq -r '.["s3"][] | select(.name == "storage") | .credentials.bucket')
S3_REGION=$(echo $VCAP_SERVICES | jq -r '.["s3"][] | select(.name == "storage") | .credentials.region')
if [ -n "$S3_BUCKET" ] && [ -n "$S3_REGION" ]; then
# Add Proxy rewrite rules to the top of the htaccess file
sed -i "s/S3_BUCKET/$S3_BUCKET/g" $APP_ROOT/web/.htaccess
sed -i "s/S3_REGION/$S3_REGION/g" $APP_ROOT/web/.htaccess
fi
install_drupal() {
ROOT_USER_NAME=$(echo $SECRETS | jq -r '.ROOT_USER_NAME')
ROOT_USER_PASS=$(echo $SECRETS | jq -r '.ROOT_USER_PASS')
: "${ROOT_USER_NAME:?Need and root user name for Drupal}"
: "${ROOT_USER_PASS:?Need and root user pass for Drupal}"
drupal site:install \
--root=$APP_ROOT/web \
--no-interaction \
--account-name="$ROOT_USER_NAME" \
--account-pass="$ROOT_USER_PASS" \
--langcode="en"
# Delete some data created in the "standard" install profile
# See https://www.drupal.org/project/drupal/issues/2583113
drupal --root=$APP_ROOT/web entity:delete shortcut_set default --no-interaction
drupal --root=$APP_ROOT/web config:delete active field.field.node.article.body --no-interaction
# Set site uuid to match our config
UUID=$(grep uuid $APP_ROOT/web/sites/default/config/system.site.yml | cut -d' ' -f2)
drupal --root=$APP_ROOT/web config:override system.site uuid $UUID
}
if [ "${CF_INSTANCE_INDEX:-''}" == "0" ] && [ "${APP_NAME}" == "web" ]; then
drupal --root=$APP_ROOT/web list | grep database > /dev/null || install_drupal
# Mild data migration: fully delete database entries related to these
# modules. These plugins (and the dependencies) can be removed once they've
# been uninstalled in all environments
drupal --root=$APP_ROOT/web module:uninstall contact
# drupal --root=$APP_ROOT/web theme:uninstall bootstrap
# Sync configs from code
drupal --root=$APP_ROOT/web config:import
# Secrets
ADMIN_EMAIL=$(echo $SECRETS | jq -r '.ADMIN_EMAIL')
BRIGHTCOVE_ACCOUNT=$(echo $SECRETS | jq -r '.BRIGHTCOVE_ACCOUNT')
BRIGHTCOVE_CLIENT=$(echo $SECRETS | jq -r '.BRIGHTCOVE_CLIENT')
BRIGHTCOVE_SECRET=$(echo $SECRETS | jq -r '.BRIGHTCOVE_SECRET')
CRON_KEY=$(echo $SECRETS | jq -r '.CRON_KEY')
drupal --root=$APP_ROOT/web config:override brightcove.brightcove_api_client.nsf_brightcove account_id $BRIGHTCOVE_ACCOUNT > /dev/null
drupal --root=$APP_ROOT/web config:override brightcove.brightcove_api_client.nsf_brightcove client_id $BRIGHTCOVE_CLIENT > /dev/null
drupal --root=$APP_ROOT/web config:override brightcove.brightcove_api_client.nsf_brightcove secret_key $BRIGHTCOVE_SECRET > /dev/null
drupal --root=$APP_ROOT/web config:override scheduler.settings lightweight_cron_access_key $CRON_KEY > /dev/null
drupal --root=$APP_ROOT/web config:override system.site mail $ADMIN_EMAIL > /dev/null
drupal --root=$APP_ROOT/web config:override update.settings notification.emails.0 $ADMIN_EMAIL > /dev/null
# Import initial content
drush --root=$APP_ROOT/web default-content-deploy:import --no-interaction
# Clear the cache
drupal --root=$APP_ROOT/web cache:rebuild --no-interaction
fi