2009-05-30 22:15:31 +02:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
/**
|
2011-06-18 12:44:56 +02:00
|
|
|
* EGroupware - RPM post install: automatic install or update EGroupware
|
2009-05-30 22:15:31 +02:00
|
|
|
*
|
|
|
|
* @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$
|
|
|
|
*/
|
|
|
|
|
2013-09-10 19:29:58 +02:00
|
|
|
if (php_sapi_name() !== 'cli') // security precaution: forbit calling post_install as web-page
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
|
|
|
die('<h1>rpm_post_install.php must NOT be called as web-page --> exiting !!!</h1>');
|
|
|
|
}
|
|
|
|
$verbose = false;
|
|
|
|
$config = array(
|
|
|
|
'php' => '/usr/bin/php',
|
2011-06-30 22:56:20 +02:00
|
|
|
'pear' => '/usr/bin/pear',
|
2009-05-30 22:15:31 +02:00
|
|
|
'source_dir' => '/usr/share/egroupware',
|
|
|
|
'data_dir' => '/var/lib/egroupware',
|
2009-06-01 23:08:51 +02:00
|
|
|
'header' => '$data_dir/header.inc.php', // symlinked to source_dir by rpm
|
|
|
|
'setup-cli' => '$source_dir/setup/setup-cli.php',
|
2009-05-30 22:15:31 +02:00
|
|
|
'domain' => 'default',
|
|
|
|
'config_user' => 'admin',
|
|
|
|
'config_passwd' => randomstring(),
|
2013-05-26 11:43:10 +02:00
|
|
|
'db_type' => 'mysqli',
|
2009-05-30 22:15:31 +02:00
|
|
|
'db_host' => 'localhost',
|
|
|
|
'db_port' => 3306,
|
|
|
|
'db_name' => 'egroupware',
|
|
|
|
'db_user' => 'egroupware',
|
|
|
|
'db_pass' => randomstring(),
|
|
|
|
'db_grant_host' => 'localhost',
|
|
|
|
'db_root' => 'root', // mysql root user/pw to create database
|
|
|
|
'db_root_pw' => '',
|
|
|
|
'backup' => '',
|
|
|
|
'admin_user' => 'sysop',
|
|
|
|
'admin_passwd'=> randomstring(),
|
|
|
|
'lang' => 'en', // languages for admin user and extra lang to install
|
|
|
|
'charset' => 'utf-8',
|
2009-12-07 19:26:28 +01:00
|
|
|
'start_db' => '/sbin/service mysqld',
|
2009-06-02 00:05:07 +02:00
|
|
|
'autostart_db' => '/sbin/chkconfig --level 345 mysqld on',
|
2009-12-07 19:26:28 +01:00
|
|
|
'start_webserver' => '/sbin/service httpd',
|
2009-06-02 00:05:07 +02:00
|
|
|
'autostart_webserver' => '/sbin/chkconfig --level 345 httpd on',
|
2009-06-09 13:22:23 +02:00
|
|
|
'distro' => 'rh',
|
2009-12-07 19:26:28 +01:00
|
|
|
'account-auth' => 'sql',
|
2009-12-05 18:42:18 +01:00
|
|
|
'account_min_id' => '',
|
|
|
|
'ldap_suffix' => 'dc=local',
|
|
|
|
'ldap_host' => 'localhost',
|
|
|
|
'ldap_admin' => 'cn=admin,$suffix',
|
|
|
|
'ldap_admin_pw' => '',
|
|
|
|
'ldap_base' => 'o=$domain,$suffix',
|
|
|
|
'ldap_root_dn' => 'cn=admin,$base',
|
|
|
|
'ldap_root_pw' => randomstring(),
|
|
|
|
'ldap_context' => 'ou=accounts,$base',
|
|
|
|
'ldap_search_filter' => '(uid=%user)',
|
|
|
|
'ldap_group_context' => 'ou=groups,$base',
|
2010-06-11 10:10:06 +02:00
|
|
|
'mailserver' => '',
|
2009-12-06 11:28:49 +01:00
|
|
|
'smtpserver' => 'localhost,25',
|
2013-06-20 16:48:53 +02:00
|
|
|
'smtp' => '', // see setup-cli.php --help config
|
|
|
|
'imap' => '',
|
2009-12-06 11:28:49 +01:00
|
|
|
'sieve' => '',
|
2014-04-15 17:10:39 +02:00
|
|
|
'folder' => '',
|
2011-06-18 12:44:56 +02:00
|
|
|
'install-update-app' => '', // install or update a single (non-default) app
|
2011-07-01 21:22:18 +02:00
|
|
|
'webserver_user'=> 'apache', // required to fix permissions
|
2009-05-30 22:15:31 +02:00
|
|
|
);
|
2009-06-01 23:08:51 +02:00
|
|
|
|
2009-05-30 22:15:31 +02:00
|
|
|
// read language from LANG enviroment variable
|
2009-06-01 23:08:51 +02:00
|
|
|
if (($lang = isset($_ENV['LANG']) ? $_ENV['LANG'] : $_SERVER['LANG']))
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
2009-07-30 11:32:19 +02:00
|
|
|
@list($lang,$nat) = preg_split('/[_.]/',$lang);
|
2009-05-30 22:15:31 +02:00
|
|
|
if (in_array($lang.'-'.strtolower($nat),array('es-es','pt-br','zh-tw')))
|
|
|
|
{
|
|
|
|
$lang .= '-'.strtolower($nat);
|
|
|
|
}
|
|
|
|
$config['lang'] = $lang;
|
|
|
|
}
|
2009-06-02 00:05:07 +02:00
|
|
|
$config['source_dir'] = dirname(dirname(dirname(__FILE__)));
|
|
|
|
|
2009-06-09 13:22:23 +02:00
|
|
|
/**
|
|
|
|
* Set distribution spezific defaults
|
|
|
|
*
|
|
|
|
* @param string $distro=null default autodetect
|
|
|
|
*/
|
|
|
|
function set_distro_defaults($distro=null)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
if (is_null($distro))
|
|
|
|
{
|
2010-04-04 13:46:48 +02:00
|
|
|
$distro = file_exists('/etc/SuSE-release') ? 'suse' : (file_exists('/etc/debian_version') ? 'debian' :
|
|
|
|
(file_exists('/etc/mandriva-release') ? 'mandriva' : 'rh'));
|
2009-06-09 13:22:23 +02:00
|
|
|
}
|
|
|
|
switch (($config['distro'] = $distro))
|
|
|
|
{
|
|
|
|
case 'suse':
|
2013-03-22 11:26:59 +01:00
|
|
|
// openSUSE 12.1+ no longer uses php5
|
|
|
|
if (file_exists('/usr/bin/php5')) $config['php'] = '/usr/bin/php5';
|
|
|
|
if (file_exists('/usr/bin/pear5')) $config['pear'] = '/usr/bin/pear5';
|
2009-12-07 19:26:28 +01:00
|
|
|
$config['start_db'] = '/sbin/service mysql';
|
2009-06-09 13:22:23 +02:00
|
|
|
$config['autostart_db'] = '/sbin/chkconfig --level 345 mysql on';
|
2009-12-07 19:26:28 +01:00
|
|
|
$config['start_webserver'] = '/sbin/service apache2';
|
2009-06-09 13:22:23 +02:00
|
|
|
$config['autostart_webserver'] = '/sbin/chkconfig --level 345 apache2 on';
|
2009-12-05 18:42:18 +01:00
|
|
|
$config['ldap_suffix'] = 'dc=site';
|
|
|
|
$config['ldap_admin'] = $config['ldap_root_dn'] = 'cn=Administrator,$suffix';
|
|
|
|
$config['ldap_root_pw'] = '$admin_pw';
|
|
|
|
$config['ldap_base'] = '$suffix';
|
|
|
|
$config['ldap_context'] = 'ou=people,$base';
|
|
|
|
$config['ldap_group_context'] = 'ou=group,$base';
|
2011-07-01 21:22:18 +02:00
|
|
|
$config['webserver_user'] = 'wwwrun';
|
2009-06-09 13:22:23 +02:00
|
|
|
break;
|
|
|
|
case 'debian':
|
2010-06-14 10:13:19 +02:00
|
|
|
// service not in Debian5, only newer Ubuntu, which complains about /etc/init.d/xx
|
|
|
|
if (file_exists('/usr/sbin/service'))
|
|
|
|
{
|
|
|
|
$config['start_db'] = '/usr/sbin/service mysql';
|
|
|
|
$config['start_webserver'] = '/usr/sbin/service apache2';
|
|
|
|
}
|
|
|
|
else
|
2011-06-18 12:44:56 +02:00
|
|
|
{
|
2010-06-14 10:13:19 +02:00
|
|
|
$config['start_db'] = '/etc/init.d/mysql';
|
|
|
|
$config['start_webserver'] = '/etc/init.d/apache2';
|
|
|
|
}
|
2009-06-09 13:22:23 +02:00
|
|
|
$config['autostart_db'] = '/usr/sbin/update-rc.d mysql defaults';
|
|
|
|
$config['autostart_webserver'] = '/usr/sbin/update-rc.d apache2 defaults';
|
2011-07-01 21:22:18 +02:00
|
|
|
$config['webserver_user'] = 'www-data';
|
2009-06-09 13:22:23 +02:00
|
|
|
break;
|
2010-04-04 13:46:48 +02:00
|
|
|
case 'mandriva':
|
|
|
|
$config['ldap_suffix'] = 'dc=site';
|
|
|
|
$config['ldap_admin'] = $config['ldap_root_dn'] = 'uid=LDAP Admin,ou=System Accounts,$suffix';
|
|
|
|
$config['ldap_root_pw'] = '$admin_pw';
|
|
|
|
$config['ldap_base'] = '$suffix';
|
|
|
|
$config['ldap_context'] = 'ou=People,$base';
|
|
|
|
$config['ldap_group_context'] = 'ou=Group,$base';
|
|
|
|
break;
|
2009-06-09 13:22:23 +02:00
|
|
|
default:
|
|
|
|
$config['distro'] = 'rh';
|
|
|
|
// fall through
|
2012-04-19 14:40:59 +02:00
|
|
|
case 'rh':
|
|
|
|
// some MySQL packages (mysql.com, MariaDB, ...) use "mysql" as service name instead of RH default "mysqld"
|
|
|
|
if (!file_exists('/etc/init.d/mysqld') && file_exists('/etc/init.d/mysql'))
|
|
|
|
{
|
|
|
|
foreach(array('start_db','autostart_db') as $name)
|
|
|
|
{
|
|
|
|
$config[$name] = str_replace('mysqld','mysql',$config[$name]);
|
|
|
|
}
|
|
|
|
}
|
2009-06-09 13:22:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_distro_defaults();
|
|
|
|
|
2009-05-30 22:15:31 +02:00
|
|
|
// read config from command line
|
|
|
|
$argv = $_SERVER['argv'];
|
|
|
|
$prog = array_shift($argv);
|
|
|
|
|
2009-12-07 19:26:28 +01:00
|
|
|
// check if we have EGW_POST_INSTALL set and prepend it to the command line (command line has precedence)
|
|
|
|
if (($config_set = isset($_ENV['EGW_POST_INSTALL']) ? $_ENV['EGW_POST_INSTALL'] : @$_SERVER['EGW_POST_INSTALL']))
|
|
|
|
{
|
|
|
|
$conf = array();
|
2009-12-08 09:27:53 +01:00
|
|
|
$config_set = preg_split('/[ \t]+/',trim($config_set));
|
|
|
|
while($config_set)
|
2009-12-07 19:26:28 +01:00
|
|
|
{
|
2009-12-08 09:27:53 +01:00
|
|
|
$val = array_shift($config_set);
|
2009-12-07 19:26:28 +01:00
|
|
|
if (($quote = $val[0]) == "'" || $quote == '"') // arguments might be quoted with ' or "
|
|
|
|
{
|
|
|
|
while (substr($val,-1) != $quote)
|
|
|
|
{
|
|
|
|
if (!$config_set) throw new Exception('Invalid EGW_POST_INSTALL enviroment variable!');
|
|
|
|
$val .= ' '.array_shift($config_set);
|
|
|
|
}
|
|
|
|
$val = substr($val,1,-1);
|
|
|
|
}
|
|
|
|
$conf[] = $val;
|
|
|
|
}
|
|
|
|
$argv = array_merge($conf,$argv);
|
|
|
|
}
|
|
|
|
|
2009-12-05 18:42:18 +01:00
|
|
|
$auth_type_given = false;
|
2009-05-30 22:15:31 +02:00
|
|
|
while(($arg = array_shift($argv)))
|
|
|
|
{
|
|
|
|
if ($arg == '-v' || $arg == '--verbose')
|
|
|
|
{
|
|
|
|
$verbose = true;
|
|
|
|
}
|
|
|
|
elseif($arg == '-h' || $arg == '--help')
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
2009-06-02 00:05:07 +02:00
|
|
|
elseif($arg == '--suse')
|
|
|
|
{
|
2009-06-09 13:22:23 +02:00
|
|
|
set_distro_defaults('suse');
|
|
|
|
}
|
|
|
|
elseif($arg == '--distro')
|
|
|
|
{
|
|
|
|
set_distro_defaults(array_shift($argv));
|
2009-06-02 00:05:07 +02:00
|
|
|
}
|
2009-05-30 22:15:31 +02:00
|
|
|
elseif(substr($arg,0,2) == '--' && isset($config[$name=substr($arg,2)]))
|
|
|
|
{
|
|
|
|
$config[$name] = array_shift($argv);
|
2009-12-05 18:42:18 +01:00
|
|
|
|
|
|
|
switch($name)
|
|
|
|
{
|
|
|
|
case 'auth_type':
|
|
|
|
$auth_type_given = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'account_repository': // auth-type defaults to account-repository
|
|
|
|
if (!$auth_type_given)
|
|
|
|
{
|
|
|
|
$config['auth_type'] = $config[$name];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-30 22:15:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage("Unknown argument '$arg'!");
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 23:08:51 +02:00
|
|
|
|
|
|
|
$replace = array();
|
|
|
|
foreach($config as $name => $value)
|
|
|
|
{
|
|
|
|
$replace['$'.$name] = $value;
|
|
|
|
if (strpos($value,'$') !== false)
|
|
|
|
{
|
|
|
|
$config[$name] = strtr($value,$replace);
|
|
|
|
}
|
|
|
|
}
|
2009-05-30 22:15:31 +02:00
|
|
|
// basic config checks
|
|
|
|
foreach(array('php','source_dir','data_dir','setup-cli') as $name)
|
|
|
|
{
|
|
|
|
if (!file_exists($config[$name])) bail_out(1,$config[$name].' not found!');
|
|
|
|
}
|
2013-03-22 11:26:59 +01:00
|
|
|
$setup_cli = $config['php'].' -d memory_limit=256M '.$config['setup-cli'];
|
2009-05-30 22:15:31 +02:00
|
|
|
|
|
|
|
if (!file_exists($config['header']) || filesize($config['header']) < 200) // default header redirecting to setup is 147 bytes
|
|
|
|
{
|
|
|
|
// --> new install
|
2009-12-05 18:42:18 +01:00
|
|
|
$extra_config = '';
|
2009-05-30 22:15:31 +02:00
|
|
|
|
|
|
|
// check for localhost if database server is started and start it (permanent) if not
|
2010-04-04 13:46:48 +02:00
|
|
|
if ($config['db_host'] == 'localhost' && $config['start_db'])
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
2013-03-22 11:26:59 +01:00
|
|
|
exec($config['start_db'].' status',$dummy,$ret);
|
|
|
|
if ($ret)
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
|
|
|
system($config['start_db'].' start');
|
|
|
|
system($config['autostart_db']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create database
|
|
|
|
$setup_db = $setup_cli.' --setup-cmd-database sub_command=create_db';
|
|
|
|
foreach(array('domain','db_type','db_host','db_port','db_name','db_user','db_pass','db_root','db_root_pw','db_grant_host') as $name)
|
|
|
|
{
|
|
|
|
$setup_db .= ' '.escapeshellarg($name.'='.$config[$name]);
|
|
|
|
}
|
|
|
|
run_cmd($setup_db);
|
|
|
|
|
2009-12-05 18:42:18 +01:00
|
|
|
// check if ldap is required and initialise it
|
2009-12-06 11:28:49 +01:00
|
|
|
// we need to specify account_repository and auth_type to --install as extra config, otherwise install happens for sql!
|
|
|
|
@list($config['account_repository'],$config['auth_type'],$rest) = explode(',',$config['account-auth'],3);
|
2009-12-05 18:42:18 +01:00
|
|
|
$extra_config .= ' '.escapeshellarg('account_repository='.$config['account_repository']);
|
2009-12-06 11:28:49 +01:00
|
|
|
$extra_config .= ' '.escapeshellarg('auth_type='.(empty($config['auth_type']) ? $config['account_repository'] : $config['auth_type']));
|
|
|
|
if (empty($rest)) unset($config['account-auth']);
|
|
|
|
if ($config['account_repository'] == 'ldap' || $config['auth_type'] == 'ldap')
|
2009-12-05 18:42:18 +01:00
|
|
|
{
|
2009-12-06 11:28:49 +01:00
|
|
|
// set account_min_id to 1100 if not specified to NOT clash with system accounts
|
2009-12-05 18:42:18 +01:00
|
|
|
$extra_config .= ' '.escapeshellarg('account_min_id='.(!empty($config['account_min_id']) ? $config['account_min_id'] : 1100));
|
|
|
|
|
|
|
|
$setup_ldap = $setup_cli.' --setup-cmd-ldap sub_command='.
|
|
|
|
($config['account_repository'] == 'ldap' ? 'create_ldap' : 'test_ldap');
|
|
|
|
foreach(array(
|
|
|
|
'domain','ldap_suffix','ldap_host','ldap_admin','ldap_admin_pw', // non-egw params: only used for create
|
|
|
|
'ldap_base','ldap_root_dn','ldap_root_pw','ldap_context','ldap_search_filter','ldap_group_context', // egw params
|
|
|
|
) as $name)
|
|
|
|
{
|
|
|
|
if (strpos($value=$config[$name],'$') !== false)
|
|
|
|
{
|
|
|
|
$config[$name] = $value = strtr($value,array(
|
|
|
|
'$suffix' => $config['ldap_suffix'],
|
|
|
|
'$base' => $config['ldap_base'],
|
|
|
|
'$admin_pw' => $config['ldap_admin_pw'],
|
|
|
|
));
|
|
|
|
}
|
|
|
|
$setup_ldap .= ' '.escapeshellarg($name.'='.$value);
|
|
|
|
|
|
|
|
if (!in_array($name,array('domain','ldap_suffix','ldap_admin','ldap_admin_pw')))
|
|
|
|
{
|
|
|
|
$extra_config .= ' '.escapeshellarg($name.'='.$value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run_cmd($setup_ldap);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create header
|
|
|
|
$setup_header = $setup_cli.' --create-header '.escapeshellarg($config['config_passwd'].','.$config['config_user']).
|
|
|
|
' --domain '.escapeshellarg($config['domain'].','.$config['db_name'].','.$config['db_user'].','.$config['db_pass'].
|
|
|
|
','.$config['db_type'].','.$config['db_host'].','.$config['db_port']);
|
|
|
|
run_cmd($setup_header);
|
|
|
|
|
2009-05-30 22:15:31 +02:00
|
|
|
// install egroupware
|
2009-12-05 18:42:18 +01:00
|
|
|
$setup_install = $setup_cli.' --install '.escapeshellarg($config['domain'].','.$config['config_user'].','.$config['config_passwd'].','.$config['backup'].','.$config['charset'].','.$config['lang'])
|
|
|
|
.$extra_config;
|
2009-05-30 22:15:31 +02:00
|
|
|
run_cmd($setup_install);
|
|
|
|
|
|
|
|
if ($config['data_dir'] != '/var/lib/egroupware')
|
|
|
|
{
|
|
|
|
// set files dir different from default
|
|
|
|
$setup_config = $setup_cli.' --config '.escapeshellarg($config['domain'].','.$config['config_user'].','.$config['config_passwd']).
|
|
|
|
' --files-dir '.escapeshellarg($config['data_dir'].'/files').' --backup-dir '.escapeshellarg($config['data_dir'].'/backup');
|
|
|
|
run_cmd($setup_config);
|
|
|
|
}
|
2009-12-06 11:28:49 +01:00
|
|
|
// create mailserver config (fmail requires at least minimal config given as default, otherwise fatal error)
|
|
|
|
$setup_mailserver = $setup_cli.' --config '.escapeshellarg($config['domain'].','.$config['config_user'].','.$config['config_passwd']);
|
2013-06-20 16:48:53 +02:00
|
|
|
foreach(array('account-auth','smtpserver','smtp','postfix','mailserver','imap','cyrus','sieve') as $name)
|
2009-12-06 11:28:49 +01:00
|
|
|
{
|
|
|
|
if (!empty($config[$name])) $setup_mailserver .= ' --'.$name.' '.escapeshellarg($config[$name]);
|
|
|
|
}
|
2009-09-30 15:05:15 +02:00
|
|
|
run_cmd($setup_mailserver);
|
2009-05-30 22:15:31 +02:00
|
|
|
|
|
|
|
// create first user
|
|
|
|
$setup_admin = $setup_cli.' --admin '.escapeshellarg($config['domain'].','.$config['config_user'].','.$config['config_passwd'].','.
|
|
|
|
$config['admin_user'].','.$config['admin_passwd'].',,,,'.$config['lang']);
|
|
|
|
run_cmd($setup_admin);
|
|
|
|
|
|
|
|
// check if webserver is started and start it (permanent) if not
|
2010-04-04 13:46:48 +02:00
|
|
|
if ($config['start_webserver'])
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
2013-03-22 11:26:59 +01:00
|
|
|
exec($config['start_webserver'].' status',$dummy,$ret);
|
|
|
|
if ($ret)
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
|
|
|
system($config['start_webserver'].' start');
|
|
|
|
system($config['autostart_webserver']);
|
|
|
|
}
|
2009-06-14 10:42:34 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
system($config['start_webserver'].' reload');
|
|
|
|
}
|
2009-05-30 22:15:31 +02:00
|
|
|
}
|
2011-06-30 22:56:20 +02:00
|
|
|
// install/upgrade required pear packages
|
|
|
|
check_install_pear_packages();
|
2011-07-01 21:22:18 +02:00
|
|
|
// fix egw_cache evtl. created by root, stoping webserver from accessing it
|
|
|
|
fix_perms();
|
2011-06-30 22:56:20 +02:00
|
|
|
|
2009-05-30 22:15:31 +02:00
|
|
|
echo "\n";
|
|
|
|
echo "EGroupware successful installed\n";
|
|
|
|
echo "===============================\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "Please note the following user names and passwords:\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "Setup username: $config[config_user]\n";
|
|
|
|
echo " password: $config[config_passwd]\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "EGroupware username: $config[admin_user]\n";
|
|
|
|
echo " password: $config[admin_passwd]\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "You can log into EGroupware by pointing your browser to http://localhost/egroupware/\n";
|
|
|
|
echo "Please replace localhost with the appropriate hostname, if you connect remote.\n\n";
|
|
|
|
|
|
|
|
if (empty($config['db_root_pw']))
|
|
|
|
{
|
|
|
|
echo "*** Database has no root password set, please fix that immediatly: mysqladmin -u root password NEWPASSWORD\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// --> existing install --> update
|
|
|
|
|
|
|
|
// get user from header and replace password, as we dont know it
|
2009-05-31 11:54:08 +02:00
|
|
|
$old_password = patch_header($config['header'],$config['config_user'],$config['config_passwd']);
|
|
|
|
// register a shutdown function to put old password back in any case
|
|
|
|
register_shutdown_function('patch_header',$config['header'],$config['config_user'],$old_password);
|
2009-05-30 22:15:31 +02:00
|
|
|
|
|
|
|
// update egroupware
|
2011-06-18 12:44:56 +02:00
|
|
|
$setup_update = $setup_cli.' --update '.escapeshellarg('all,'.$config['config_user'].','.$config['config_passwd'].',,'.$config['install-update-app']);
|
2009-05-31 11:54:08 +02:00
|
|
|
$ret = run_cmd($setup_update,$output,array(4,15));
|
|
|
|
|
|
|
|
switch($ret)
|
|
|
|
{
|
|
|
|
case 4: // header needs an update
|
|
|
|
$header_update = $setup_cli.' --update-header '.escapeshellarg($config['config_passwd'].','.$config['config_user']);
|
|
|
|
run_cmd($header_update);
|
|
|
|
$ret = run_cmd($setup_update,$output,15);
|
|
|
|
if ($ret != 15) break;
|
|
|
|
// fall through
|
|
|
|
case 15: // missing configuration (eg. mailserver)
|
|
|
|
if (!$verbose) echo implode("\n",(array)$output)."\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
echo "\nEGroupware successful updated\n";
|
|
|
|
break;
|
|
|
|
}
|
2011-06-30 22:56:20 +02:00
|
|
|
// install/upgrade required pear packages
|
|
|
|
check_install_pear_packages();
|
2011-07-01 21:22:18 +02:00
|
|
|
// fix egw_cache evtl. created by root, stoping webserver from accessing it
|
|
|
|
fix_perms();
|
2011-06-30 22:56:20 +02:00
|
|
|
|
2013-03-22 11:26:59 +01:00
|
|
|
// restart running Apache, to force APC to update changed sources and/or Apache configuration
|
|
|
|
$output = array();
|
|
|
|
run_cmd($config['start_webserver'].' status && '.$config['start_webserver'].' restart', $output, true);
|
|
|
|
|
2009-05-31 11:54:08 +02:00
|
|
|
exit($ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Patches a given password (for header admin) into the EGroupware header.inc.php and returns the old one
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
* @param string &$user username on return(!)
|
|
|
|
* @param string $password new password
|
|
|
|
* @return string old password
|
|
|
|
*/
|
|
|
|
function patch_header($filename,&$user,$password)
|
|
|
|
{
|
|
|
|
$header = file_get_contents($filename);
|
|
|
|
|
2014-02-11 10:20:14 +01:00
|
|
|
$umatches = $pmatches = null;
|
|
|
|
if (!preg_match('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_user'] = '", '/')."([^']+)';/m",$header,$umatches) ||
|
|
|
|
!preg_match('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m",$header,$pmatches))
|
2009-05-31 11:54:08 +02:00
|
|
|
{
|
|
|
|
bail_out(99,"$filename is no regular EGroupware header.inc.php!");
|
|
|
|
}
|
2014-02-11 10:20:14 +01:00
|
|
|
file_put_contents($filename,preg_replace('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m",
|
2009-05-31 11:54:08 +02:00
|
|
|
"\$GLOBALS['egw_info']['server']['header_admin_password'] = '".$password."';",$header));
|
2009-05-30 22:15:31 +02:00
|
|
|
|
2009-05-31 11:54:08 +02:00
|
|
|
$user = $umatches[1];
|
2009-05-30 22:15:31 +02:00
|
|
|
|
2009-05-31 11:54:08 +02:00
|
|
|
return $pmatches[1];
|
2009-05-30 22:15:31 +02:00
|
|
|
}
|
|
|
|
|
2009-05-31 11:54:08 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2013-03-22 11:26:59 +01:00
|
|
|
* @param int|array|true $no_bailout=null exit code(s) to NOT bail out, or true to never bail out
|
2009-05-31 11:54:08 +02:00
|
|
|
* @return int exit code of $cmd
|
|
|
|
*/
|
|
|
|
function run_cmd($cmd,array &$output=null,$no_bailout=null)
|
2009-05-30 22:15:31 +02:00
|
|
|
{
|
|
|
|
global $verbose;
|
|
|
|
|
|
|
|
if ($verbose)
|
|
|
|
{
|
|
|
|
echo $cmd."\n";
|
2014-02-11 10:20:14 +01:00
|
|
|
$ret = null;
|
2009-05-30 22:15:31 +02:00
|
|
|
system($cmd,$ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$output[] = $cmd;
|
|
|
|
exec($cmd,$output,$ret);
|
|
|
|
}
|
2013-03-22 11:26:59 +01:00
|
|
|
if ($ret && $no_bailout !== true && !in_array($ret,(array)$no_bailout))
|
2009-05-31 11:54:08 +02:00
|
|
|
{
|
|
|
|
bail_out($ret,$verbose?null:$output);
|
|
|
|
}
|
|
|
|
return $ret;
|
2009-05-30 22:15:31 +02:00
|
|
|
}
|
|
|
|
|
2009-05-31 11:54:08 +02:00
|
|
|
/**
|
|
|
|
* Stop programm execution with a given exit code and optional extra message
|
|
|
|
*
|
|
|
|
* @param int $ret=1
|
|
|
|
* @param array|string $output line(s) to output before temination notice
|
|
|
|
*/
|
2009-05-30 22:15:31 +02:00
|
|
|
function bail_out($ret=1,$output=null)
|
|
|
|
{
|
|
|
|
if ($output) echo implode("\n",(array)$output);
|
|
|
|
echo "\n\nInstallation failed --> exiting!\n\n";
|
|
|
|
exit($ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a rand string, eg. to generate passwords
|
|
|
|
*
|
|
|
|
* @param int $len=16
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function randomstring($len=16)
|
|
|
|
{
|
|
|
|
static $usedchars = array(
|
|
|
|
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f',
|
|
|
|
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
|
|
|
|
'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L',
|
|
|
|
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
|
2014-02-11 10:20:14 +01:00
|
|
|
'@','!','$','%','&','(',')','=','?',';',':','#','_','-','<',
|
|
|
|
'>','|','[',']','}', // dont add /\,'"{ as we have problems dealing with them
|
2009-05-30 22:15:31 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$str = '';
|
|
|
|
for($i=0; $i < $len; $i++)
|
|
|
|
{
|
|
|
|
$str .= $usedchars[mt_rand(0,count($usedchars)-1)];
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2009-05-31 11:54:08 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2009-05-30 22:15:31 +02:00
|
|
|
function usage($error=null)
|
|
|
|
{
|
|
|
|
global $prog,$config;
|
2009-05-31 11:54:08 +02:00
|
|
|
|
2009-06-09 13:22:23 +02:00
|
|
|
echo "Usage: $prog [-h|--help] [-v|--verbose] [--distro=(suse|rh|debian)] [options, ...]\n\n";
|
2009-05-30 22:15:31 +02:00
|
|
|
echo "options and their defaults:\n";
|
|
|
|
foreach($config as $name => $default)
|
|
|
|
{
|
2013-06-20 16:48:53 +02:00
|
|
|
if (in_array($name, array('postfix','cyrus'))) continue; // do NOT report deprecated options
|
2009-12-07 19:26:28 +01:00
|
|
|
if (in_array($name,array('config_passwd','db_pass','admin_passwd','ldap_root_pw')))
|
|
|
|
{
|
|
|
|
$default = '<16 char random string>';
|
|
|
|
}
|
2009-05-30 22:15:31 +02:00
|
|
|
echo '--'.str_pad($name,20).$default."\n";
|
|
|
|
}
|
2009-05-31 11:54:08 +02:00
|
|
|
if ($error)
|
|
|
|
{
|
|
|
|
echo "$error\n\n";
|
|
|
|
exit(90);
|
|
|
|
}
|
|
|
|
exit(0);
|
2009-05-30 22:15:31 +02:00
|
|
|
}
|
2011-06-30 22:56:20 +02:00
|
|
|
|
|
|
|
/**
|
2014-04-18 11:00:22 +02:00
|
|
|
* Get installed pear packages, optional from a certain channel
|
|
|
|
*
|
|
|
|
* @global type $config
|
|
|
|
* @param string $channel=''
|
|
|
|
* @return null|array with package => version
|
2011-06-30 22:56:20 +02:00
|
|
|
*/
|
2014-04-18 11:00:22 +02:00
|
|
|
function pear_list($channel='')
|
2011-06-30 22:56:20 +02:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
2014-02-11 10:20:14 +01:00
|
|
|
$out = $ret = null;
|
2014-04-18 11:00:22 +02:00
|
|
|
exec($config['pear'].' list'.($channel?' -c '.$channel:''),$out,$ret);
|
|
|
|
if ($channel && $ret == 1)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2011-06-30 22:56:20 +02:00
|
|
|
if ($ret)
|
|
|
|
{
|
|
|
|
echo "Error running pear command ($config[pear])!\n";
|
|
|
|
exit(95);
|
|
|
|
}
|
|
|
|
$packages_installed = array();
|
2014-02-11 10:20:14 +01:00
|
|
|
foreach($out as $line)
|
2011-06-30 22:56:20 +02:00
|
|
|
{
|
2014-02-11 10:20:14 +01:00
|
|
|
$matches = null;
|
2011-06-30 22:56:20 +02:00
|
|
|
if (preg_match('/^([a-z0-9_]+)\s+([0-9.]+[a-z0-9]*)\s+([a-z]+)/i',$line,$matches))
|
|
|
|
{
|
2014-04-18 11:00:22 +02:00
|
|
|
$packages_installed[($channel?$channel.'/':'').$matches[1]] = $matches[2];
|
2011-06-30 22:56:20 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-18 11:00:22 +02:00
|
|
|
return $packages_installed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
$packages_installed = pear_list();
|
|
|
|
|
2011-06-30 22:56:20 +02:00
|
|
|
// read required packages from apps
|
2011-08-05 11:45:22 +02:00
|
|
|
$packages = array('PEAR' => true, 'HTTP_WebDAV_Server' => '999.egw-pear'); // pear must be the first, to run it's update first!
|
2014-04-18 11:00:22 +02:00
|
|
|
$channels = array();
|
2011-06-30 22:56:20 +02:00
|
|
|
$egw_pear_packages = array();
|
2014-02-11 10:20:14 +01:00
|
|
|
$setup_info = array();
|
2011-06-30 22:56:20 +02:00
|
|
|
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')
|
|
|
|
{
|
2011-08-05 11:45:22 +02:00
|
|
|
if (!$package) $package = 'PEAR';
|
2014-04-18 11:00:22 +02:00
|
|
|
// if package is prefixed with a channel, list or discover it first
|
|
|
|
if (strpos($package, '/'))
|
|
|
|
{
|
|
|
|
list($channel) = explode('/', $package);
|
|
|
|
if (!in_array($channel, $channels))
|
|
|
|
{
|
|
|
|
if (($channel_packages = pear_list($channel)))
|
|
|
|
{
|
|
|
|
$packages_installed += $channel_packages;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$discover_cmd = $config['pear'].' channel-discover '.$channel;
|
|
|
|
echo "$discover_cmd\n"; system($discover_cmd);
|
|
|
|
}
|
|
|
|
$channels[] = $channel;
|
|
|
|
}
|
|
|
|
}
|
2011-08-05 11:45:22 +02:00
|
|
|
// 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;
|
|
|
|
}
|
2011-06-30 22:56:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($app == 'egw-pear')
|
|
|
|
{
|
2014-04-18 10:33:15 +02:00
|
|
|
$egw_pear_packages['HTTP_WebDAV_Server'] = $egw_pear_packages['Net_IMAP'] = '999.egw-pear';
|
2011-06-30 22:56:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//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)
|
|
|
|
{
|
2013-11-07 11:05:25 +01:00
|
|
|
if ($version !== true && $version !== '999.egw-pear' && isset($packages_installed[$package]) &&
|
2011-06-30 22:56:20 +02:00
|
|
|
version_compare($version, $packages_installed[$package], '>'))
|
|
|
|
{
|
|
|
|
$need_upgrade[] = $package;
|
|
|
|
}
|
|
|
|
}
|
2011-08-05 11:45:22 +02:00
|
|
|
//echo 'Need upgrade: '; print_r($need_upgrade);
|
|
|
|
//echo 'To install: '; print_r($to_install);
|
2011-06-30 22:59:57 +02:00
|
|
|
if (($to_install || $need_upgrade))
|
2011-06-30 22:56:20 +02:00
|
|
|
{
|
2011-06-30 22:59:57 +02:00
|
|
|
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";
|
2011-08-05 11:45:22 +02:00
|
|
|
// 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)
|
|
|
|
{
|
2014-04-18 11:00:22 +02:00
|
|
|
$cmd = $config['pear'].' install '.implode(' ', $to_install);
|
2011-08-05 11:45:22 +02:00
|
|
|
echo "$cmd\n"; system($cmd);
|
|
|
|
}
|
2011-06-30 22:59:57 +02:00
|
|
|
}
|
2011-06-30 22:56:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function lang() {} // required to be able to include */setup/setup.inc.php files
|
2011-07-01 21:22:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fix egw_cache perms evtl. created by root, stoping webserver from accessing it
|
|
|
|
*/
|
|
|
|
function fix_perms()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
2011-08-05 11:45:22 +02:00
|
|
|
if (file_exists('/tmp/egw_cache'))
|
|
|
|
{
|
|
|
|
system('/bin/chown -R '.$config['webserver_user'].' /tmp/egw_cache');
|
|
|
|
system('/bin/chmod 700 /tmp/egw_cache');
|
|
|
|
}
|
2011-07-01 21:22:18 +02:00
|
|
|
}
|