-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_swoole2.sh
147 lines (117 loc) · 4.12 KB
/
install_swoole2.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
run() {
# Run the compilation process.
echo "Debug Begin";
pwd
cd $MAGENTO_CLOUD_CACHE_DIR || pwd || exit 1;
SWOOLE_PROJECT=$1;
SWOOLE_VERSION=$2;
PHP_VERSION=$(php -r "echo PHP_VERSION;")
SWOOLE_BINARY="${SWOOLE_PROJECT}_v$2-php${PHP_VERSION}"
SWOOLE_BINARY="${SWOOLE_BINARY//\./_}"
if [ ! -f "${MAGENTO_CLOUD_CACHE_DIR}/${SWOOLE_BINARY}.so" ]; then
ensure_source "$SWOOLE_PROJECT" "$SWOOLE_VERSION"
compile_source "$SWOOLE_PROJECT"
move_extension "$SWOOLE_PROJECT" "$SWOOLE_BINARY"
fi
echo "Debug Before Copy Lib";
copy_lib "$SWOOLE_PROJECT" "$SWOOLE_BINARY"
# enable_lib "$SWOOLE_PROJECT"
}
copy_lib() {
echo "------------------------------------------------"
echo " Copying compiled extension to PLATFORM_APP_DIR "
echo "------------------------------------------------"
SWOOLE_PROJECT=$1;
SWOOLE_BINARY=$2;
cp "${MAGENTO_CLOUD_CACHE_DIR}/${SWOOLE_BINARY}.so" "${MAGENTO_CLOUD_APP_DIR}/${SWOOLE_PROJECT}.so"
}
enable_lib() {
echo "-------------------------------"
echo " Enabling extension in php.ini "
echo "-------------------------------"
SWOOLE_PROJECT=$1;
echo "extension=${MAGENTO_CLOUD_APP_DIR}/${SWOOLE_PROJECT}.so" >> $MAGENTO_CLOUD_APP_DIR/php.ini
}
move_extension() {
echo "---------------------------------------"
echo " Moving and caching compiled extension "
echo "---------------------------------------"
SWOOLE_PROJECT=$1;
SWOOLE_BINARY=$2;
echo "Debug move move_extension path";
pwd
mv "${MAGENTO_CLOUD_CACHE_DIR}/${SWOOLE_PROJECT}/swoole-src/modules/${SWOOLE_PROJECT}.so" "${MAGENTO_CLOUD_CACHE_DIR}/${SWOOLE_BINARY}.so"
}
ensure_source() {
echo "---------------------------------------------------------------------"
echo " Ensuring that the extension source code is available and up to date "
echo "---------------------------------------------------------------------"
SWOOLE_PROJECT=$1;
SWOOLE_VERSION=$2;
mkdir -p "$MAGENTO_CLOUD_CACHE_DIR/$SWOOLE_PROJECT"
cd "$MAGENTO_CLOUD_CACHE_DIR/$SWOOLE_PROJECT" || exit 1;
if [ -d "swoole-src" ]; then
cd swoole-src || exit 1;
git fetch --all --prune
else
git clone https://github.com/$SWOOLE_PROJECT/swoole-src.git swoole-src
cd swoole-src || exit 1;
git checkout "v$SWOOLE_VERSION"
fi
if [ -d "valgrind" ]; then
cd valgrind || exit 1;
git fetch --all --prune
else
git clone git://sourceware.org/git/valgrind.git valgrind
cd valgrind || exit 1;
fi
}
compile_source() {
SWOOLE_PROJECT=$1;
echo "--------------------"
echo " Compiling valgrind "
echo "--------------------"
./autogen.sh
./configure --prefix="$MAGENTO_CLOUD_CACHE_DIR/$SWOOLE_PROJECT/swoole-src"
make
make install
echo "---------------------"
echo " Compiling extension "
echo "---------------------"
cd ..
phpize
./configure --enable-openssl \
--enable-mysqlnd \
--enable-sockets \
--enable-http2 \
--with-postgres
make
}
ensure_environment() {
# If not running in a Platform.sh build environment, do nothing.
if [ -z "${MAGENTO_CLOUD_CACHE_DIR}" ]; then
echo "Not running in a Platform.sh build environment. Aborting Open Swoole installation."
exit 0;
fi
}
ensure_arguments() {
# If no Swoole repository was specified, don't try to guess.
if [ -z $1 ]; then
echo "No version of the Swoole project specified. (swoole/openswoole)."
exit 1;
fi
if [[ ! "$1" =~ ^(swoole|openswoole)$ ]]; then
echo "The requested Swoole project is not supported: ${1} Aborting.\n"
exit 1;
fi
# If no version was specified, don't try to guess.
if [ -z $2 ]; then
echo "No version of the ${1} extension specified. You must specify a tagged version on the command line."
exit 1;
fi
}
ensure_environment
ensure_arguments "$1" "$2"
SWOOLE_PROJECT=$1;
SWOOLE_VERSION=$(sed "s/^[=v]*//i" <<< "$2" | tr '[:upper:]' '[:lower:]')
run "$SWOOLE_PROJECT" "$SWOOLE_VERSION"