Implementing updates in shell scripts Php5_linux shell

Source: Internet
Author: User
Tags vc9 ntfs permissions


I'm obsessed with the Shell, and I like to watch the characters jump in the Black Console interface, and strangely, I didn't become a Linux/unix programmer, but just a bad egg to write a CGI program. What do people call "PHP programmers"? Right--grassroots ~ Well, buried in the soil too long, maybe one day will rot off!



may be spoiled by Windows, really do not want to change the OS, fortunately there are cygwin,mingw ... Things like that, when appropriate, you can take out to install the B, self comfort ~



I always like to download the latest snapshot from windows.php.net, not that I want to experience the latest features, but the relationship between obsessive-compulsive disorder-,-。 All the software on my machine, the program is up to date, most of them still have beta tags, even some of them are directly from the svn,git to drag down the trunk version, think really sick. If you climb these sites every day, human flesh check whether there is a new version of the release, so as to meet their abnormal psychology, it is really crazy.



If you can get the machine to do something, don't do it by hand. The following code will automatically check the latest snapshot and unzip to the directory you want. And then what? Set up a cron job to hang up, you can find a new fun ~



The Code downloads the None thead safe VC9 version, with a note to replace it with a version that is available to you. If you need to force an update, add the "–force" argument.



The last line uses ICACLS to reset the permissions on the files in the Php5-nts directory (note that the path is written, ICACLS is Windows own program), because Cygwin will make NTFS permissions a huge nausea.
PS: Non-cgi/fcgi installation mode, remember to turn off the 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:
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.