* PEAR: automatic upgrade or install of required PEAR packages via package post_instal.php (only package installs!)

This commit is contained in:
Ralf Becker 2011-08-05 10:03:12 +00:00
parent 61310222ab
commit 6222e320e2

View File

@ -1,7 +1,7 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/** /**
* eGroupWare - RPM post install: automatic install or update EGroupware * EGroupware - RPM post install: automatic install or update EGroupware
* *
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
@ -16,6 +16,7 @@ if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling post_in
$verbose = false; $verbose = false;
$config = array( $config = array(
'php' => '/usr/bin/php', 'php' => '/usr/bin/php',
'pear' => '/usr/bin/pear',
'source_dir' => '/usr/share/egroupware', 'source_dir' => '/usr/share/egroupware',
'data_dir' => '/var/lib/egroupware', 'data_dir' => '/var/lib/egroupware',
'header' => '$data_dir/header.inc.php', // symlinked to source_dir by rpm 'header' => '$data_dir/header.inc.php', // symlinked to source_dir by rpm
@ -59,6 +60,7 @@ $config = array(
'postfix' => '', // see setup-cli.php --help config 'postfix' => '', // see setup-cli.php --help config
'cyrus' => '', 'cyrus' => '',
'sieve' => '', 'sieve' => '',
'webserver_user'=> 'apache', // required to fix permissions
); );
// read language from LANG enviroment variable // read language from LANG enviroment variable
@ -90,6 +92,7 @@ function set_distro_defaults($distro=null)
{ {
case 'suse': case 'suse':
$config['php'] = '/usr/bin/php5'; $config['php'] = '/usr/bin/php5';
$config['pear'] = '/usr/bin/pear5';
$config['start_db'] = '/sbin/service mysql'; $config['start_db'] = '/sbin/service mysql';
$config['autostart_db'] = '/sbin/chkconfig --level 345 mysql on'; $config['autostart_db'] = '/sbin/chkconfig --level 345 mysql on';
$config['start_webserver'] = '/sbin/service apache2'; $config['start_webserver'] = '/sbin/service apache2';
@ -100,6 +103,7 @@ function set_distro_defaults($distro=null)
$config['ldap_base'] = '$suffix'; $config['ldap_base'] = '$suffix';
$config['ldap_context'] = 'ou=people,$base'; $config['ldap_context'] = 'ou=people,$base';
$config['ldap_group_context'] = 'ou=group,$base'; $config['ldap_group_context'] = 'ou=group,$base';
$config['webserver_user'] = 'wwwrun';
break; break;
case 'debian': case 'debian':
// service not in Debian5, only newer Ubuntu, which complains about /etc/init.d/xx // service not in Debian5, only newer Ubuntu, which complains about /etc/init.d/xx
@ -115,6 +119,7 @@ function set_distro_defaults($distro=null)
} }
$config['autostart_db'] = '/usr/sbin/update-rc.d mysql defaults'; $config['autostart_db'] = '/usr/sbin/update-rc.d mysql defaults';
$config['autostart_webserver'] = '/usr/sbin/update-rc.d apache2 defaults'; $config['autostart_webserver'] = '/usr/sbin/update-rc.d apache2 defaults';
$config['webserver_user'] = 'www-data';
break; break;
case 'mandriva': case 'mandriva':
$config['ldap_suffix'] = 'dc=site'; $config['ldap_suffix'] = 'dc=site';
@ -320,6 +325,11 @@ if (!file_exists($config['header']) || filesize($config['header']) < 200) // def
system($config['start_webserver'].' reload'); system($config['start_webserver'].' reload');
} }
} }
// install/upgrade required pear packages
check_install_pear_packages();
// fix egw_cache evtl. created by root, stoping webserver from accessing it
fix_perms();
echo "\n"; echo "\n";
echo "EGroupware successful installed\n"; echo "EGroupware successful installed\n";
echo "===============================\n"; echo "===============================\n";
@ -369,6 +379,11 @@ else
echo "\nEGroupware successful updated\n"; echo "\nEGroupware successful updated\n";
break; break;
} }
// install/upgrade required pear packages
check_install_pear_packages();
// fix egw_cache evtl. created by root, stoping webserver from accessing it
fix_perms();
exit($ret); exit($ret);
} }
@ -490,3 +505,116 @@ function usage($error=null)
} }
exit(0); exit(0);
} }
/**
* Check if required PEAR packges are installed and install them if not, update pear packages with to low version
*/
function check_install_pear_packages()
{
global $config;
exec($config['pear'].' list',$out,$ret);
if ($ret)
{
echo "Error running pear command ($config[pear])!\n";
exit(95);
}
$packages_installed = array();
foreach($out as $n => $line)
{
if (preg_match('/^([a-z0-9_]+)\s+([0-9.]+[a-z0-9]*)\s+([a-z]+)/i',$line,$matches))
{
$packages_installed[$matches[1]] = $matches[2];
}
}
// read required packages from apps
$packages = array('PEAR' => true, 'HTTP_WebDAV_Server' => '999.egw-pear'); // pear must be the first, to run it's update first!
$egw_pear_packages = array();
foreach(scandir($config['source_dir']) as $app)
{
if (is_dir($dir=$config['source_dir'].'/'.$app) && file_exists($file=$dir.'/setup/setup.inc.php')) include $file;
}
foreach($setup_info as $app => $data)
{
if (isset($data['check_install']))
{
foreach($data['check_install'] as $package => $args)
{
if ($args['func'] == 'pear_check')
{
if (!$package) $package = 'PEAR';
// only overwrite lower version or no version
if (!isset($packages[$package]) || $packages[$package] === true || isset($args['version']) && version_compare($args['version'],$packages[$package],'>'))
{
$packages[$package] = isset($args['version']) ? $args['version'] : true;
}
}
}
}
if ($app == 'egw-pear')
{
$egw_pear_packages['HTTP_WebDAV_Server'] = $egw_pear_packages['Net_IMAP'] = $egw_pear_packages['Net_Sieve'] = $egw_pear_packages['Log'] = '999.egw-pear';
}
}
//echo 'Installed: '; print_r($packages_installed);
//echo 'egw-pear: '; print_r($egw_pear_packages);
//echo 'Required: '; print_r($packages);
$to_install = array_diff(array_keys($packages),array_keys($packages_installed),array_keys($egw_pear_packages));
$need_upgrade = array();
foreach($packages as $package => $version)
{
if ($version !== true && isset($packages_installed[$package]) &&
version_compare($version, $packages_installed[$package], '>'))
{
$need_upgrade[] = $package;
}
}
//echo 'Need upgrade: '; print_r($need_upgrade);
//echo 'To install: '; print_r($to_install);
if (($to_install || $need_upgrade))
{
if (getmyuid())
{
echo "You need to run as user root to be able to install/upgrade required PEAR packages!\n";
}
else
{
echo "Install/upgrade required PEAR packages:\n";
// need to run upgrades first, they might be required for install!
if ($need_upgrade)
{
if (in_array('PEAR',$need_upgrade)) // updating pear itself can be very tricky, this is what's needed for stock RHEL pear
{
$cmd = $config['pear'].' channel-update pear.php.net';
echo "$cmd\n"; system($cmd);
$cmd = $config['pear'].' upgrade --force Console_Getopt Archive_Tar';
echo "$cmd\n"; system($cmd);
}
$cmd = $config['pear'].' upgrade '.implode(' ',$need_upgrade);
echo "$cmd\n"; system($cmd);
}
if ($to_install)
{
$cmd = $config['pear'].' install '.implode(' ',$to_install);
echo "$cmd\n"; system($cmd);
}
}
}
}
function lang() {} // required to be able to include */setup/setup.inc.php files
/**
* fix egw_cache perms evtl. created by root, stoping webserver from accessing it
*/
function fix_perms()
{
global $config;
if (file_exists('/tmp/egw_cache'))
{
system('/bin/chown -R '.$config['webserver_user'].' /tmp/egw_cache');
system('/bin/chmod 700 /tmp/egw_cache');
}
}