Skip to content

Commit

Permalink
Fix: nzbget.conf.template installation path (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnzbk authored Oct 9, 2024
1 parent 347dce3 commit c2b1f88
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
set(DOC_FILES
${CMAKE_SOURCE_DIR}/ChangeLog.md
${CMAKE_SOURCE_DIR}/COPYING
)
set(SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/${PACKAGE})
set(CONF_FILE ${CMAKE_SOURCE_DIR}/nzbget.conf)
set(WEBUI_DIR ${CMAKE_SOURCE_DIR}/webui)
set(DOC_FILES_DEST ${SHARE_DIR}/doc)
set(CONF_TEMPLATE_FILE_DEST ${SHARE_DIR})
set(WEBUI_DIR_DEST ${SHARE_DIR})
set(CONF_FILE nzbget.conf)
set(SHARE_DIR_DEST ${CMAKE_INSTALL_PREFIX}/share/${PACKAGE})
set(DOC_FILES_SRC ${CMAKE_SOURCE_DIR}/ChangeLog.md ${CMAKE_SOURCE_DIR}/COPYING)
set(CONF_FILE_SRC ${CMAKE_SOURCE_DIR}/${CONF_FILE})
set(WEBUI_DIR_SRC ${CMAKE_SOURCE_DIR}/webui)
set(DOC_FILES_DEST ${SHARE_DIR_DEST}/doc)
set(WEBUI_DIR_DEST ${SHARE_DIR_DEST})
set(TEMPLATE_CONF_FILE_DEST ${SHARE_DIR_DEST})
set(CONF_FILE_DEST ${CMAKE_INSTALL_PREFIX}/etc)
set(BIN_FILE_DEST ${CMAKE_INSTALL_PREFIX}/bin)

file(READ ${CONF_FILE_SRC} CONFIG_CONTENT)
string(REPLACE "WebDir=" "WebDir=${WEBUI_DIR_DEST}/webui" MODIFIED_CONFIG_CONTENT "${CONFIG_CONTENT}")
string(REPLACE "ConfigTemplate=" "ConfigTemplate=${TEMPLATE_CONF_FILE_DEST}/${CONF_FILE}" MODIFIED_CONFIG_CONTENT "${MODIFIED_CONFIG_CONTENT}")
file(WRITE ${CMAKE_BINARY_DIR}/${CONF_FILE} ${MODIFIED_CONFIG_CONTENT})

install(TARGETS ${PACKAGE} PERMISSIONS
OWNER_EXECUTE
OWNER_WRITE
Expand All @@ -18,32 +22,26 @@ install(TARGETS ${PACKAGE} PERMISSIONS
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE
DESTINATION ${BIN_FILE_DEST})
install(FILES ${DOC_FILES} DESTINATION ${DOC_FILES_DEST})
install(DIRECTORY ${WEBUI_DIR} DESTINATION ${WEBUI_DIR_DEST})

file(READ ${CONF_FILE} CONFIG_CONTENT)
string(REPLACE "WebDir=" "WebDir=${WEBUI_DIR_DEST}/webui" MODIFIED_CONFIG_CONTENT "${CONFIG_CONTENT}")
string(REPLACE "ConfigTemplate=" "ConfigTemplate=${CONF_TEMPLATE_FILE_DEST}/nzbget.conf" MODIFIED_CONFIG_CONTENT "${MODIFIED_CONFIG_CONTENT}")
file(WRITE ${CMAKE_BINARY_DIR}/nzbget.conf "${MODIFIED_CONFIG_CONTENT}")
DESTINATION ${BIN_FILE_DEST}
)
install(DIRECTORY ${WEBUI_DIR_SRC} DESTINATION ${WEBUI_DIR_DEST})
install(FILES ${DOC_FILES_SRC} DESTINATION ${DOC_FILES_DEST})
install(FILES ${CMAKE_BINARY_DIR}/${CONF_FILE} DESTINATION ${TEMPLATE_CONF_FILE_DEST})

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -E remove_directory ${DOC_FILES_DEST}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${SHARE_DIR}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${SHARE_DIR_DEST}
COMMAND ${CMAKE_COMMAND} -E remove ${BIN_FILE_DEST}/${PACKAGE}
COMMENT "Uninstalling" ${PACKAGE}
)

add_custom_target(install-conf
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_PREFIX}/etc
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/nzbget.conf ${CMAKE_INSTALL_PREFIX}/etc/nzbget.conf
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/nzbget.conf ${CONF_TEMPLATE_FILE_DEST}/nzbget.conf
COMMAND ${CMAKE_COMMAND} -E make_directory ${CONF_FILE_DEST}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/${CONF_FILE} ${CONF_FILE_DEST}/${CONF_FILE}
COMMENT "Installing nzbget.conf"
)

add_custom_target(uninstall-conf
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_PREFIX}/etc
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_INSTALL_PREFIX}/etc/nzbget.conf
COMMAND ${CMAKE_COMMAND} -E remove ${CONF_TEMPLATE_FILE_DEST}/nzbget.conf
COMMAND ${CMAKE_COMMAND} -E remove ${CONF_FILE_DEST}/${CONF_FILE}
COMMENT "Unstalling nzbget.conf"
)

0 comments on commit c2b1f88

Please sign in to comment.