-
Notifications
You must be signed in to change notification settings - Fork 33
/
php-install
executable file
·59 lines (51 loc) · 1.66 KB
/
php-install
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
#!/bin/bash
while getopts fh OPT
do
case $OPT in
"f") FLAG_FORCE="TRUE" ;;
"h") FLAG_HELP="TRUE" ;;
* ) FLAG_HELP="TRUE" ;;
esac
done
shift `expr $OPTIND - 1`
TARGET_VERSION="$1"
LOCATION="$2"
CONFIGURE_OPTIONS=${@:4:($#-3)}
if [ "x"$FLAG_HELP != "x" -o "x$LOCATION" = "x" ]; then
echo "[usage] php-install [-f] VERSION LOCATION -- CONFIGURE_OPTIONS"
echo " ex: php-install 5.5.10 ~/local/php-5.5.10 -- --with-pear"
exit 0
fi
cd $(dirname $0)
XBUILD_PATH=$(pwd)
if [ ! -d ./var/php-build ]; then
(
set -e
mkdir -p var
cd var
git clone -q https://github.com/php-build/php-build.git php-build-repo
cd php-build-repo
PREFIX="$XBUILD_PATH"/var/php-build ./install.sh >/dev/null 2>&1
)
if [ $? -ne 0 ]; then
echo "failed to download php-build"
exit 1
fi
fi
if [ "x"$FLAG_FORCE = "x" -a -d "$LOCATION" -a -x "$LOCATION/bin/php" ]; then
version_pattern=$(echo "$TARGET_VERSION" | sed -e 's/\./\\\./')
check=$("$LOCATION"/bin/php -v | head -1 | grep "$version_pattern")
if [ "x$check" != "x" ]; then
echo "php $TARGET_VERSION already installed on $LOCATION"
echo "To do force re-install, use '-f' option"
exit 0
fi
fi
echo "Start to build php $TARGET_VERSION ..."
PHP_BUILD_CONFIGURE_OPTS="$CONFIGURE_OPTIONS" ./var/php-build/bin/php-build "$TARGET_VERSION" "$LOCATION" > /tmp/$USER-php-install.log 2>&1
if [ $? -ne 0 ]; then
echo "php-build failed. see log: /tmp/$USER-php-install.log"
exit 1
fi
echo "php $TARGET_VERSION successfully installed on $LOCATION"
echo "To use this php, do 'export PATH=$LOCATION/bin:\$PATH'."