This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
upgrade.sh
371 lines (318 loc) · 10.1 KB
/
upgrade.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!"
exit 1
fi
LANMP_PATH=`pwd`
if [ `echo $LANMP_PATH | awk -F/ '{print $NF}'` != "lanmp" ]; then
clear && echo "Please enter lanmp script path:"
read -p "(Default path: ${LANMP_PATH}/lanmp):" LANMP_PATH
[ -z "$LANMP_PATH" ] && LANMP_PATH=$(pwd)/lanmp
cd $LANMP_PATH/
fi
clear
echo "#############################################################"
echo "# LANMP Auto Update Script"
echo "# Env: Redhat/CentOS"
echo "# Intro: https://wangyan.org/blog/lanmp.html"
echo "# Version: $(awk '/version/{print $2}' $LANMP_PATH/Changelog)"
echo "#"
echo "# Copyright (c) 2012, WangYan <WangYan@188.com>"
echo "# All rights reserved."
echo "# Distributed under the GNU General Public License, version 3.0."
echo "#"
echo "#############################################################"
echo ""
echo "Please enter the webroot dir:"
read -p "(Default webroot dir: /var/www):" WEBROOT
if [ -z $WEBROOT ]; then
WEBROOT="/var/www"
fi
echo "---------------------------"
echo "Webroot dir=$WEBROOT"
echo "---------------------------"
echo ""
echo "Please choose webserver software! (1:nginx,2:apache,3:nginx+apache) (1/2/3)"
read -p "(Default: 3):" SOFTWARE
if [ -z $SOFTWARE ]; then
SOFTWARE="3"
fi
echo "---------------------------"
echo "You choose = $SOFTWARE"
echo "---------------------------"
echo ""
######################### PHP5 #########################
LATEST_PHP=$(curl -s http://www.php.net/downloads.php | awk '/Current Stable/{print $3}')
INSTALLED_PHP=$(php -r 'echo PHP_VERSION;' 2>/dev/null)
echo -e "Latest version of PHP: \033[41;37m $LATEST_PHP \033[0m"
echo -e "Installed version of PHP: \033[41;37m $INSTALLED_PHP \033[0m"
echo ""
if [ "$INSTALLED_PHP" != "5.2.17p1" ];then
echo "Do you want to upgrade PHP ? (y/n)"
read -p "(Default: n):" UPGRADE_PHP
if [ -z $UPGRADE_PHP ]; then
UPGRADE_PHP="n"
fi
echo "---------------------------"
echo "You choose = $UPGRADE_PHP"
echo "---------------------------"
echo ""
fi
######################### Nginx #########################
if [ "$SOFTWARE" != 2 ];then
INSTALLED_NGINX=$(echo `nginx -v 2>&1` | cut -d '/' -f 2)
LATEST_NGINX=$(curl -s http://nginx.org/| awk -F- '/nginx-/{print $6}' | head -1|cut -d '<' -f 1)
echo -e "Latest version of Nginx: \033[41;37m $LATEST_NGINX \033[0m"
echo -e "Installed version of Nginx: \033[41;37m $INSTALLED_NGINX \033[0m"
echo ""
echo "Do you want to upgrade Nginx ? (y/n)"
read -p "(Default: n):" UPGRADE_NGINX
if [ -z $UPGRADE_NGINX ]; then
UPGRADE_NGINX="n"
fi
echo "---------------------------"
echo "You choose = $UPGRADE_NGINX"
echo "---------------------------"
echo ""
fi
######################### phpMyAdmin #########################
if [ ! -s "$LANMP_PATH/version.txt" ]; then
echo -e "phpmyadmin\t0" > $LANMP_PATH/version.txt
fi
INSTALLED_PMA=$(awk '/phpmyadmin/{print $2}' $LANMP_PATH/version.txt)
LATEST_PMA=$(elinks http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/ | awk -F/ '{print $7F}' | sort -n | grep -iv '-' | tail -1)
echo -e "Latest version of phpmyadmin: \033[41;37m $LATEST_PMA \033[0m"
echo -e "Installed version of phpmyadmin: \033[41;37m $INSTALLED_PMA \033[0m"
echo ""
echo "Do you want to upgrade phpmyadmin ? (y/n)"
read -p "(Default: n):" UPGRADE_PMA
if [ -z $UPGRADE_PMA ]; then
UPGRADE_PMA="n"
fi
echo "---------------------------"
echo "You choose = $UPGRADE_PMA"
echo "---------------------------"
echo ""
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo "Press any key to start Upgrade..."
echo "Or Ctrl+C cancel and exit ?"
echo ""
char=`get_char`
######################### Extract Function #########################
Extract(){
local TARBALL_TYPE
if [ -n $1 ]; then
SOFTWARE_NAME=`echo $1 | awk -F/ '{print $NF}'`
TARBALL_TYPE=`echo $1 | awk -F. '{print $NF}'`
wget -c -t3 -T3 $1 -P $LANMP_PATH/
if [ $? != "0" ];then
rm -rf $LANMP_PATH/$SOFTWARE_NAME
wget -c -t3 -T60 $2 -P $LANMP_PATH/
SOFTWARE_NAME=`echo $2 | awk -F/ '{print $NF}'`
TARBALL_TYPE=`echo $2 | awk -F. '{print $NF}'`
fi
else
SOFTWARE_NAME=`echo $2 | awk -F/ '{print $NF}'`
TARBALL_TYPE=`echo $2 | awk -F. '{print $NF}'`
wget -c -t3 -T3 $2 -P $LANMP_PATH/ || exit
fi
EXTRACTED_DIR=`tar tf $LANMP_PATH/$SOFTWARE_NAME | tail -n 1 | awk -F/ '{print $1}'`
case $TARBALL_TYPE in
gz|tgz)
tar zxf $LANMP_PATH/$SOFTWARE_NAME -C $LANMP_PATH/ && cd $LANMP_PATH/$EXTRACTED_DIR || return 1
;;
bz2|tbz)
tar jxf $LANMP_PATH/$SOFTWARE_NAME -C $LANMP_PATH/ && cd $LANMP_PATH/$EXTRACTED_DIR || return 1
;;
tar|Z)
tar xf $LANMP_PATH/$SOFTWARE_NAME -C $LANMP_PATH/ && cd $LANMP_PATH/$EXTRACTED_DIR || return 1
;;
*)
echo "$SOFTWARE_NAME is wrong tarball type ! "
esac
}
echo "===================== PHP5 Upgrade ===================="
if [[ "$UPGRADE_PHP" = "y" && "$INSTALLED_PHP" > 5 ]];then
if [[ -d "/usr/local/php.bak" && -d "/usr/local/php" ]];then
rm -rf /usr/local/php.bak/
fi
\mv /usr/local/php /usr/local/php.bak
cd $LANMP_PATH
if [ ! -s php-5.5.*.tar.gz ]; then
LATEST_PHP_LINK="http://php.net/distributions/php-${$LATEST_PHP}.tar.gz"
BACKUP_PHP_LINK="http://wangyan.org/download/lanmp-src/php-latest.tar.gz"
Extract ${LATEST_PHP_LINK} ${BACKUP_PHP_LINK}
else
tar -zxf php-5.5.*.tar.gz
cd php-5.5.*/
fi
if [ "$SOFTWARE" != "1" ]; then
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-curl \
--with-curlwrappers \
--with-freetype-dir \
--with-gettext \
--with-gd \
--with-iconv-dir \
--with-jpeg-dir \
--with-libxml-dir \
--with-mcrypt \
--with-mhash \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-openssl \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-zlib \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-gd-native-ttf \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--enable-zip
else
./configure \
--prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gettext \
--with-gd \
--with-iconv-dir \
--with-jpeg-dir \
--with-libxml-dir \
--with-mcrypt \
--with-mhash \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-openssl \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-zlib \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-fpm \
--enable-ftp \
--enable-gd-native-ttf \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--enable-zip
fi
make ZEND_EXTRA_LIBS='-liconv'
make install
echo "---------- PHP Extension ----------"
PHP_EXT1=`ls /usr/local/php.bak/lib/php/extensions/`
PHP_EXT2=`ls /usr/local/php/lib/php/extensions/`
mkdir -p /usr/local/php/lib/php/extensions/${PHP_EXT2}
cp /usr/local/php.bak/lib/php/extensions/${PHP_EXT1}/* /usr/local/php/lib/php/extensions/${PHP_EXT2}
echo "---------- PHP Config ----------"
cp /usr/local/php.bak/lib/php.ini /usr/local/php/lib/php.ini
if [ "$SOFTWARE" != "1" ]; then
pkill httpd
/etc/init.d/httpd start
else
cp /usr/local/php.bak/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf
pkill php-fpm
/etc/init.d/php-fpm start
fi
rm -rf $LANMP_PATH/src/{php-*,memcache-*,xcache-*}
fi
echo "===================== Nginx Upgrade ===================="
if [[ "$UPGRADE_NGINX" = "y" || "$UPGRADE_NGINX" = "Y" ]];then
cd $LANMP_PATH
if [ ! -s nginx-${LATEST_NGINX}.tar.gz ]; then
LATEST_NGINX_LINK="http://nginx.org/download/nginx-$LATEST_NGINX.tar.gz"
BACKUP_NGINX_LINK="http://wangyan.org/download/lanmp-src/nginx-latest.tar.gz"
Extract ${LATEST_NGINX_LINK} ${BACKUP_NGINX_LINK}
else
tar -zxf nginx-${LATEST_NGINX}.tar.gz
cd nginx-${LATEST_NGINX}/
fi
./configure \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-mail \
--with-mail_ssl_module \
--with-pcre \
--with-debug \
--with-ipv6 \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi
make
\mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp objs/nginx /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -t
make upgrade
echo "Upgrade completed!"
/usr/local/nginx/sbin/nginx -v
echo ""
/etc/init.d/nginx restart
rm -rf $LANMP_PATH/src/nginx-*
fi
echo "===================== phpMyAdmin Upgrade ===================="
if [[ "$UPGRADE_PMA" = "y" || "$UPGRADE_PMA" = "Y" ]];then
PMA_LINK="http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin"
mv $WEBROOT/phpmyadmin/config.inc.php $WEBROOT/config.inc.php
rm -rf $WEBROOT/phpmyadmin/
if [ ! -s phpMyAdmin-${LATEST_PMA}-all-languages.tar.gz ]; then
LATEST_PMA_LINK="${PMA_LINK}/${LATEST_PMA}/phpMyAdmin-${LATEST_PMA}-all-languages.tar.gz"
BACKUP_PMA_LINK="http://wangyan.org/download/lanmp/phpMyAdmin-latest-all-languages.tar.gz"
Extract ${LATEST_PMA_LINK} ${BACKUP_PMA_LINK}
mkdir -p $WEBROOT/phpmyadmin
mv * $WEBROOT/phpmyadmin
else
tar -zxf phpMyAdmin-${LATEST_PMA}-all-languages.tar.gz -C $WEBROOT
mv $WEBROOT/phpMyAdmin-${LATEST_PMA}-all-languages $WEBROOT/phpmyadmin
fi
mv $WEBROOT/config.inc.php $WEBROOT/phpmyadmin/
sed -i '/phpmyadmin/d' $LANMP_PATH/version.txt
echo -e "phpmyadmin\t${LATEST_PMA}" >> $LANMP_PATH/version.txt 2>&1
rm -rf $LANMP_PATH/src/phpMyAdmin-*
fi
if [ ! -d "$LANMP_PATH/src" ];then
mkdir -p $LANMP_PATH/src/
fi
\mv $LANMP_PATH/{*gz,*-*/,ioncube,package.xml} $LANMP_PATH/src >/dev/null 2>&1