-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·356 lines (319 loc) · 9.11 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/bin/bash
# GatherPHP
#
# Don't touch this file here - it would prevent you to just "git pull"
# your GatherPHP installation.
#
# Author: Pascal Mathis <[email protected]>
# Parse command line arguments
# -------------------------
source helpers.sh
parse_args $1
if [ $? -ne 0 ]; then
echo 'You need to specify atleast a valid php version' >&2
exit 1
fi
# Set directories
# -------------------------
# Base directory of GatherPHP.
basedir=`dirname "$0"`
cd $basedir
basedir=`pwd`
# Directory for PHP sources
srcdir="$basedir/src/php-$VERSION"
# Directory with source archives
bzipsdir="$basedir/src/bzips"
# Directory where PHPs get installed to
instbasedir=`readlink -f "$basedir/inst"`
# Directory where this specific PHP version gets installed into
instdir="$instbasedir/php-$VERSION"
# Directory where all binaries are symlinked to
shbindir="$instbasedir/bin"
# Print installation overview
# -------------------------
echo 'Installation overview'
echo '-----------------------------------'
echo "PHP version: $VERSION"
echo "Source directory: $srcdir"
echo "Installation directory: $instdir"
echo ''
read -p 'Do you want to continue (Y/N)? '
[ "$(echo $REPLY | tr [:upper:] [:lower:])" == "y" ] || exit
echo 'Installation progress'
echo '-----------------------------------'
# Download & Extract PHP source
# -------------------------
# Check if PHP source was already downloaded & extracted
if [ ! -d "$srcdir" ]; then
echo 'Source directory does not exist; trying to extract'
srcfile="$bzipsdir/php-$SHORT_VERSION.tar.bz2"
# Check if source file exists, if not try to fetch it
if [ ! -e "$srcfile" ]; then
echo "Source file not found: $srcfile"
# Try to download version from museum
url="http://museum.php.net/php$VMAJOR/php-$SHORT_VERSION.tar.bz2"
wget -P "$bzipsdir" "$url"
if [ ! -f "$srcfile" ]; then
echo "Fetching sources from museum failed: $url"
# Try the real download now
url="http://www.php.net/get/php-$SHORT_VERSION.tar.bz2/from/this/mirror"
wget -P "$bzipsdir" -O "$srcfile" "$url"
fi
if [ ! -s "$srcfile" -a -f "$srcfile" ]; then
rm "$srcfile"
fi
# Try to download from QAs
if [ ! -f "$srcfile" ]; then
release_masters="johannes stas dsp ilia"
for release_master in $release_masters; do
url="http://downloads.php.net/$release_master/php-$SHORT_VERSION.tar.bz2"
wget -P "$bzipsdir" -O "$srcfile" "$url"
if [ ! -s "$srcfile" -a -f "$srcfile" ]; then
echo "Fetching sources from QA failed: $url"
rm "$srcfile"
else
break
fi
done
fi
if [ ! -s "$srcfile" -a -f "$srcfile" ]; then
rm "$srcfile"
fi
# If everything failed, abort
if [ ! -f "$srcfile" ]; then
echo "Fetching sources failed: $url" >&2
exit 2
fi
fi
# Extract the source file
tar xjvf "$srcfile" --show-transformed-names --xform 's#^[^/]*#src/php-'"$VERSION"'#'
if [ $? -ne 0 ]; then
echo "Failed to extract source file: $srcfile" >&2
exit 2
fi
else
echo "Found source directory: $srcdir"
fi
# Read configuration flags
# -------------------------
source options.sh "$VERSION" "$VMAJOR" "$VMINOR" "$VPATCH" "$FLAGS"
cd "$srcdir"
# Only configure & make during the first install of a new version
# or after some changes were made in configuration
tstamp=0
if [ -f "config.nice" -a -f "config.status" ]; then
tstamp=`stat -c '%Y' config.status`
fi
echo "Last configuration change: $config_timestamp";
echo "Last ./configure: $tstamp";
if [ $config_timestamp -gt $tstamp ]; then
# Configure PHP
if [ $DEBUG = 1 ]; then
config_options="--enable-debug $config_options"
fi
if [ $PEAR = 1 ]; then
config_options="--with-pear=\"$instdir/pear\""
fi
if [ $ARCH32 = 1 ]; then
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
fi
if [ $ZTS = 1 ]; then
config_options="--enable-maintainer-zts $config_options"
fi
./configure $config_options \
--prefix="$instdir" \
--exec-prefix="$instdir" \
--with-config-file-path="$instdir/etc"
if [ $? -gt 0 ]; then
echo 'configure.sh failed' >&2
exit 3
fi
else
echo 'Skipping execution of ./configure'
fi
# Check configure status
# -------------------------
# Check that no unknown options have been used
unknown_options=
if [ -e "config.status" ]; then
unknown_options=`sed -ne '/Following unknown configure options were used/,/for available options/p' config.status | sed -n -e '$d' -e '/^$/d' -e '3,$p'`
fi
if [ -z "$unknown_options" -a -e "config.log" ]; then
unknown_options=`sed -n -r -e 's/configure:[^\020]+WARNING: unrecognized options: //p' config.log`
fi
# Abort if some unknown options were found
if [ -n "$unknown_options" ]; then
if [ $config_timestamp -le $tstamp ]; then
echo '' >&2
echo 'ERROR: The following unrecognized configure options were used:' >&2
echo '' >&2
echo $unknown_options >&2
echo '' >&2
echo "Check 'configure --help' for available options." >&2
fi
echo 'Please fix your configure options and try again.' >&2
exit 3
fi
# Build and install PHP
# -------------------------
# Clean working directory and build PHP
if [ $config_timestamp -gt $tstamp -o ! -f sapi/cli/php ]; then
make clean
make
if [ $? -gt 0 ]; then
echo 'make failed.'
exit 4
fi
else
echo 'Skipping executing of make'
fi
# Install PHP
make install
if [ $? -gt 0 ]; then
echo 'make install failed.'
exit 5
fi
# Create PHP configuration
# -------------------------
# Apply custom PHP.ini if available
echo ''
mkdir "$instdir/etc"
initarget="$instdir/etc/php.ini"
useCustom=0
if [ ! -f "$initarget" ]; then
for suffix in \
"" \
"-$VMAJOR" \
"-$VMAJOR.$VMINOR" \
"-$VMAJOR.$VMINOR.$VPATCH" \
"-$VMAJOR$FLAGS" \
"-$VMAJOR.$VMINOR$FLAGS" \
"-$VMAJOR.$VMINOR.$VPATCH$FLAGS" \
; do
custom="$basedir/custom/php$suffix.ini"
if [ -e "$custom" ]; then
if [ $useCustom -eq 0 ]; then
useCustom=1
sed -e 's#$ext_dir#'"$ext_dir"'#' "$custom" > "$initarget"
echo "Using custom php.ini: $custom"
else
sed -e 's#$ext_dir#'"$ext_dir"'#' "$custom" >> "$initarget"
echo "Appending custom php.ini: $custom"
fi
fi
done
else
useCustom=1
echo "Skipped creation of $initarget."
fi
# If no custom PHP.ini was found, copy the default one
cd "$srcdir"
if [ $useCustom -eq 0 ]; then
if [ -f "php.ini-recommended" ]; then
cp "php.ini-recommended" "$initarget"
echo "Copied php.ini-recommended to $initarget"
elif [ -f "php.ini-development" ]; then
cp "php.ini-development" "$initarget"
echo "Copied php.ini-recommended to $initarget"
else
echo 'No php.ini file found'
echo "Please copy it manually to $instdir/lib/php.ini"
fi
fi
echo ''
# Create binary symlinks
# -------------------------
# Create bin directory if necessary
[ ! -d "$shbindir" ] && mkdir "$shbindir"
if [ ! -d "$shbindir" ]; then
echo 'Cannot create shared binary directory.' >&2
exit 6
else
# Delete old symlinks if there are some
rm -f "$shbindir/php-$VERSION"
rm -f "$shbindir/php-cgi-$VERSION"
rm -f "$shbindir/php-fpm-$VERSION"
rm -f "$shbindir/phpconfig-$VERSION"
rm -f "$shbindir/phpize-$VERSION"
rm -f "$shbindir/pear-$VERSION"
rm -f "$shbindir/peardev-$VERSION"
rm -f "$shbindir/pecl-$VERSION"
rm -f "$shbindir/phar-$VERSION"
fi
# [Function] symlink
function symlink {
if [ -e "$1" ]; then
ln -fs "$1" "$2"
echo "Created symlink $1"
else
binary=`basename "$1"`
echo "NOTICE: No $binary binary found." >&2
fi
}
# Symlink PHP executable
bphp="$instdir/bin/php"
bphpgcno="$instdir/bin/php.gcno"
if [ -f "$bphp" ]; then
symlink "$bphp" "$shbindir/php-$VERSION"
elif [ -f "$bphpgcno" ]; then
symlink "$bphpgcno" "$shbindir/php-$VERSION"
else
echo 'No php binary found.' >&2
exit 7
fi
# Symlink PHP cgi executable
bphpcgi="$instdir/bin/php-cgi"
bphpcgigcno="$instdir/bin/php-cgi.gcno"
if [ -f "$bphpcgi" ]; then
symlink "$bphpcgi" "$shbindir/php-cgi-$VERSION"
elif [ -f "$bphpcgigcno" ]; then
symlink "$bphpcgigcno" "$shbindir/php-cgi-$VERSION"
else
echo 'NOTICE: No php-cgi binary found.' >&2
fi
# Symlink PHP fpm executable
symlink "$instdir/sbin/php-fpm" "$shbindir/php-fpm-$VERSION"
# Symlink PHP dbg executable
symlink "$instdir/bin/phpdbg" "$shbindir/phpdbg-$VERSION"
# Symlink php-config & phpize
symlink "$instdir/bin/php-config" "$shbindir/php-config-$VERSION"
symlink "$instdir/bin/phpize" "$shbindir/phpize-$VERSION"
# Finish PEAR installation if it was installed
if [ -e "$instdir/bin/pear" ]; then
symlink "$instdir/bin/pear" "$shbindir/pear-$VERSION"
symlink "$instdir/bin/peardev" "$shbindir/peardev-$VERSION"
symlink "$instdir/bin/pecl" "$shbindir/pecl-$VERSION"
fi
# Symlink PHAR if available
if [ -e "$instdir/bin/phar.phar" ]; then
symlink "$instdir/bin/phar.phar" "$shbindir/phar-$VERSION"
fi
# Post-install stuff
# -------------------------
# Execute post-install scripts if available
echo ''
echo 'Executing post-install scripts'
echo '-----------------------------------'
cd "$basedir"
for suffix in \
"" \
"-$VMAJOR" \
"-$VMAJOR.$VMINOR" \
"-$VMAJOR.$VMINOR.$VPATCH" \
"-$VMAJOR$FLAGS" \
"-$VMAJOR.$VMINOR$FLAGS" \
"-$VMAJOR.$VMINOR.$VPATCH$FLAGS" \
; do
post="$basedir/custom/post-install$suffix.sh"
if [ -e "$post" ]; then
echo ''
echo "Running commands from '$post'"
/bin/bash $post "$VERSION" "$instdir" "$shbindir"
fi
done
# Exit
echo ''
echo "PHP $VERSION installed."
exit 0