Skip to content

Commit b3e94d2

Browse files
committed
osm2pgsql-replication: run against installed osm2pgsql
When installing osm2pgsql-replication run the script per default against osm2pgsql in the same directory. This avoids potential security issues through PATH manipulation.
1 parent 8760df7 commit b3e94d2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,11 @@ add_subdirectory(docs)
332332
# Install
333333
#############################################################
334334

335+
include(GNUInstallDirs)
336+
335337
if (ENABLE_INSTALL)
336338
install(TARGETS osm2pgsql DESTINATION bin)
337-
install(PROGRAMS scripts/osm2pgsql-replication DESTINATION bin)
338339
install(FILES default.style empty.style DESTINATION share/osm2pgsql)
340+
install(CODE "set(OSM2PGSQL_BINDIR ${CMAKE_INSTALL_FULL_BINDIR})
341+
configure_file(${PROJECT_SOURCE_DIR}/scripts/osm2pgsql-replication ${CMAKE_INSTALL_FULL_BINDIR}/osm2pgsql-replication)")
339342
endif()

scripts/osm2pgsql-replication

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ except ImportError:
5151

5252
LOG = logging.getLogger()
5353

54+
# Will be replaced when installed via CMake.
55+
INSTALL_PREFIX = '@OSM2PGSQL_BINDIR@/'
56+
if INSTALL_PREFIX.startswith('@'):
57+
INSTALL_PREFIX = ''
5458

5559
def pretty_format_timedelta(seconds):
5660
minutes = int(seconds/60)
@@ -484,8 +488,8 @@ def get_parser():
484488
help='File to save changes before they are applied to osm2pgsql.')
485489
cmd.add_argument('--max-diff-size', type=int, default=500,
486490
help='Maximum data to load in MB (default: 500MB)')
487-
cmd.add_argument('--osm2pgsql-cmd', default='osm2pgsql',
488-
help='Path to osm2pgsql command (default: osm2pgsql)')
491+
cmd.add_argument('--osm2pgsql-cmd', default=INSTALL_PREFIX + 'osm2pgsql',
492+
help=f'Path to osm2pgsql command (default: {INSTALL_PREFIX}osm2pgsql)')
489493
cmd.add_argument('--once', action='store_true',
490494
help='Run updates only once, even when more data is available.')
491495
cmd.add_argument('--post-processing', metavar='SCRIPT',

0 commit comments

Comments
 (0)