Tuesday, December 14, 2010

Zend Framework Local Deployment Script

Here is a deployment script I wrote to install Zend Framework on my local development computer. I use Gnu/Linux, so converting this for use on Windows is, at least for the time being, left as an exercise to the reader. Use it, improve it, throw it away, ignore it. Whatever you do with it, enjoy!

#! /bin/sh
# deploy latest ZF to LOCAL development machine
# run using sudo (make executable with chmod u+x deploy-zf-latest-to-local.sh)

# TARFILE_LOCATION is where the ZF tarball you downloaded resides
# TARGET_LOCATION is where ZF is to be deployed (and is my PHP include_path)
# PHP_BIN_DIR is where zf command line tool is to be deployed
# A symlink in ~/bin like this is useful: zf -> /usr/local/bin/zf.sh
# See http://framework.zend.com/manual/en/zend.tool.framework.clitool.html

ZF_BASENAME=ZendFramework-1.11.1
TARFILE_LOCATION=/home/clark/deploy/archives
TARGET_LOCATION=/usr/share/php
PHP_BIN_DIR=/usr/local/bin

if test `whoami` != root
then
    echo Please run using \"sudo\".
    exit
fi

# extract ZF from tarball
cd ${TARFILE_LOCATION}
tar -xzf ${ZF_BASENAME}.tar.gz

# remove prior version of ZF from the system; put the current version in place
cd ${TARGET_LOCATION}
rm -rf Zend
cp -r ${TARFILE_LOCATION}/${ZF_BASENAME}/library/Zend .
cp ${TARFILE_LOCATION}/${ZF_BASENAME}/bin/zf.sh ${TARFILE_LOCATION}/${ZF_BASENAME}/bin/zf.php ${PHP_BIN_DIR}/

# autoloading is always used, so remove require_once statements for performance
find ${TARGET_LOCATION}/Zend -name '*.php' -not -name 'Application.php' -not -wholename '*/Loader/Autoloader.php' -print0 | xargs -0 sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

# set up autoloading for zf.php command line tool
sed --regexp-extended --in-place "s/^(if \(!getenv\('ZF_NO_MAIN)/require_once 'Zend\/Loader\/Autoloader\.php'\; Zend_Loader_Autoloader::getInstance\(\)\;\n\1/g" ${PHP_BIN_DIR}/zf.php

# set file permissions, clean up extraction area, indicate what version we're running
chown -R root:root ${TARGET_LOCATION}/Zend/
rm -rf ${TARFILE_LOCATION}/${ZF_BASENAME}
# next line should reference PHP_BIN_DIR instead of hardcoding the directory
php -r 'include "/usr/share/php/Zend/Version.php"; echo "Running Version " . Zend_Version::VERSION . "\n";'

No comments:

Post a Comment