mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-07-06 07:44:57 +03:00
CMake: install systemd configuration files
This commit is contained in:
@ -1,19 +1,39 @@
|
||||
include(GNUInstallDirs)
|
||||
|
||||
macro(install_wrapper_script component target destination)
|
||||
get_filename_component(filename ${target} NAME)
|
||||
# Creates wrapper scripts and installs them in the user's binaries directory, which is usually "/usr/local/bin".
|
||||
# This is required because symlinks use the folder they are in as working directory.
|
||||
macro(install_wrapper_script component target)
|
||||
get_filename_component(file_name ${target} NAME)
|
||||
|
||||
file(WRITE ${CMAKE_SOURCE_DIR}/tmp/script/${filename} "#!/bin/sh\n")
|
||||
file(APPEND ${CMAKE_SOURCE_DIR}/tmp/script/${filename} "${target} \"$@\"\n")
|
||||
file(APPEND ${CMAKE_SOURCE_DIR}/tmp/script/${filename} "exit $?\n")
|
||||
file(WRITE ${CMAKE_SOURCE_DIR}/tmp/script/${file_name} "#!/bin/sh\n")
|
||||
file(APPEND ${CMAKE_SOURCE_DIR}/tmp/script/${file_name} "${target} \"$@\"\n")
|
||||
file(APPEND ${CMAKE_SOURCE_DIR}/tmp/script/${file_name} "exit $?\n")
|
||||
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/tmp/script/${filename}
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/tmp/script/${file_name}
|
||||
COMPONENT ${component}
|
||||
DESTINATION ${destination}
|
||||
DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
endmacro(install_wrapper_script)
|
||||
|
||||
macro(install_systemd_service component file_path binary_path)
|
||||
get_filename_component(file_name ${file_path} NAME)
|
||||
get_filename_component(binary_directory ${binary_path} DIRECTORY)
|
||||
|
||||
file(READ ${file_path} FILE_CONTENT)
|
||||
string(REPLACE "[DIRECTORY]" ${binary_directory} FILE_CONTENT ${FILE_CONTENT})
|
||||
string(REPLACE "[BINARY]" ${binary_path} FILE_CONTENT ${FILE_CONTENT})
|
||||
file(WRITE ${CMAKE_SOURCE_DIR}/tmp/systemd/${file_name} ${FILE_CONTENT})
|
||||
|
||||
if(EXISTS "/lib/systemd/system")
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/tmp/systemd/${file_name}
|
||||
COMPONENT ${component}
|
||||
DESTINATION "/lib/systemd/system"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
|
||||
)
|
||||
endif()
|
||||
endmacro(install_systemd_service)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_definitions(-D_DEBUG -DDEBUG)
|
||||
endif()
|
||||
@ -128,7 +148,7 @@ add_custom_command(TARGET hamcore-archive-build
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tmp/hamcore.se2 ${VPNCMD_RUNTIME_OUTPUT_DIRECTORY}
|
||||
)
|
||||
|
||||
# Copy "vpnserver" directory to /usr/lib(exec)/softether/
|
||||
# Copy "vpnserver" directory to /usr/lib(exec)/softether/, install launch script and systemd service
|
||||
install(DIRECTORY ${VPNSERVER_RUNTIME_OUTPUT_DIRECTORY}
|
||||
COMPONENT "vpnserver"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/softether"
|
||||
@ -136,7 +156,10 @@ install(DIRECTORY ${VPNSERVER_RUNTIME_OUTPUT_DIRECTORY}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
|
||||
# Copy "vpnclient" directory to /usr/lib(exec)/softether/
|
||||
install_wrapper_script("vpnserver" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnserver/vpnserver")
|
||||
install_systemd_service("vpnserver" "${CMAKE_SOURCE_DIR}/systemd/softether-vpnserver.service" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnserver/vpnserver")
|
||||
|
||||
# Copy "vpnclient" directory to /usr/lib(exec)/softether/, install launch script and systemd service
|
||||
install(DIRECTORY ${VPNCLIENT_RUNTIME_OUTPUT_DIRECTORY}
|
||||
COMPONENT "vpnclient"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/softether"
|
||||
@ -144,7 +167,10 @@ install(DIRECTORY ${VPNCLIENT_RUNTIME_OUTPUT_DIRECTORY}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
|
||||
# Copy "vpnbridge" directory to /usr/lib(exec)/softether/
|
||||
install_wrapper_script("vpnclient" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnclient/vpnclient")
|
||||
install_systemd_service("vpnclient" "${CMAKE_SOURCE_DIR}/systemd/softether-vpnclient.service" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnclient/vpnclient")
|
||||
|
||||
# Copy "vpnbridge" directory to /usr/lib(exec)/softether/, install launch script and systemd service
|
||||
install(DIRECTORY ${VPNBRIDGE_RUNTIME_OUTPUT_DIRECTORY}
|
||||
COMPONENT "vpnbridge"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/softether"
|
||||
@ -152,7 +178,10 @@ install(DIRECTORY ${VPNBRIDGE_RUNTIME_OUTPUT_DIRECTORY}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
|
||||
# Copy "vpncmd" directory to /usr/lib(exec)/softether/
|
||||
install_wrapper_script("vpnbridge" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnbridge/vpnbridge")
|
||||
install_systemd_service("vpnbridge" "${CMAKE_SOURCE_DIR}/systemd/softether-vpnbridge.service" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnbridge/vpnbridge")
|
||||
|
||||
# Copy "vpncmd" directory to /usr/lib(exec)/softether/, install launch script and systemd service
|
||||
install(DIRECTORY ${VPNCMD_RUNTIME_OUTPUT_DIRECTORY}
|
||||
COMPONENT "vpncmd"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/softether"
|
||||
@ -160,12 +189,7 @@ install(DIRECTORY ${VPNCMD_RUNTIME_OUTPUT_DIRECTORY}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
|
||||
# Create wrapper scripts in the user's binaries directory, which is usually "/usr/local/bin".
|
||||
# This is required because symlinks use the folder they are in as working directory.
|
||||
install_wrapper_script("vpnserver" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnserver/vpnserver" ${CMAKE_INSTALL_FULL_BINDIR})
|
||||
install_wrapper_script("vpnclient" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnclient/vpnclient" ${CMAKE_INSTALL_FULL_BINDIR})
|
||||
install_wrapper_script("vpnbridge" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnbridge/vpnbridge" ${CMAKE_INSTALL_FULL_BINDIR})
|
||||
install_wrapper_script("vpncmd" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpncmd/vpncmd" ${CMAKE_INSTALL_FULL_BINDIR})
|
||||
install_wrapper_script("vpncmd" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpncmd/vpncmd")
|
||||
|
||||
# Print message after installing the targets
|
||||
install(CODE "message(\"\n----------------------------------------------------------------------------------------------------------------------------\")")
|
||||
|
Reference in New Issue
Block a user