-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·293 lines (249 loc) · 6.41 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·293 lines (249 loc) · 6.41 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
###############################################################################
#
# DO NOT MODIFY THIS FILE
#
# Use the file $conf_file to override default settings
# and the $post_make file to run manual patches etc. after drush make
#
###############################################################################
# Some colors
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
base=$(cd "$(dirname "$0")"; pwd) # Base path
site_name="site" # Make file name without .make
site_profile="site" # Site install profile in code/profiles
config_file="$base/conf/config.sh" # configuration
post_make="$base/conf/prepare.sh" # post make
store_old_builds=true
builds_to_keep=4
command=$1 # Command to run
drush=$(which drush 2> /dev/null) # Drush command file
drush_make_script="$base/conf/site.make" # Make script
builds_dir="$base" # Directory where we build sites
build_dir="$builds_dir/current" # Active current build dir
temp_build_dir="$builds_dir/build_new" # Active current build dir
old_builds_dir="$builds_dir/builds" # Directory for old builds
files_dir="$builds_dir/files" # Files directory for symbolic linking
drush_params="" # Drush parameters that are always passed
# Source directories
code_modules_dir=$base/code/modules
code_themes_dir=$base/code/themes
code_profiles_dir=$base/code/profiles
# Drupal internal paths for modules, themes and profiles
modules_path=sites/all/modules
themes_path=sites/all/themes
profiles_path=profiles
files_path=sites/default/files
settings_directory="$base/conf"
settings_file=sites/default/settings.php
# Print a notification message
notice() {
echo -e "${yel}** BUILD NOTICE: ${end}"
}
# Print error and exit
error() {
echo -e "${red}** BUILD ERROR: ${end}"
exit -1
}
if [ -z "$drush" ]; then
error "Drush seems to be missing."
fi
if [ -z "$WKV_SITE_ENV" ]; then
error "You need to define WKV_SITE_ENV before using build.sh"
fi
if [ -e $config_file ]; then
# Include site specific overrides for the settings
source $config_file
else
error "This project does not yet have $config_file. Please set it up."
fi
###############################################################################
# Functions
# Post make setup
post_make() {
# Link code directories
for file in $code_modules_dir/*
do
name=${file##*/}
if [ -d $file -a ! -d $temp_build_dir/$modules_path/$name ]; then
ln -s $file $temp_build_dir/$modules_path/$name
fi
done
# Link theme directories
for file in $code_themes_dir/*
do
name=${file##*/}
if [ -d $file -a ! -d $temp_build_dir/$themes_path/$name ]; then
ln -s $file $temp_build_dir/$themes_path/$name
fi
done
# Link theme directories
for file in $code_profiles_dir/*
do
name=${file##*/}
if [ -d $file -a ! -d $temp_build_dir/$profiles_path/$name ]; then
ln -s $file $temp_build_dir/$profiles_path/$name
fi
done
if [ -d $files_dir ]; then
ln -s $files_dir $temp_build_dir/$files_path
fi
# Prep settings.php
echo "<?php
// ** DO NOT EDIT ** THIS FILE IS AUTOMATICALLY GENERATED BY THE BUILD PROCESS" >> $temp_build_dir/$settings_file
if [ -e $settings_directory/$WKV_SITE_ENV.settings.php ]
then
echo "
include '$settings_directory/$WKV_SITE_ENV.settings.php';" >> $temp_build_dir/$settings_file
else
notice "No local settings.php file defined: TIP! You can create one at $settings_directory/$WKV_SITE_ENV.settings.php"
fi
echo "include '$settings_directory/global.settings.php';" >> $temp_build_dir/$settings_file
# post make script
if [ -e $post_make ]
then
notice "Post make script..."
$post_make $base $temp_build_dir $command
fi
}
# Requirements checking
check_requirements() {
local error=false
local dirs=(
"$drush_make_script"
)
for dir in ${dirs[@]}
do
if [ ! -e $dir ]
then
echo "$dir does not exist"
error=true
fi
done
local commands=(
"drush"
"git"
"curl"
"unzip"
)
for cmd in ${commands[@]}
do
hash $cmd 2>&- || { echo >&2 "The command $cmd seems to be missing or inaccessible"; error=true; }
done
if [ $error == true ]
then
error "Please fix the problems and try again"
fi
# Ensure the build directories exists
mkdir -p $old_builds_dir
mkdir -p $files_dir
}
# Make a fresh build
make_build() {
notice "Building..."
$drush $drush_params --root=$temp_build_dir -y make $drush_make_script $temp_build_dir
rc=$?
if [[ $rc != 0 ]]
then
error "There seems to be a problem in your drush make file."
fi
# Store old build dir
if $store_old_builds
then
# Store old build dir if it exists
if [ -e $build_dir ]
then
build_time=`date +%Y-%m-%d_%H-%M-%S`
mv $build_dir $old_builds_dir/$build_time
fi
else
# Remove old build dir
rm -rf $build_dir
fi
post_make
# Replace old build with new one
mv $temp_build_dir $build_dir
# Run cleanup
remove_old_builds
}
# Purge the current build
purge_build() {
if [ -d $current_build_dir ]; then
notice "Purging..."
$drush $drush_params --root=$build_dir -y sql-dump > $build_dir/dump.sql
# We dont need any of this so redirect to null
$drush $drush_params --root=$build_dir -y sql-drop &> /dev/null
fi
}
# Clean up builds directory
remove_old_builds() {
notice "Removing old builds..."
files=($(find $old_builds_dir -mindepth 1 -maxdepth 1 -type d|sort -r))
for (( i = 0 ; i < ${#files[@]} ; i++ )) do
if [ $i -gt $builds_to_keep ]; then
rm -rf ${files[$i]}
fi
done
}
# Update the current build
update_build() {
notice "Updating..."
$drush $drush_params --root=$build_dir updatedb --y
$drush $drush_params --root=$build_dir cc all
}
# Print help
usage() {
echo "Usage $0 command"
echo "Where command is one of:"
echo " new - Create a new fresh build ready for installation"
echo " update - Update current build"
echo " purge - Clean up the current build"
echo " clean - Remove old builds"
}
control_c() {
echo ""
notice "Cancelled - Previous build remains intact"
# if prev build dir exists
# remove
exit 1
}
trap control_c SIGINT
###############################################################################
# MAIN SCRIPT START
check_requirements
case $command in
new )
if [ -e $build_dir ]
then
purge_build
fi
make_build
;;
clean )
remove_old_builds
;;
purge )
if [ ! -e $build_dir ]
then
error "There is no current build to purge!"
fi
purge_build
;;
update )
if [ ! -e $build_dir ]
then
error "There is no current build to update!"
fi
make_build
update_build
;;
* )
usage
;;
esac