我很迷戀 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 1fi ## Test if build-time file exists, if not, create itif [ ! -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 timeCURRENT_BUILD_TIME=`cat $BUILD_TIME_FILE` ## Get latest build timeLATEST_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" fifi ## Delete if file already existsls $package > /dev/null 2>&1if 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 packageuprint -n "Downloading latest php binary package ... "wget -q $PACKAGE_URLecho -e "/e[32m[OK]/e[0m" ## Extractingif [ -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 permissionsicacls D:/php5-nts /reset /T > /dev/null # vim: set expandtab tabstop=4 shiftwidth=4:
新聞熱點
疑難解答