new script to build egroupware archives

This commit is contained in:
Ralf Becker 2009-06-01 11:53:03 +00:00
parent 2d7f5720cd
commit b65c8fbf61
2 changed files with 347 additions and 155 deletions

View File

@ -1,155 +0,0 @@
#!/bin/bash -x
# This script work for generating rpms without Root rights
# When you create rmp's with Root rights and you have as example
# the follow command rm -rf / in your script you are in trouble :-)
#
# Change the path names for ANONCVSDIR and RHBASE to you needs.
#
# When you would create daily rpm's with update from CVS include
# delete the # sign at the start from the follow lines
#
# cd $ANONCVSDIR
# cvs update -Pd
# This scipt create auotmaticly signed rpm's
# When you don't want signed rpm's change the follow line from
#
# rpmbuild -bb --sign egroupware-rh.spec >> $LOGFILE 2>&1
#
# to
# rpmbuild -bb egroupware-rh.spec >> $LOGFILE 2>&1
#
# in the script
# How to create GPG keys to sign your rpm's you will found in a seperate
# Document
#
# Script changed 2004 May 21 Reiner Jung
# Script changed 2005 Apr 15 by Ralf Becker and Wim Bonis
# 2005 Sep 20 Ralf Becker: disabled fedora 2 build
#SVNURL="http://svn.egroupware.org/egroupware/branches/1.6/"
#SVNURL="http://svn.egroupware.org/egroupware/tags/1.6pre1/"
SVNURL="http://svn.egroupware.org/egroupware/trunk/"
SPECFILE="egroupware-1.6.spec"
SOURCEFILES="egroupware_fedora.tar.bz2 egroupware_suse.tar.bz2 manageheader.php.patch class.uiasyncservice.inc.php.patch"
CONTRIB="gallery icalsrv mydms"
EXTRAPACKAGES="egw-pear $CONTRIB"
for p in $EXTRAPACKAGES
do
EXCLUDE_CONTRIB="$EXCLUDE_CONTRIB --exclude=egroupware/$p"
ONLY_CONTRIB="$ONLY_CONTRIB egroupware/$p"
done
PACKAGENAME=`grep "%define packagename" $SPECFILE | cut -f3 -d' '`
VERSION=`grep "%define egwversion" $SPECFILE | cut -f3 -d' '`
PACKAGING=`grep "%define packaging" $SPECFILE | cut -f3 -d' '`
HOMEBUILDDIR=`whoami`
ANONCVSDIR=/tmp/build_root/egw_buildroot-svn
NOSVNDIR=/tmp/build_root/egw_buildroot
RHBASE=$HOME/rpm
SRCDIR=$RHBASE/SOURCES
SPECDIR=$RHBASE/SPECS
LOGFILE=$RHBASE/LOG/build-$PACKAGENAME-$VERSION.$PACKAGING.log
VIRUSSCAN=$SPECDIR/clamav_scan-$PACKAGENAME-$VERSION.$PACKAGING.log
MD5SUM=$SRCDIR/md5sum-$PACKAGENAME-$VERSION.$PACKAGING.txt
mkdir -p $RHBASE/SOURCES $RHBASE/SPECS $RHBASE/BUILD $RHBASE/SRPMS $RHBASE/RPMS $RHBASE/LOG $ANONCVSDIR $NOSVNDIR
cp *.spec $RHBASE/SPECS/
cp $SOURCEFILES $RHBASE/SOURCES/
echo "Starting build process of - $PACKAGENAME $VERSION" > $LOGFILE
echo "" >> $LOGFILE 2>&1
date >> $LOGFILE 2>&1
cd $ANONCVSDIR
if [ ! -d egroupware/phpgwapi ] # new checkout
then
if [ -z "$SVNREVISION" ]; then
echo -n "Creating a new checkout ... " >> $LOGFILE 2>&1
svn checkout $SVNURL"aliases/default" ./
else
echo -n "Creating a new checkout for revision $SVNREVISION ... " >> $LOGFILE 2>&1
svn checkout -r $SVNREVISION $SVNURL"aliases/default" ./
fi
cd egroupware
for CONTRIBMODULE in $CONTRIB; do
if [ -z "$CONTRIB_SVNREVISION" ]; then
svn checkout $SVNURL"$CONTRIBMODULE"
else
svn checkout -r $SVNREVISION $SVNURL"$CONTRIBMODULE"
fi
done
else
[ -z "$SVNREVISION" ] && SVNREVISION=HEAD
echo -n "Updating existing checkout ... " >> $LOGFILE 2>&1
cd egroupware
svn update -r $SVNREVISION . *
fi
cd $ANONCVSDIR
echo "done" >> $LOGFILE 2>&1
echo -n "Change directory rights back ... " >> $LOGFILE 2>&1
chmod -R u=rwX,g=rX,o=rX . >> $LOGFILE 2>&1
chmod +x egroupware/*/*cli.php egroupware/phpgwapi/cron/*.php >> $LOGFILE 2>&1
echo "done" >> $LOGFILE 2>&1
echo -n "Starting anti virus scan ... " >> $LOGFILE 2>&1
test -x /usr/bin/clamscan && /usr/bin/clamscan --quiet -r $ANONCVSDIR --log=$VIRUSSCAN
echo "done" >> $LOGFILE 2>&1
rm -rf $NOSVNDIR/egroupware
cp -ra $ANONCVSDIR/egroupware $NOSVNDIR
find $NOSVNDIR -name .svn | xargs rm -rf
cd $NOSVNDIR
echo -n "building tar.gz ... " >> $LOGFILE 2>&1
tar --owner=root --group=root -czf $SRCDIR/$PACKAGENAME-$VERSION.$PACKAGING.tar.gz $EXCLUDE_CONTRIB egroupware 2>&1 | tee -a $LOGFILE
for CONTRIBMODULE in $EXTRAPACKAGES; do
tar --owner=root --group=root -czf $SRCDIR/$PACKAGENAME-$CONTRIBMODULE-$VERSION.$PACKAGING.tar.gz egroupware/$CONTRIBMODULE >> $LOGFILE 2>&1
done
echo "done" >> $LOGFILE 2>&1
echo -n "building tar.bz2 ... " >> $LOGFILE 2>&1
tar --owner=root --group=root -cjf $SRCDIR/$PACKAGENAME-$VERSION.$PACKAGING.tar.bz2 $EXCLUDE_CONTRIB egroupware >> $LOGFILE 2>&1
for CONTRIBMODULE in $EXTRAPACKAGES; do
tar --owner=root --group=root -cjf $SRCDIR/$PACKAGENAME-$CONTRIBMODULE-$VERSION.$PACKAGING.tar.bz2 egroupware/$CONTRIBMODULE >> $LOGFILE 2>&1
done
echo "done" >> $LOGFILE 2>&1
echo -n "building zip ... " >> $LOGFILE 2>&1
for CONTRIBMODULE in $EXTRAPACKAGES; do
zip -q -r -9 $SRCDIR/$PACKAGENAME-$CONTRIBMODULE-$VERSION.$PACKAGING.zip egroupware/$CONTRIBMODULE >> $LOGFILE 2>&1
done
rm -rf $ONLY_CONTRIB >> $LOGFILE 2>&1
zip -q -r -9 $SRCDIR/$PACKAGENAME-$VERSION.$PACKAGING.zip egroupware >> $LOGFILE 2>&1
echo "done" >> $LOGFILE 2>&1
echo "Building tar.gz, tar.bz and zip archives finnished" >> $LOGFILE 2>&1
echo "------------------------------------------" >> $LOGFILE 2>&1
echo "Create the md5sum file for tar.gz, tar.bz, zip ($MD5SUM)" >> $LOGFILE 2>&1
echo "------------------------------------------" >> $LOGFILE 2>&1
cd $SRCDIR
for f in eGroupware*-$VERSION.$PACKAGING.*
do
md5sum $f >> $MD5SUM 2>&1
done
echo "sign the md5sum file" >> $LOGFILE 2>&1
rm -f $MD5SUM.asc >> $LOGFILE 2>&1
gpg --local-user packager@egroupware.org --clearsign $MD5SUM >> $LOGFILE 2>&1
echo "delete the original md5sum file" >> $LOGFILE 2>&1
rm -rf $MD5SUM >> $LOGFILE 2>&1
echo "------------------------------------------" >> $LOGFILE 2>&1
echo "End Create md5sum of tar.gz, tar.bz, zip" >> $LOGFILE 2>&1
echo "------------------------------------------" >> $LOGFILE 2>&1
echo "Building of $PACKAGENAME $VERSION finnished" >> $LOGFILE 2>&1

View File

@ -0,0 +1,347 @@
#!/usr/bin/php -qC
<?php
/**
* EGroupware - checkout and build EGroupware tgz
*
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @author RalfBecker@outdoor-training.de
* @version $Id$
*/
if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling setup-cli as web-page
{
die('<h1>checkout-build-tgz.php must NOT be called as web-page --> exiting !!!</h1>');
}
$verbose = 0;
$config = array(
'packagename' => 'eGroupware',
'version' => 'trunk', // '1.6'
'packaging' => date('Ymd'), // '001'
'egwdir' => 'egroupware',
'svndir' => '/tmp/build_root/egw_buildroot-svn',
'egw_buildroot' => '/tmp/build_root/egw_buildroot',
'sourcedir' => '~/rpm/SOURCES',
'svnbase' => 'http://svn.egroupware.org/egroupware',
'svnbranch' => 'trunk', // 'branches/1.6' or 'tags/1.6.001'
'svnalias' => 'aliases/default', // default alias
'aliasdir' => 'egroupware', // directory created by the alias
'extra' => array('egw-pear','gallery','mydms','icalsrv'),
'types' => array('tar.bz2','tar.gz','zip'),
'svn' => '/usr/bin/svn',
'clamscan' => '/usr/bin/clamscan',
'freshclam' => '/usr/bin/freshclam',
'skip' => array(),
'run' => array('checkout','copy','virusscan','create','sign')
);
// process config from command line
$argv = $_SERVER['argv'];
$prog = array_shift($argv);
while(($arg = array_shift($argv)))
{
if ($arg == '-v' || $arg == '--verbose')
{
++$verbose;
}
elseif($arg == '-h' || $arg == '--help')
{
usage();
}
elseif(substr($arg,0,2) == '--' && isset($config[$name=substr($arg,2)]))
{
$value = array_shift($argv);
switch($name)
{
case 'extra': // stored as array and allow to add/delete items with +/- prefix
case 'types':
case 'skip':
case 'run':
if ($value[0] == '+')
{
$config[$name] = array_unique(array_merge($config['name'],split('[ ,]+',$value)));
}
elseif ($value[0] == '-')
{
$config[$name] = array_diff($config['name'],split('[ ,]+',$value));
}
else
{
$config[$name] = array_unique(split('[ ,]+',$value));
}
break;
default:
$config[$name] = $value;
break;
}
}
else
{
usage("Unknown argument '$arg'!");
}
}
if ($verbose > 1)
{
echo "Using following config:\n";
print_r($config);
}
$svn = $config['svn'];
foreach(array_diff($config['run'],$config['skip']) as $func)
{
$func = 'do_'.$func;
$func();
}
/**
* Sign sha1sum file
*/
function do_sign()
{
global $config,$verbose;
if (substr($config['sourcedir'],0,2) == '~/') // sha1_file cant deal with '~/rpm'
{
$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'],1);
}
$sumsfile = $config['sourcedir'].'/sha1sum-'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.txt';
if (!file_exists($sumsfile))
{
echo "sha1sum file '$sumsfile' not found!\n";
return;
}
// signing it
if (!file_exists('/usr/bin/gpg'))
{
echo "/usr/bin/gpg not found --> skipping signing sha1sum file!\n";
return;
}
echo "Signing sha1sum file:\n";
if (file_exists($sumsfile.'.asc')) unlink($sumsfile.'.asc');
$cmd = '/usr/bin/gpg --local-user packager@egroupware.org --clearsign '.$sumsfile;
run_cmd($cmd);
unlink($sumsfile); // delete the unsigned file
}
/**
* Create archives
*/
function do_create()
{
global $config,$verbose;
if (!file_exists($config['sourcedir'])) mkdir($config['sourcedir'],0755,true);
if (substr($config['sourcedir'],0,2) == '~/') // sha1_file cant deal with '~/rpm'
{
$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'],1);
}
$sumsfile = $config['sourcedir'].'/sha1sum-'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.txt';
$sums = '';
chdir($config['egw_buildroot']);
if($config['extra'])
{
$exclude_extra = ' --exclude=egroupware/'.implode(' --exclude=egroupware/',$config['extra']);
}
foreach($config['types'] as $type)
{
echo "Creating $type archives\n";
$tar_type = $type == 'tar.bz2' ? 'j' : 'z';
$file = $config['sourcedir'].'/'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.'.$type;
switch($type)
{
case 'tar.bz2':
case 'tar.gz':
$cmd = '/bin/tar --owner=root --group=root -c'.$tar_type.'f '.$file.' '.$exclude_extra.' egroupware';
break;
case 'zip':
$cmd = '/bin/mv egroupware/'.implode(' egroupware/',$config['extra']).' . ;';
$cmd .= '/usr/bin/zip -q -r -9 '.$file.' egroupware ;';
$cmd .= '/bin/mv '.implode(' ',$config['extra']).' egroupware';
break;
}
run_cmd($cmd);
$sums .= sha1_file($file)."\t".basename($file)."\n";
foreach($config['extra'] as $module)
{
$file = $config['sourcedir'].'/'.$config['packagename'].'-'.$module.'-'.$config['version'].'.'.$config['packaging'].'.'.$type;
switch($type)
{
case 'tar.bz2':
case 'tar.gz':
$cmd = '/bin/tar --owner=root --group=root -c'.$tar_type.'f '.$file.' egroupware/'.$module;
break;
case 'zip':
$cmd = '/usr/bin/zip -q -r -9 '.$file.' egroupware/'.$module;
break;
}
run_cmd($cmd);
$sums .= sha1_file($file)."\t".basename($file)."\n";
}
}
// writing sha1sum file
file_put_contents($sumsfile,$sums);
}
/**
* Scan checkout for viruses, if clamscan is installed (not fatal if not!)
*/
function do_virusscan()
{
global $config,$verbose;
if (!file_exists($config['clamscan']) || !is_executable($config['clamscan']))
{
echo "Virusscanner '$config[clamscan]' not found --> skipping virus scan!\n";
return;
}
// try updating virus database
if (file_exists($config['freshclam']))
{
echo "Updating virus signatures\n";
$cmd = '/usr/bin/sudo '.$config['freshclam'];
if (!$verbose && function_exists('posix_getuid') && posix_getuid()) echo $cmd."\n";
run_cmd($cmd,$output,1); // 1 = ignore already up to date database
}
echo "Starting virusscan\n";
$cmd = $config['clamscan'].' --quiet -r '.$config['egw_buildroot'];
run_cmd($cmd);
echo "Virusscan successful (no viruses found).\n";
}
/**
* Copy non .svn parts to egw_buildroot and fix permissions and ownership
*/
function do_copy()
{
global $config;
// copy everything, but .svn dirs from svndir to egw_buildroot
echo "Copying non-svn dirs to buildroot\n";
$cmd = '/usr/bin/rsync -r --delete --exclude .svn '.$config['svndir'].'/'.$config['aliasdir'].' '.$config['egw_buildroot'];
run_cmd($cmd);
// fix permissions
echo "Fixing permissions\n";
chdir($config['egw_buildroot'].'/'.$config['aliasdir']);
$cmd = '/bin/chmod -R a-x,u=rwX,g=rX,o=rX .';
run_cmd($cmd);
$cmd = '/bin/chmod +x */*cli.php phpgwapi/cron/*.php svn-helper.php';
run_cmd($cmd);
}
/**
* Checkout or update EGroupware
*
* Ensures an existing checkout is from the correct branch! Otherwise it get's deleted
*/
function do_checkout()
{
global $config,$svn,$verbose;
echo "Starting svn checkout/update\n";
if (!file_exists($config['svndir']))
{
mkdir($config['svndir'],0755,true);
}
elseif (!is_dir($config['svndir']) || !is_writable($config['svndir']))
{
throw new Exception("svn checkout directory '{$config['svndir']} exists and is NO directory or NOT writable!");
}
chdir($config['svndir']);
$svnbranch = $config['svnbase'].'/'.$config['svnbranch'];
if (file_exists($config['aliasdir']))
{
// check if correct branch
$cmd = 'LANG=C '.$svn.' info '.$config['aliasdir'];
exec($cmd,$output,$ret);
foreach($output as $line)
{
if ($ret || substr($line,0,5) == 'URL: ')
{
$url = substr($line,5);
if ($ret || substr($url,0,strlen($svnbranch)) != $svnbranch) // wrong branch (or no svn dir)
{
echo "Checkout is of wrong branch --> deleting it\n";
system('/bin/rm -rf .svn '.$config['aliasdir']); // --> remove the whole checkout
clearstatcache();
}
break;
}
}
}
$url = $svnbranch.'/'.$config['svnalias'];
$cmd = $svn.' co '.$url.' .';
run_cmd($cmd);
chdir($config['aliasdir']);
foreach($config['extra'] as $module)
{
$url = strpos($module,'://') === false ? $svnbranch.'/' : '';
$url .= $module;
$cmd = $svn.' co '.$url;
run_cmd($cmd);
}
}
/**
* Runs given shell command, exists with error-code after echoing the output of the failed command (if not already running verbose)
*
* @param string $cmd
* @param array &$output=null $output of command
* @param int|array $no_bailout=null exit code(s) to NOT bail out
* @return int exit code of $cmd
*/
function run_cmd($cmd,array &$output=null,$no_bailout=null)
{
global $verbose;
if ($verbose)
{
echo $cmd."\n";
system($cmd,$ret);
}
else
{
$output[] = $cmd;
exec($cmd,$output,$ret);
}
if ($ret && !in_array($ret,(array)$no_bailout))
{
if (!$verbose) echo implode("\n",$output)."\n";
throw new Exception("Error during '$cmd' --> aborting",$ret);
}
return $ret;
}
/**
* Give usage information and an optional error-message, before stoping program execution with exit-code 90 or 0
*
* @param string $error=null optional error-message
*/
function usage($error=null)
{
global $prog,$config;
echo "Usage: $prog [-h|--help] [-v|--verbose] [options, ...]\n\n";
echo "options and their defaults:\n";
foreach($config as $name => $default)
{
if (is_array($default)) $default = implode(' ',$default);
echo '--'.str_pad($name,20).$default."\n";
}
if ($error)
{
echo "$error\n\n";
exit(90);
}
exit(0);
}