-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase
More file actions
94 lines (69 loc) · 1.56 KB
/
Copy pathbase
File metadata and controls
94 lines (69 loc) · 1.56 KB
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
#!/usr/bin/env bash
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
IFS=$'\n\t'
execute_name=execute
usage() {
(cat >&2 <<EOF
--------------------------------------------------------------------------------
Example usage:
#!/usr/bin/env bash
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
IFS=$'\n\t'
script_dir=\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)
# The $execute_name function will be invoked in the root of a Drupal 10 installation.
$execute_name() {
echo "Executing!"
echo "module_path: \$module_path"
}
source "\$script_dir/base"
EOF
)
exit 1
}
# @see https://stackoverflow.com/a/28776166
if ! (return 0 2>/dev/null); then
(cat >&2 <<EOF
This script (${BASH_SOURCE[0]}) must be sourced!
EOF
)
usage
fi
if [[ $(type -t "$execute_name") != function ]]; then
(cat >&2 <<EOF
Function $execute_name does not exist!
EOF
)
usage
fi
compose() {
docker compose "$@"
}
shell() {
compose exec drupal "$@"
}
composer() {
shell composer "$@"
}
drush() {
shell vendor/bin/drush "$@"
}
# Extract the module path from the service.
module_path=$(compose run --rm drupal sh -c 'echo $MODULE_PATH')
module_name=$(basename "$module_path")
# https://www.man7.org/linux/man-pages/man1/trap.1p.html
trap teardown EXIT
setup() {
# compose down --remove-orphans
compose pull --ignore-buildable
compose up --detach --remove-orphans --wait
# Finally, install our module.
drush --yes pm:install "$module_name"
}
teardown() {
# Remove EXIT trap
trap - EXIT
compose down --remove-orphans
}
setup
execute
teardown