4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 // ->indirect via init-cmd.php->/lib/cmd.php for runWithEnv, getCmdOpt
7 // ->indirect via init-cmd.php->/lib/init.php->db.php for &getDB()
9 require_once(CONST_BasePath.'/lib/setup/SetupClass.php');
10 require_once(CONST_BasePath.'/lib/setup_functions.php');
11 ini_set('memory_limit', '800M');
13 use Nominatim\Setup\SetupFunctions as SetupFunctions;
15 // (long-opt, short-opt, min-occurs, max-occurs, num-arguments, num-arguments, type, help)
18 'Create and setup nominatim search system',
19 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
20 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
21 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
23 array('osm-file', '', 0, 1, 1, 1, 'realpath', 'File to import'),
24 array('threads', '', 0, 1, 1, 1, 'int', 'Number of threads (where possible)'),
26 array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
28 array('create-db', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
29 array('setup-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
30 array('import-data', '', 0, 1, 0, 0, 'bool', 'Import a osm file'),
31 array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
32 array('create-functions', '', 0, 1, 0, 0, 'bool', 'Create functions'),
33 array('enable-diff-updates', '', 0, 1, 0, 0, 'bool', 'Turn on the code required to make diff updates work'),
34 array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'),
35 array('ignore-errors', '', 0, 1, 0, 0, 'bool', 'Continue import even when errors in SQL are present (EXPERT)'),
36 array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
37 array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'),
38 array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'),
39 array('no-partitions', '', 0, 1, 0, 0, 'bool', 'Do not partition search indices (speeds up import of single country extracts)'),
40 array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
41 array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
42 array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
43 array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'),
44 array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
45 array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
46 array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
47 array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
48 array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
49 array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
50 array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
53 // $aCMDOptions passed to getCmdOpt by reference
54 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
56 $bDidSomething = false;
58 //*******************************************************
59 // Making some sanity check:
60 // Check if osm-file is set and points to a valid file
61 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
62 // to remain in /lib/setup_functions.php function
63 checkInFile($aCMDResult['osm-file']);
66 // osmosis init is no longer supported
67 if ($aCMDResult['osmosis-init']) {
68 $bDidSomething = true;
69 echo "Command 'osmosis-init' no longer available, please use utils/update.php --init-updates.\n";
72 // ******************************************************
73 // instantiate Setup class
74 $oSetup = new SetupFunctions($aCMDResult);
76 // *******************************************************
77 // go through complete process if 'all' is selected or start selected functions
78 if ($aCMDResult['create-db'] || $aCMDResult['all']) {
79 $bDidSomething = true;
85 if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
86 $bDidSomething = true;
90 // Try accessing the C module, so we know early if something is wrong
91 if (!checkModulePresence()) {
92 fail('error loading nominatim.so module');
95 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
96 $bDidSomething = true;
97 $oSetup->importData($aCMDResult['osm-file']);
100 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
101 $bDidSomething = true;
102 $oSetup->createFunctions();
105 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
106 $bDidSomething = true;
107 $oSetup->createTables();
108 $oSetup->createFunctions();
111 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
112 $bDidSomething = true;
113 $oSetup->createPartitionTables();
116 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
117 $bDidSomething = true;
118 $oSetup->createPartitionFunctions();
121 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
122 $bDidSomething = true;
123 $oSetup->importWikipediaArticles();
126 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
127 $bDidSomething = true;
128 $oSetup->loadData($aCMDResult['disable-token-precalc']);
131 if ($aCMDResult['import-tiger-data']) {
132 $bDidSomething = true;
133 $oSetup->importTigerData();
136 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
137 $bDidSomething = true;
138 $oSetup->calculatePostcodes($aCMDResult['all']);
141 if ($aCMDResult['index'] || $aCMDResult['all']) {
142 $bDidSomething = true;
143 $oSetup->index($aCMDResult['index-noanalyse']);
146 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
147 $bDidSomething = true;
148 $oSetup->createSearchIndices();
151 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
152 $bDidSomething = true;
153 $oSetup->createCountryNames($aCMDResult);
156 if ($aCMDResult['drop']) {
157 $bDidSomething = true;
158 $oSetup->drop($aCMDResult);
161 // ******************************************************
162 // If we did something, repeat the warnings
163 if (!$bDidSomething) {
164 showUsage($aCMDOptions, true);
166 echo "Summary of warnings:\n\n";
169 info('Setup finished.');