-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·108 lines (93 loc) · 3.42 KB
/
install.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/command/with-contenv bash
# shellcheck shell=bash
set -e
# shellcheck disable=SC1091
source /etc/islandora/utilities.sh
readonly SITE="default"
function configure {
# Starter site post install steps.
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" cache:rebuild
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" user:role:add fedoraadmin admin
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" pm:uninstall pgsql sqlite
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" migrate:import --userid=1 --tag=islandora
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" cron || true
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" search-api:index || true
drush --root=/var/www/drupal --uri="${DRUPAL_DRUSH_URI}" cache:rebuild
}
function install {
wait_for_service "${SITE}" db
wait_for_service "${SITE}" broker
wait_for_service "${SITE}" fcrepo
wait_for_service "${SITE}" fits
wait_for_service "${SITE}" solr
wait_for_service "${SITE}" triplestore
create_database "${SITE}"
install_site "${SITE}"
create_blazegraph_namespace_with_default_properties "${SITE}"
if [[ "${DRUPAL_DEFAULT_FCREPO_URL}" == https* ]]; then
# Certificates might need to be generated which can take a minute or more.
if timeout 300 curl -X HEAD "${DRUPAL_DEFAULT_FCREPO_URL}" &>/dev/null; then
echo "Valid certificate"
else
echo "Invalid certificate"
exit 1
fi
fi
configure
}
function mysql_count_query {
cat <<-EOF
SELECT COUNT(DISTINCT table_name)
FROM information_schema.columns
WHERE table_schema = '${DRUPAL_DEFAULT_DB_NAME}';
EOF
}
# Check the number of tables to determine if it has already been installed.
function installed {
local count
count=$(execute-sql-file.sh <(mysql_count_query) -- -N 2>/dev/null) || exit $?
[[ $count -ne 0 ]]
}
# Required even if not installing.
function setup() {
local site drupal_root subdir site_directory public_files_directory private_files_directory twig_cache_directory
site="${1}"
shift
drupal_root=/var/www/drupal/web
subdir=$(drupal_site_env "${site}" "SUBDIR")
site_directory="${drupal_root}/sites/${subdir}"
public_files_directory="${site_directory}/files"
private_files_directory="/var/www/drupal/private"
twig_cache_directory="${private_files_directory}/php"
# Ensure the files directories are writable by nginx, as when it is a new volume it is owned by root.
mkdir -p "${site_directory}" "${public_files_directory}" "${private_files_directory}" "${twig_cache_directory}"
chown nginx:nginx "${site_directory}" "${public_files_directory}" "${private_files_directory}" "${twig_cache_directory}"
chmod ug+rw "${site_directory}" "${public_files_directory}" "${private_files_directory}" "${twig_cache_directory}"
}
function drush_cache_setup {
# Make sure the default drush cache directory exists and is writeable.
mkdir -p /tmp/drush-/cache
chmod a+rwx /tmp/drush-/cache
}
# External processes can look for `/installed` to check if installation is completed.
function finished {
touch /installed
cat <<-EOT
#####################
# Install Completed #
#####################
EOT
}
function main() {
cd /var/www/drupal
drush_cache_setup
for_all_sites setup
if installed; then
echo "Already Installed"
else
echo "Installing"
install
fi
finished
}
main