-
-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate startup scripts in CMake install process with automatic init system detection #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||||||||
| # Detect Linux init system and install appropriate startup script | ||||||||||||
| # This script runs at install time to detect the init system and install the correct startup script | ||||||||||||
|
|
||||||||||||
| message(STATUS "========================================") | ||||||||||||
| message(STATUS "Installing startup script...") | ||||||||||||
| message(STATUS "========================================") | ||||||||||||
|
|
||||||||||||
| # Detect systemd | ||||||||||||
| if(EXISTS "/run/systemd/system" OR EXISTS "/usr/lib/systemd/system") | ||||||||||||
| set(INIT_SYSTEM "systemd") | ||||||||||||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/systemd/falcon-as.service") | ||||||||||||
| set(INIT_SCRIPT_DEST "/etc/systemd/system/falcon-as.service") | ||||||||||||
| message(STATUS "Detected init system: systemd") | ||||||||||||
|
|
||||||||||||
| # Detect OpenRC | ||||||||||||
| elseif((EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") OR EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run") | ||||||||||||
| set(INIT_SYSTEM "openrc") | ||||||||||||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as") | ||||||||||||
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | ||||||||||||
| message(STATUS "Detected init system: OpenRC") | ||||||||||||
|
|
||||||||||||
| # Fallback to SysVinit | ||||||||||||
| elseif(EXISTS "/etc/init.d") | ||||||||||||
| set(INIT_SYSTEM "sysvinit") | ||||||||||||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as") | ||||||||||||
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | ||||||||||||
| message(STATUS "Detected init system: SysVinit") | ||||||||||||
|
|
||||||||||||
| else() | ||||||||||||
| message(WARNING "Could not detect init system. Defaulting to SysVinit.") | ||||||||||||
| set(INIT_SYSTEM "sysvinit") | ||||||||||||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as") | ||||||||||||
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | ||||||||||||
|
Comment on lines
+30
to
+33
|
||||||||||||
| endif() | ||||||||||||
|
|
||||||||||||
| # Check if source script exists | ||||||||||||
| if(NOT EXISTS "${INIT_SCRIPT_SRC}") | ||||||||||||
| message(FATAL_ERROR "Startup script not found: ${INIT_SCRIPT_SRC}") | ||||||||||||
| endif() | ||||||||||||
|
|
||||||||||||
| # Install the startup script | ||||||||||||
| message(STATUS "Installing ${INIT_SYSTEM} startup script...") | ||||||||||||
| message(STATUS " Source: ${INIT_SCRIPT_SRC}") | ||||||||||||
| message(STATUS " Destination: ${INIT_SCRIPT_DEST}") | ||||||||||||
|
|
||||||||||||
| execute_process( | ||||||||||||
| COMMAND ${CMAKE_COMMAND} -E copy ${INIT_SCRIPT_SRC} ${INIT_SCRIPT_DEST} | ||||||||||||
| RESULT_VARIABLE INSTALL_RESULT | ||||||||||||
| ERROR_VARIABLE INSTALL_ERROR | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| if(INSTALL_RESULT EQUAL 0) | ||||||||||||
| message(STATUS "✓ Startup script installed successfully") | ||||||||||||
|
|
||||||||||||
| # Make executable for init.d scripts | ||||||||||||
| if(INIT_SYSTEM STREQUAL "openrc" OR INIT_SYSTEM STREQUAL "sysvinit") | ||||||||||||
| execute_process( | ||||||||||||
| COMMAND chmod +x ${INIT_SCRIPT_DEST} | ||||||||||||
| RESULT_VARIABLE CHMOD_RESULT | ||||||||||||
| ) | ||||||||||||
| if(CHMOD_RESULT EQUAL 0) | ||||||||||||
| message(STATUS "✓ Made script executable") | ||||||||||||
|
||||||||||||
| message(STATUS "✓ Made script executable") | |
| message(STATUS "✓ Made script executable") | |
| else() | |
| message(WARNING "Failed to make script executable: ${INIT_SCRIPT_DEST}") | |
| message(WARNING "You may need to run 'chmod +x ${INIT_SCRIPT_DEST}' with sudo/root privileges.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The OpenRC detection logic is complex and could benefit from being split into separate conditions for better readability. Consider breaking this into multiple elseif statements or storing intermediate boolean variables.