3 require_once(CONST_LibDir.'/init-cmd.php');
4 require_once(CONST_LibDir.'/setup/SetupClass.php');
5 require_once(CONST_LibDir.'/setup_functions.php');
6 ini_set('memory_limit', '800M');
8 use Nominatim\Setup\SetupFunctions as SetupFunctions;
10 // (long-opt, short-opt, min-occurs, max-occurs, num-arguments, num-arguments, type, help)
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'),
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)'),
21 array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
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('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
42 array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
43 array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
44 array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
45 array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
46 array('setup-website', '', 0, 1, 0, 0, 'bool', 'Used to compile environment variables for the website'),
47 array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'),
50 // $aCMDOptions passed to getCmdOpt by reference
51 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
53 loadSettings($aCMDResult['project-dir'] ?? getcwd());
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 // ******************************************************
67 // instantiate Setup class
68 $oSetup = new SetupFunctions($aCMDResult);
70 // *******************************************************
71 // go through complete process if 'all' is selected or start selected functions
72 if ($aCMDResult['create-db'] || $aCMDResult['all']) {
73 $bDidSomething = true;
77 if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
78 $bDidSomething = true;
82 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
83 $bDidSomething = true;
84 $oSetup->importData($aCMDResult['osm-file']);
87 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
88 $bDidSomething = true;
89 $oSetup->createFunctions();
92 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
93 $bDidSomething = true;
94 $oSetup->createTables($aCMDResult['reverse-only']);
95 $oSetup->createFunctions();
96 $oSetup->createTableTriggers();
99 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
100 $bDidSomething = true;
101 $oSetup->createPartitionTables();
104 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
105 $bDidSomething = true;
106 $oSetup->createPartitionFunctions();
109 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
110 $bDidSomething = true;
111 $oSetup->importWikipediaArticles();
114 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
115 $bDidSomething = true;
116 $oSetup->loadData($aCMDResult['disable-token-precalc']);
119 if ($aCMDResult['import-tiger-data']) {
120 $bDidSomething = true;
121 $sTigerPath = getSetting('TIGER_DATA_PATH');
123 $sTigerPath = CONST_DataDir.'/data/tiger';
125 $oSetup->importTigerData($sTigerPath);
128 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
129 $bDidSomething = true;
130 $oSetup->calculatePostcodes($aCMDResult['all']);
133 if ($aCMDResult['index'] || $aCMDResult['all']) {
134 $bDidSomething = true;
135 $oSetup->index($aCMDResult['index-noanalyse']);
138 if ($aCMDResult['drop']) {
139 $bDidSomething = true;
140 $oSetup->drop($aCMDResult);
143 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
144 $bDidSomething = true;
145 $oSetup->createSearchIndices();
148 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
149 $bDidSomething = true;
150 $oSetup->createCountryNames($aCMDResult);
153 if ($aCMDResult['setup-website'] || $aCMDResult['all']) {
154 $bDidSomething = true;
155 $oSetup->setupWebsite();
158 // ******************************************************
159 // If we did something, repeat the warnings
160 if (!$bDidSomething) {
161 showUsage($aCMDOptions, true);
163 echo "Summary of warnings:\n\n";
166 info('Setup finished.');