手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >Shell脚本中实现更新PHP5
Shell脚本中实现更新PHP5
摘要:我很迷恋Shell,很喜欢看着字符在黑色的Console界面中跳跃着,奇怪的是,我居然没有因此成为一个Linux/Unix程序员,而只是个写...

我很迷恋 Shell,很喜欢看着字符在黑色的 Console 界面中跳跃着,奇怪的是,我居然没有因此成为一个 Linux/Unix 程序员,而只是个写 CGI 程序的倒霉蛋。大家都是怎么称呼 “PHP 程序员”的?对了——草根~ 嗯,在土里埋的太久,说不定哪天就烂掉了咯!

可能是被 Windows 惯坏了,实在不想换个 OS,还好有 Cygwin,MinGW … 之类的东西, 适当的时候,可以拿出来装下 B,自我安慰一下~

我总喜欢从 windows.php.net 下载最新的 snapshot,不是我想体验最新的功能,只是强迫症的关系-,-。我机器上的所有软件,程序都是最新的,绝大部分都还挂着 beta 标签,甚至有一些是直接从 SVN,Git 上面拖下来的 trunk 版本,想想真是变态。如果你每天都爬上这些网站,人肉检查一下是不是有新的版本发布,以此满足一下自己变态的心理,那真是要疯掉了。

能让机器干的事情,就不要手工去做,是吧!下面这段代码会自动去 check 最新的 snapshot,解压到你想要的目录。 然后呢?建个 cron job 挂上去,就可以去找新的乐子了~

代码中下载的是,None thead safe VC9 版本,注意替换成自己能用的版本。需要强制更新的话,加上 “–force” 参数。

最后一行使用 icacls 重置了 php5-nts 目录下文件的权限(注意路径的写法,icacls 是 windows 自己的程序),因为 cygwin 会把 NTFS 的权限搞的巨恶心。

PS: 非 CGI/FCGI 安装模式,记得关掉 Web Server。

#!/bin/bash INSTALL_PATH="/cygdrive/d/php5-nts" BUILD_TIME_FILE="/cygdrive/d/php5-nts/build-time" PACKAGE_URL="http://windows.php.net/downloads/snaps/php-5.3-nts-win32-VC9-x86-latest.zip" function uprint { if [ "${1:0:1}" = "-" ]; then echo $1 "# $2" else echo "# $1" fi } ## If unzip available? UNZIP=`which unzip 2> /dev/null` if [ -z $UNZIP ]; then uprint "Could not find unzip, please install." exit 1 fi ## Test if build-time file exists, if not, create it if [ ! -f $BUILD_TIME_FILE ]; then uprint -n "Build time file does not exists, created ... " touch $BUILD_TIME_FILE echo -e "e[32m[OK]e[0m" fi ## Get current build time CURRENT_BUILD_TIME=`cat $BUILD_TIME_FILE` ## Get latest build time LATEST_BUILD_TIME=`curl --silent http://windows.php.net/snapshots/ | grep "php-5.3-nts-VC9-x86" | grep "VC9 x86 Non Thread Safe (" | grep -o "(.*)" | sed 's/[()]//g'` ## Any update? package=`basename $PACKAGE_URL` if [ "$CURRENT_BUILD_TIME" != "$LATEST_BUILD_TIME" ]; then uprint -e "New version available, build time: e[36m$LATEST_BUILD_TIMEe[0m" else if [ "$1" != "--force" ]; then uprint "You are using the latest snapshot version." exit 0 else uprint -e "e[31mForce to update local php version.e[0m" fi fi ## Delete if file already exists ls $package > /dev/null 2>&1 if test $? -eq 0; then uprint -n "Performing: rm -f `ls $package` ... " rm -f `ls $package` echo -e "e[32m[OK]e[0m" fi ## Get latest php5 binary package uprint -n "Downloading latest php binary package ... " wget -q $PACKAGE_URL echo -e "e[32m[OK]e[0m" ## Extracting if [ -f $package ]; then # kill php processes for php_pid in `ps -as | grep php | awk '{print $1}'` do kill -9 $php_pid done uprint -n "Extracting ... " unzip -o $package -x -d $INSTALL_PATH > /dev/null 2>&1 echo -e "e[32m[OK]e[0m" echo $LATEST_BUILD_TIME > $BUILD_TIME_FILE uprint -n "Cleaning up ... " rm -f $package echo -e "e[32m[OK]e[0m" fi ## Fixed cygwin permissions icacls D:/php5-nts /reset /T > /dev/null # vim: set expandtab tabstop=4 shiftwidth=4:

【Shell脚本中实现更新PHP5】相关文章:

Shell脚本注释写法

shell脚本实现快速生成xml格式sitemap实例分享

shell 进度条实现代码

备份shell脚本实例代码

Shell脚本实现检测进程是否正在运行

Shell脚本for循环语句简明教程

Shell脚本实现查杀子进程、僵尸进程

Shell脚本实现防止国外ip访问服务器

Shell脚本实现apache日志中的状态码分析

Shell脚本实现启动PHP内置FastCGI Server

精品推荐
分类导航