• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > Shell脚本中实现更新PHP5

Shell脚本中实现更新PHP5

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了shell脚本,shell脚本编程,shell脚本学习指南,shell脚本实例,linux shell脚本等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

我很迷恋 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_TIME\e[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:
</div> </div>

您可能想查找下面的文章:

  • Shell脚本监控目录内文件改动
  • 实现自动清除日期目录shell脚本实例代码
  • 使用Linux shell脚本实现FTP定时执行批量下载指定文件
  • shell脚本连接并重启远程服务器的方法
  • shell 脚本安装PHP扩展的简单方法
  • Linux shell脚本输出日志笔记整理(必看篇)
  • shell脚本实现分日志级别输出的方法
  • shell将脚本输出结果记录到日志文件的实现
  • 输出执行操作和打印日志的shell脚本实例
  • shell脚本 自动创建用户详解及实例代码

相关文章

  • Shell脚本遍历一个日期范围实例
  • Shell逐行读取文件的4种方法
  • 实现自动清除日期目录shell脚本实例代码
  • Shell中取今天、昨天、前天的时间操作代码
  • 实现MySQL定时批量检查表repair和优化表optimize table的shell脚本
  • linux shell之文件锁
  • Cygwin下安装vim后,vim中退格键无法正常使用的解决方法
  • 分享个简易版Linux服务器初始化Shell脚本
  • Shell脚本数组用法小结
  • shell脚本编程之循环语句学习笔记

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • GitBook 制作电子书详细教程
    • shell脚本echo输出不换行功能增强实例
    • 杀掉oracle在线用户脚本分享
    • 消耗CPU资源的shell脚本
    • Linux系统中bash shell编程的10个基础问题讲解
    • Shell编程中while与for的区别及用法详解
    • shell脚本从SVN推送到多台服务器的代码
    • Shell脚本实现查找字符串中某字符最后出现的位置
    • Nginx和PHP-FPM的启动、重启、停止脚本分享
    • Linux 中(加、减、乘、除)实例详解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有