]> git.openstreetmap.org Git - nominatim.git/blob - utils/setup.php
Merge pull request #1663 from mtmail/vagrant-centos-8
[nominatim.git] / utils / setup.php
1 <?php
2
3 require_once(CONST_BasePath.'/lib/init-cmd.php');
4 require_once(CONST_BasePath.'/lib/setup/SetupClass.php');
5 require_once(CONST_BasePath.'/lib/setup_functions.php');
6 ini_set('memory_limit', '800M');
7
8 use Nominatim\Setup\SetupFunctions as SetupFunctions;
9
10 // (long-opt, short-opt, min-occurs, max-occurs, num-arguments, num-arguments, type, help)
11 $aCMDOptions
12 = array(
13    'Create and setup nominatim search system',
14    array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
15    array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
16    array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
17
18    array('osm-file', '', 0, 1, 1, 1, 'realpath', 'File to import'),
19    array('threads', '', 0, 1, 1, 1, 'int', 'Number of threads (where possible)'),
20
21    array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
22
23    array('create-db', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
24    array('setup-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
25    array('import-data', '', 0, 1, 0, 0, 'bool', 'Import a osm file'),
26    array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
27    array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Do not create search tables and indexes'),
28    array('create-functions', '', 0, 1, 0, 0, 'bool', 'Create functions'),
29    array('enable-diff-updates', '', 0, 1, 0, 0, 'bool', 'Turn on the code required to make diff updates work'),
30    array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'),
31    array('ignore-errors', '', 0, 1, 0, 0, 'bool', 'Continue import even when errors in SQL are present (EXPERT)'),
32    array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
33    array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'),
34    array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'),
35    array('no-partitions', '', 0, 1, 0, 0, 'bool', 'Do not partition search indices (speeds up import of single country extracts)'),
36    array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
37    array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
38    array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
39    array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'),
40    array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
41    array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
42    array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
43    array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
44    array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
45    array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
46    array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
47   );
48
49 // $aCMDOptions passed to getCmdOpt by reference
50 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
51
52 $bDidSomething = false;
53
54 //*******************************************************
55 // Making some sanity check:
56 // Check if osm-file is set and points to a valid file
57 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
58     // to remain in /lib/setup_functions.php function
59     checkInFile($aCMDResult['osm-file']);
60 }
61
62 // osmosis init is no longer supported
63 if ($aCMDResult['osmosis-init']) {
64     $bDidSomething = true;
65     echo "Command 'osmosis-init' no longer available, please use utils/update.php --init-updates.\n";
66 }
67
68 // ******************************************************
69 // instantiate Setup class
70 $oSetup = new SetupFunctions($aCMDResult);
71
72 // *******************************************************
73 // go through complete process if 'all' is selected or start selected functions
74 if ($aCMDResult['create-db'] || $aCMDResult['all']) {
75     $bDidSomething = true;
76     $oSetup->createDB();
77 }
78
79 $oSetup->connect();
80
81 if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
82     $bDidSomething = true;
83     $oSetup->setupDB();
84 }
85
86 // Try accessing the C module, so we know early if something is wrong
87 checkModulePresence(); // raises exception on failure
88
89 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
90     $bDidSomething = true;
91     $oSetup->importData($aCMDResult['osm-file']);
92 }
93
94 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
95     $bDidSomething = true;
96     $oSetup->createFunctions();
97 }
98
99 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
100     $bDidSomething = true;
101     $oSetup->createTables($aCMDResult['reverse-only']);
102     $oSetup->createFunctions();
103     $oSetup->createTableTriggers();
104 }
105
106 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
107     $bDidSomething = true;
108     $oSetup->createPartitionTables();
109 }
110
111 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
112     $bDidSomething = true;
113     $oSetup->createPartitionFunctions();
114 }
115
116 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
117     $bDidSomething = true;
118     $oSetup->importWikipediaArticles();
119 }
120
121 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
122     $bDidSomething = true;
123     $oSetup->loadData($aCMDResult['disable-token-precalc']);
124 }
125
126 if ($aCMDResult['import-tiger-data']) {
127     $bDidSomething = true;
128     $oSetup->importTigerData();
129 }
130
131 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
132     $bDidSomething = true;
133     $oSetup->calculatePostcodes($aCMDResult['all']);
134 }
135
136 if ($aCMDResult['index'] || $aCMDResult['all']) {
137     $bDidSomething = true;
138     $oSetup->index($aCMDResult['index-noanalyse']);
139 }
140
141 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
142     $bDidSomething = true;
143     $oSetup->createSearchIndices();
144 }
145
146 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
147     $bDidSomething = true;
148     $oSetup->createCountryNames($aCMDResult);
149 }
150
151 if ($aCMDResult['drop']) {
152     $bDidSomething = true;
153     $oSetup->drop($aCMDResult);
154 }
155
156 // ******************************************************
157 // If we did something, repeat the warnings
158 if (!$bDidSomething) {
159     showUsage($aCMDOptions, true);
160 } else {
161     echo "Summary of warnings:\n\n";
162     repeatWarnings();
163     echo "\n";
164     info('Setup finished.');
165 }