diff --git a/BUILD.md b/BUILD.md index 8e881385..8515528d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -42,6 +42,10 @@ For Ubuntu/Debian systems, this might look like: sudo apt install make cmake libglib2.0-dev libcairo2-dev librsvg2-dev libfuse-dev libarchive-dev libxpm-dev libcurl4-openssl-dev libboost-all-dev qtbase5-dev qtdeclarative5-dev qttools5-dev-tools patchelf libc6-dev libc6-dev gcc-multilib g++-multilib ``` +## Options +By default, AppImageLauncher is built for System-D based systems. +OpenRC can be targeted instead by adding `-DSERVICE_TYPE="openrc"`. + ## Build Please update the `PREFIX` if you want. The prefix is the location the final application will be installed to. Usual locations may be `/usr/local` (default), `/usr`, `~/.local` or `/opt`. diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fa21c65..764bcb0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,16 @@ endif() # note: for the time being, we require AppImageUpdate to be fetched during build, even if only to make libappimage available FetchContent_MakeAvailable(AppImageUpdate) +# choose what init service system to target (for daemon user service) +# set by adding -DSERVICE_TYPE="" when calling cmake +# options: systemd, openrc +set(SERVICE_TYPE "systemd" CACHE STRING "init service provider to target") +if (SERVICE_TYPE STREQUAL "systemd") + add_definitions(-DSERVICE_TYPE_SYSTEMD) +elseif (SERVICE_TYPE STREQUAL "openrc") + add_definitions(-DSERVICE_TYPE_OPENRC) +endif() + # install resources, bundle libraries privately, etc. # initializes important installation destination variables, therefore must be included before adding subdirectories include(cmake/install.cmake) diff --git a/cmake/install.cmake b/cmake/install.cmake index ee3de23e..3138efb1 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -89,14 +89,35 @@ if(NOT BUILD_LITE) ) endif() -# install systemd service configuration for appimagelauncherd -configure_file( - ${PROJECT_SOURCE_DIR}/resources/appimagelauncherd.service.in - ${PROJECT_BINARY_DIR}/resources/appimagelauncherd.service - @ONLY -) -# caution: don't use ${CMAKE_INSTALL_LIBDIR} here, it's really just lib/systemd/user -install( - FILES ${PROJECT_BINARY_DIR}/resources/appimagelauncherd.service - DESTINATION lib/systemd/user/ COMPONENT APPIMAGELAUNCHER -) +if (SERVICE_TYPE STREQUAL "systemd") + # install systemd service configuration for appimagelauncherd + configure_file( + ${PROJECT_SOURCE_DIR}/resources/appimagelauncherd.service.in + ${PROJECT_BINARY_DIR}/resources/appimagelauncherd.service + @ONLY + ) + # caution: don't use ${CMAKE_INSTALL_LIBDIR} here, it's really just lib/systemd/user + install( + FILES ${PROJECT_BINARY_DIR}/resources/appimagelauncherd.service + DESTINATION lib/systemd/user/ COMPONENT APPIMAGELAUNCHER + ) + message("Using SystemD service") +elseif (SERVICE_TYPE STREQUAL "openrc") + # install openrc service configuration for appimagelauncherd + # + # the output file name will be the name of the service + # so it must be "appimagelauncherd" + configure_file( + ${PROJECT_SOURCE_DIR}/resources/appimagelauncherd_openrc.in + ${PROJECT_BINARY_DIR}/resources/appimagelauncherd + @ONLY + ) + install( + FILES ${PROJECT_BINARY_DIR}/resources/appimagelauncherd + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE + DESTINATION etc/user/init.d COMPONENT APPIMAGELAUNCHER + ) + message("Using OpenRC service") +endif() diff --git a/resources/appimagelauncherd_openrc.in b/resources/appimagelauncherd_openrc.in new file mode 100755 index 00000000..2ffa6273 --- /dev/null +++ b/resources/appimagelauncherd_openrc.in @@ -0,0 +1,9 @@ +#!/sbin/openrc-run + +#OpenRC user service + +description="AppImageLauncher daemon" +supervisor="supervise-daemon" +respawn_delay=10 +command="@CMAKE_INSTALL_PREFIX@/bin/appimagelauncherd" +output_log="${XDG_STATE_HOME}/appimagelauncherd" diff --git a/src/ui/settings_dialog.cpp b/src/ui/settings_dialog.cpp index c2b451de..23e99533 100644 --- a/src/ui/settings_dialog.cpp +++ b/src/ui/settings_dialog.cpp @@ -157,6 +157,7 @@ void SettingsDialog::saveSettings() { void SettingsDialog::toggleDaemon() { // assumes defaults if config doesn't exist or lacks the related key(s) if (settingsFile) { +#ifdef SERVICE_TYPE_SYSTEMD if (settingsFile->value("AppImageLauncher/enable_daemon", "true").toBool()) { system("systemctl --user enable appimagelauncherd.service"); // we want to actually restart the service to apply the new configuration @@ -165,6 +166,17 @@ void SettingsDialog::toggleDaemon() { system("systemctl --user disable appimagelauncherd.service"); system("systemctl --user stop appimagelauncherd.service"); } +#elif SERVICE_TYPE_OPENRC + if (settingsFile->value("AppImageLauncher/enable_daemon", "true").toBool()) { + // enable service and restart + system("rc-update add --user appimagelauncherd default"); + system("rc-service --user appimagelauncherd restart"); + } else { + // disable service and stop it + system("rc-update del --user appimagelauncherd default"); + system("rc-service --user appimagelauncherd stop"); + } +#endif } }