Nominatim/utils/setup.php

77 lines
2.8 KiB
PHP
Raw Normal View History

2010-10-24 03:12:37 +04:00
#!/usr/bin/php -Cq
<?php
2010-10-25 16:22:22 +04:00
require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
2010-10-24 03:12:37 +04:00
ini_set('memory_limit', '800M');
$aCMDOptions = array(
"Create and setup nominatim search system",
array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
2010-10-25 16:22:22 +04:00
array('create-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
2010-10-26 19:22:41 +04:00
array('load-data', '', 0, 1, 1, 1, 'realpath', 'Import a osm file'),
2010-10-24 03:12:37 +04:00
array('create-partitions', '', 0, 1, 0, 0, 'bool', 'Create required partition tables and triggers'),
);
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
2010-10-26 19:22:41 +04:00
$bDidSomething = false;
2010-10-25 16:22:22 +04:00
if ($aCMDResult['create-db'])
{
2010-10-26 19:22:41 +04:00
$bDidSomething = true;
2010-10-25 16:22:22 +04:00
// TODO: path detection, detection memory, etc.
2010-10-26 19:22:41 +04:00
// passthru('createdb nominatim');
2010-10-25 16:22:22 +04:00
passthru('createlang plpgsql nominatim');
2010-10-26 19:22:41 +04:00
passthru('psql -f '.CONST_Path_Postgresql_Contrib.'/_int.sql nominatim');
passthru('psql -f '.CONST_Path_Postgresql_Contrib.'/hstore.sql nominatim');
passthru('psql -f '.CONST_Path_Postgresql_Postgis.'/postgis.sql nominatim');
passthru('psql -f '.CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/data/country_name.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/data/country_osm_grid.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/data/gb_postcode.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/data/us_statecounty.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/data/us_state.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/data/worldboundaries.sql nominatim');
2010-10-25 16:22:22 +04:00
}
2010-10-26 19:22:41 +04:00
if (isset($aCMDResult['load-data']) && $aCMDResult['load-data'])
2010-10-25 16:22:22 +04:00
{
2010-10-26 19:22:41 +04:00
$bDidSomething = true;
passthru(CONST_BasePath.'/osm2pgsql/osm2pgsql -lsc -O gazetteer -C 10000 --hstore -d nominatim '.$aCMDResult['load-data']);
passthru('psql -f '.CONST_BasePath.'/sql/functions.sql nominatim');
passthru('psql -f '.CONST_BasePath.'/sql/tables.sql nominatim');
2010-10-25 16:22:22 +04:00
}
2010-10-24 03:12:37 +04:00
if ($aCMDResult['create-partitions'])
{
2010-10-26 19:22:41 +04:00
$bDidSomething = true;
2010-10-24 03:12:37 +04:00
$sSQL = 'select distinct country_code from country_name order by country_code';
$aPartitions = $oDB->getCol($sSQL);
2010-10-25 16:22:22 +04:00
if (PEAR::isError($aPartitions))
{
fail($aPartitions->getMessage());
}
2010-10-24 03:12:37 +04:00
$aPartitions[] = 'none';
$sTemplate = file_get_contents(CONST_BasePath.'/sql/partitions.src.sql');
preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
foreach($aMatches as $aMatch)
{
$sResult = '';
foreach($aPartitions as $sPartitionName)
{
$sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
}
$sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
}
echo $sTemplate;
2010-10-25 16:22:22 +04:00
exit;
2010-10-24 03:12:37 +04:00
}
2010-10-26 19:22:41 +04:00
if (!$bDidSomething)
{
showUsage($aCMDOptions, true);
}