mksnapshot.sh
#!/bin/bash
function init_config()
{
echo
# Setup the build environment
source /etc/vcenv.sh $MSCVER
CVSROOT=:pserver:cvsread@cvs.php.net:/repository
SSH_URL="***@***"
SSH_DIR="/***/win32"
snap=`date -u +"%Y%m%d%H30"`
}
function print_usage()
{
echo "Usage: mksnapshot [-r <cvstag>] [-t] [-m <compiler version>] [-h]"
echo
echo "-r PHP CVS tag, PHP_5_2 for example"
echo "-t skip CVS checkout, assume files are in snap dir"
echo "-m compiler version, supported 6 and 8"
echo "-h prints this message"
exit 1
}
function proces_args()
{
TARBALL=""
WD=`dirname $0`
WD=`realpath $WD`
MSCVER="6"
BRANCH=""
while [ "$1" != "" ]; do
case $1 in
-t)
TARBALL="$WD/snap"
echo "Skipping cvs download"
;;
-r)
shift
BRANCH="-r $1"
;;
-m)
shift
MSCVER="$1"
if [ "$MSCVER" != "6" -a "$MSCVER" != "8" ]; then
echo "Error: unsupported compiler version"
echo
print_usage
fi
;;
-h)
print_usage
;;
*)
echo "Warning, unkown option $1"
esac
shift
done
}
function get_php_ver()
{
verstr=`grep "PHP_VERSION " $WD/snap/main/php_version.h | cut -f2 -d"\""`
vermaj=`grep "PHP_MAJOR_VERSION" $WD/snap/main/php_version.h | sed -e 's|\s+| |g' | cut -d " " -f3`
vermin=`grep "PHP_MINOR_VERSION" $WD/snap/main/php_version.h | sed -e 's|\s+| |g' | cut -d " " -f3`
verrel=`grep "PHP_RELEASE_VERSION" $WD/snap/main/php_version.h | sed -e 's|\s+| |g' | cut -d " " -f3`
verext=`grep "PHP_EXTRA_VERSION" $WD/snap/main/php_version.h | sed -e 's|\s+| |g' | cut -d "\"" -f2`
VER="$vermaj.$vermin"
VERU="$vermaj""_$vermin"
}
function do_cvs_checkout()
{
if [ "$TARBALL" = "" ]; then
echo
echo Checking out current cvs
echo ========================
cvscmd="cvs -d $CVSROOT -z3 checkout $BRANCH -d snap php-src-ze2"
echo $cvscmd > $WD/cvs.log
rm -rf $WD/snap
cd $WD
($cvscmd) >> $WD/cvs.log 2>&1
cd $WD/pecl
cvs -q update -dP >> $WD/cvs.log 2>&1
cd $WD
./cleanpecl.sh snap pecl >> $WD/cvs.log 2>&1
fi
}
function do_base_build()
{
echo
echo Building base package
echo =====================
cd $WD/snap
cmd /c buildconf.bat
cmd /c cscript /nologo configure.js --enable-snapshot-build --with-gd=shared
cmd /c nmake snap
cd $WD
}
function exit_with_msg()
{
echo $1
rm -f $WD/lock
exit $2
}
function do_check_build()
{
cd $WD
fname=$WD/snap/Release_TS/php-$verstr-Win32.zip
peclfname=$WD/snap/Release_TS/pecl-$verstr-Win32.zip
dbgpfname=$WD/snap/Release_TS/php-debug-pack-$verstr-Win32.zip
if [ -f "$fname" -a -f "$peclfname" -a -f "$dbgpfname" ]; then
echo "Build success"
else
exit_with_msg "Build failed" 1
fi
}
function build_installer()
{
echo
echo Buildinging installer
echo =====================
echo -n Unpacking files...
cd $WD/installer/win-installer
cvs upd -dP
rm -rf $WD/installer/tmp
cp -a $WD/installer/win-installer $WD/installer/tmp
cd $WD/installer/tmp
rm -rf Files
mkdir Files
cd Files
cp $WD/installer/php_manual_en.chm .
unzip $fname
mkdir PECL
cd PECL
unzip $peclfname
echo OK
cd $WD/installer/tmp
cmd /c build.bat "$verstr"
instfname=$WD/installer/tmp/php-$verstr-win32-installer.msi
if [ -f $instfname ]; then
echo SUCCESS
else
echo "Building installer failed"
instfname=""
fi
}
function do_delete_old()
{
for i in "php$VER-win32-2*.zip" "php$VER-dbgpack-win32-2*.zip" "pecl$VER-win32-2*.zip" "php$VER-win32-installer-2*.msi"; do
list=`ssh $SSH_URL "cd $SSH_DIR; ls -r $i 2>/dev/null"`
cmd="cd $SSH_DIR"
count=0
for j in $list; do
let count=count+1
if [ "$count" -gt "5" ]; then
cmd="$cmd; rm -f $j"
fi
done
if [ "$cmd" != "cd $SSH_DIR" ]; then
ssh $SSH_URL "$cmd"
fi
done
}
function do_upload_files()
{
echo
echo Uploading files to snaps.php.net
echo ===============================
cd $WD
scp -q $fname $SSH_URL:$SSH_DIR/php$VER-win32-$snap.zip
scp -q $dbgpfname $SSH_URL:$SSH_DIR/php$VER-dbgpack-win32-$snap.zip
scp -q $peclfname $SSH_URL:$SSH_DIR/pecl$VER-win32-$snap.zip
scp -q $WD/snapshot.log $SSH_URL:$SSH_DIR/snapshot-$VER.log
scp -q $WD/compile.log $SSH_URL:$SSH_DIR/compile-$VER.log
local_ssh_cmd="cd $SSH_DIR; rm -f php$VER-win32-latest.zip php$VER-dbgpack-win32-latest.zip pecl$VER-win32-latest.zip; ln -s php$VER-win32-$snap.zip php$VER-win32-latest.zip; ln -s pecl$VER-win32-$snap.zip pecl$VER-win32-latest.zip; ln -s php$VER-dbgpack-win32-$snap.zip php$VER-dbgpack-win32-latest.zip"
if [ "$instfname" != "" ]; then
scp -q $instfname $SSH_URL:$SSH_DIR/php$VER-win32-installer-$snap.msi
local_ssh_cmd="$local_ssh_cmd; rm -f php$VER-win32-installer-latest.msi; ln -s php$VER-win32-installer-$snap.msi php$VER-win32-installer-latest.msi"
fi
ssh $SSH_URL "$local_ssh_cmd"
}
proces_args "$@"
init_config
# Make sure only once instance is running
if [ -f $WD/lock ]; then
echo "Error: snapshot builder locked"
exit 1
fi
touch $WD/lock
rm -f $WD/snapshot.log
exec >> $WD/snapshot.log 2>&1
echo `date`
echo Starting snapshot $snap
echo ===============================
do_cvs_checkout
get_php_ver
do_base_build
do_check_build
build_installer
if [ "$TARBALL" != "" ]; then
exit_with_msg "Tarball build complete" 0
fi
# We used to have compile.log
echo "See snapshot.log" > "$WD/compile.log"
do_upload_files
do_delete_old
rm -f $WD/lock
Generated by GNU enscript 1.6.4.