-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinit
executable file
·210 lines (166 loc) · 5.2 KB
/
init
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
## Initialize a Docksal powered Drupal 7 site
##
## Usage: fin init
# Abort if anything fails
set -e
#-------------------------- Settings --------------------------------
# PROJECT_ROOT is passed from fin.
# The following variables are configured in the '.env' file: DOCROOT, SITE_DIRECTORY, SOURCE_ALIAS and others.
DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}"
SITEDIR_PATH="${DOCROOT_PATH}/sites/${SITE_DIRECTORY}"
#-------------------------- END: Settings --------------------------------
#-------------------------- Helper functions --------------------------------
# Console colors
red='\033[0;31m'
green='\033[0;32m'
green_bg='\033[1;97;42m'
yellow='\033[1;33m'
NC='\033[0m'
echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }
# Check whether shell is interactive (otherwise we are running in a non-interactive script environment)
is_tty ()
{
[[ "$(/usr/bin/tty || true)" != "not a tty" ]]
}
# Yes/no confirmation dialog with an optional message
# @param $1 confirmation message
_confirm ()
{
# Skip checks if not a tty
if ! is_tty ; then return 0; fi
while true; do
read -p "$1 [y/n]: " answer
case "$answer" in
[Yy]|[Yy][Ee][Ss] )
break
;;
[Nn]|[Nn][Oo] )
exit 1
;;
* )
echo 'Please answer yes or no.'
esac
done
}
# Copy a settings file.
# Skips if the destination file already exists.
# @param $1 source file
# @param $2 destination file
copy_settings_file()
{
local source="$1"
local dest="$2"
if [[ ! -f $dest ]]; then
echo "Copying ${dest}..."
cp "$source" "$dest"
else
echo-yellow "${dest} already in place."
fi
}
#-------------------------- END: Helper functions --------------------------------
#-------------------------- Functions --------------------------------
# Fix file/folder permissions
fix_permissions ()
{
echo-green "Making site directory writable..."
chmod 755 "$SITEDIR_PATH"
}
# Install site
site_install ()
{
# Initialize local settings
copy_settings_file "${SITEDIR_PATH}/example.settings.local.php" "${SITEDIR_PATH}/settings.local.php"
cd "$DOCROOT_PATH"
# We disable email sending here so site-install does not return an error
# Credit: https://www.drupal.org/project/phpconfig/issues/1826652#comment-12004674
fin drush site-install standard -y \
install_configure_form.update_status_module='array(FALSE,FALSE)' \
--site-name='My Drupal 7 Site'
echo -e "Open ${yellow}http://${VIRTUAL_HOST}${NC} in your browser to verify the setup."
}
# Install another site
site_install_anothersite ()
{
cd "$DOCROOT_PATH"
# Initialize local settings
copy_settings_file "sites/example.com/example.settings.local.php" "sites/example.com/settings.local.php"
# Create an additional database
fin db create 'anothersite'
# Install site
fin exec "php -d sendmail_path=/bin/true /usr/local/bin/drush @drupal7-advanced.anothersite site-install -y --site-name='Another Drupal 7 Site'" || true
echo -e "Open ${yellow}http://anothersite.${VIRTUAL_HOST}${NC} in your browser to verify the setup."
}
# Import database from the source site alias
db_import ()
{
_confirm "Do you want to import DB from ${SOURCE_ALIAS}?"
cd "$DOCROOT_PATH"
fin drush -l "${SITE_DIRECTORY}" sql-sync "${SOURCE_ALIAS}" @self -y
}
# Misc drush commands to bring DB up-to-date
db_updates ()
{
cd "$DOCROOT_PATH"
echo-yellow "Applying DB updates..."
set -x
fin drush -l $SITE_DIRECTORY status
fin drush -l $SITE_DIRECTORY rr # resolve moved modules
fin drush -l $SITE_DIRECTORY updb -y # run necessary db updaes
#fin drush -l $SITE_DIRECTORY fra -y # revert features
fin drush -l $SITE_DIRECTORY cc all # clear caches
fin drush -l $SITE_DIRECTORY cron -v
set +x
}
# Local adjustments
local_settings ()
{
cd "$DOCROOT_PATH"
echo-yellow "Applying local settings..."
set -x
fin drush -l "$SITE_DIRECTORY" en "$MODULES_ENABLED" -y
fin drush -l "$SITE_DIRECTORY" dis "$MODULES_DISABLED" -y
set +x
}
# Compile Sass
compass_compile ()
{
cd "$PROJECT_ROOT"
echo-yellow "Compiling Sass..."
# set -x
# cd "${DOCROOT_PATH}/sites/all/themes/<themename>"
# fin exec bundle install
# fin exec bundle exec compass compile
# set +x
}
# Run basic Behat validation tests
run_behat ()
{
cd "$PROJECT_ROOT"
echo -e "${yellow}Launching Behat validation tests...${NC}"
cd tests/behat
fin behat --format=pretty --out=std --format=junit --out=junit features/blackbox.feature
}
#-------------------------- END: Functions --------------------------------
#-------------------------- Execution --------------------------------
# Stack initialization
echo -e "${green_bg} Step 1 ${NC}${green} Initializing stack...${NC}"
fin project reset -f
# Site initialization
echo -e "${green_bg} Step 2 ${NC}${green} Initializing site...${NC}"
fix_permissions
time site_install
# Multisite - install an additional site
echo -e "${green_bg} Step 3 ${NC}${green} Initializing another site...${NC}"
time site_install_anothersite
# Examples of other things that can be done.
#db_import
#db_updates
#local_settings
#compass_compile
#run_behat
echo -e "${green_bg} DONE! ${NC}${green} Completed all initialization steps.${NC}"
#-------------------------- END: Execution --------------------------------