forked from drupal-composer/drupal-project
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install_drupal.sh
executable file
·71 lines (64 loc) · 2.14 KB
/
install_drupal.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
#!/usr/bin/env bash
set -e
BIN_DIR=../vendor/bin
TEST_VAR=install_drupal_backup_test
TEST_VAR_VALUE=TestValue
BACKUP_FILE=$(pwd -P)'/db/restore.sql'
BACKUP_FILE_GZ=${BACKUP_FILE}'.gz'
NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
RED='\033[0;31m'
RED='\033[0;31m'
BROWN='\033[0;33m'
CYAN='\033[0;36m'
function drupal { php "${BIN_DIR}"/drupal "$@"; }
function drush { php "${BIN_DIR}"/drush "$@"; }
function error_exit {
echo -e "${RED}\n$@\n${NC}" >&2
exit 1
}
function success {
echo -e "${GREEN}\n$@${NC}"
}
function assert {
echo -e "${BROWN}\n$@${NC}"
}
function varvalue {
echo -e "${CYAN}\n$@${NC}"
}
function get_var { drush state-get "${TEST_VAR}"; }
function set_var { drupal state:override "${TEST_VAR}" "$@"; }
function del_var { drupal state:delete "${TEST_VAR}" "$@"; }
function test_var {
var=`get_var`
if [[ ${var} != "$@" ]]; then
varvalue "Test variable's value is '${var}' not '$@'"
return 1
else
varvalue "Test variable's value is '$@'"
return 0
fi
}
cd web && echo $PWD
echo "testing install"
drupal site:install standard --force --no-interaction --verbose
assert 'On new install, our test variable should not exist.'
test_var ${TEST_VAR_VALUE} && error_exit 'Failure' || success 'Success'
set_var ${TEST_VAR_VALUE}
assert "After setting the var to '${TEST_VAR_VALUE}', that should be the value if retrieved."
test_var ${TEST_VAR_VALUE} && success 'Success' || error_exit 'Failure'
drupal database:dump --file=${BACKUP_FILE} --gz
if [[ ! -f ${BACKUP_FILE_GZ} ]]; then
error_exit "Backup not found: ${BACKUP_FILE_GZ}."
else
success "Backup was found: ${BACKUP_FILE_GZ}."
fi
echo 'Reinstalling site to clear out our variable.'
drupal site:install standard --force --no-interaction
assert "After reinstall, we should not get '${TEST_VAR_VALUE}' as the value."
test_var ${TEST_VAR_VALUE} && error_exit 'Failure' || success 'Success'
echo "Restoring the database using the backup."
drupal database:restore --file=${BACKUP_FILE_GZ}
assert "After restoring the backup, the var should be '${TEST_VAR_VALUE}' again."
test_var ${TEST_VAR_VALUE} && success 'Success' || error_exit 'Failure'