Browse Source

Make init flavor configurable

Currently supported are Upstart and System-V.
tags/1.0
Timo Röhling 12 years ago
parent
commit
d830af0c56
3 changed files with 55 additions and 28 deletions
  1. 17
    2
      CMakeLists.txt
  2. 18
    26
      postinstall.cmake.in
  3. 20
    0
      postsrsd.upstart.in

+ 17
- 2
CMakeLists.txt View File

@@ -4,6 +4,21 @@ project(postsrsd C)
4 4
 find_program(HELP2MAN help2man DOC "path to help2man executable")
5 5
 find_program(DD dd DOC "path to dd executable")
6 6
 find_program(BASE64 base64 DOC "path to base64 executable")
7
+find_program(INSSERV insserv DOC "path to insserv executable")
8
+
9
+if(NOT DEFINED INIT_FLAVOR)
10
+    if(IS_DIRECTORY "/etc/init" AND EXISTS "/lib/init/upstart-job")
11
+        message(STATUS "Detected init flavor: upstart")
12
+        set(INIT_FLAVOR "upstart" CACHE STRING "Init daemon of this system")
13
+    elseif(IS_DIRECTORY "/etc/init.d")
14
+        message(STATUS "Detected init flavor: sysv")
15
+        set(INIT_FLAVOR "sysv" CACHE STRING "Init daemon of this system")
16
+    else()
17
+        message(STATUS "Detected init flavor: none")
18
+        message(STATUS "System startup files will not be installed")
19
+        set(INIT_FLAVOR "" CACHE STRING "Init daemon of this system")
20
+    endif()
21
+endif()
7 22
 
8 23
 add_executable(${PROJECT_NAME} postsrsd.c sha1.c srs2.c)
9 24
 
@@ -11,11 +26,12 @@ get_target_property(POSTSRSD ${PROJECT_NAME} LOCATION)
11 26
 get_filename_component(POSTSRSD ${POSTSRSD} NAME_WE)
12 27
 
13 28
 configure_file(${PROJECT_NAME}.init.in ${PROJECT_NAME}.init @ONLY)
29
+configure_file(${PROJECT_NAME}.upstart.in ${PROJECT_NAME}.upstart @ONLY)
14 30
 configure_file(postinstall.cmake.in postinstall.cmake @ONLY)
15 31
 
16 32
 if(HELP2MAN)
17 33
 add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
18
-	COMMAND ${HELP2MAN} ARGS -s8 -o${PROJECT_NAME}.8 -N -h-h -v-v ./${PROJECT_NAME}
34
+	COMMAND ${HELP2MAN} ARGS -s8 -o${PROJECT_NAME}.8 -N -h-h -v-v ${CMAKE_CURRENT_BINARY_DIR}/${POSTSRSD}
19 35
 	VERBATIM
20 36
 )
21 37
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.8 DESTINATION "share/man/man8")
@@ -23,6 +39,5 @@ endif()
23 39
 
24 40
 install(TARGETS ${PROJECT_NAME} DESTINATION "sbin")
25 41
 install(FILES README.md main.cf.ex DESTINATION "share/doc/${PROJECT_NAME}")
26
-install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.init DESTINATION "/etc/init.d" RENAME ${PROJECT_NAME})
27 42
 install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/postinstall.cmake")
28 43
 

+ 18
- 26
postinstall.cmake.in View File

@@ -1,31 +1,24 @@
1
-message(STATUS "Updating RC: $ENV{DESTDIR}/etc/init.d/@PROJECT_NAME@")
2
-file(MAKE_DIRECTORY 
3
-	"$ENV{DESTDIR}/etc/rc0.d" 
4
-	"$ENV{DESTDIR}/etc/rc1.d" 
5
-	"$ENV{DESTDIR}/etc/rc2.d" 
6
-	"$ENV{DESTDIR}/etc/rc3.d" 
7
-	"$ENV{DESTDIR}/etc/rc4.d" 
8
-	"$ENV{DESTDIR}/etc/rc5.d" 
9
-	"$ENV{DESTDIR}/etc/rc6.d" 
10
-)
11
-execute_process(
12
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc0.d/K20@PROJECT_NAME@
13
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc1.d/K20@PROJECT_NAME@
14
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc2.d/S20@PROJECT_NAME@
15
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc3.d/S20@PROJECT_NAME@
16
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc4.d/S20@PROJECT_NAME@
17
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc5.d/S20@PROJECT_NAME@
18
-	COMMAND ln -sf ../init.d/@PROJECT_NAME@ rc6.d/K20@PROJECT_NAME@
19
-	WORKING_DIRECTORY "$ENV{DESTDIR}/etc"
20
-)
21
-if(NOT EXISTS "$ENV{DESTDIR}/etc/default/@PROJECT_NAME@")
22
-	file(INSTALL "@CMAKE_CURRENT_SOURCE_DIR@/@PROJECT_NAME@.default" DESTINATION "/etc/default" RENAME "@PROJECT_NAME@")
23
-else()
24
-	message(STATUS "Keeping old version: $ENV{DESTDIR}/etc/default/@PROJECT_NAME@")
25
-endif()
1
+set(INIT_FLAVOR "@INIT_FLAVOR@")
26 2
 set(SECRET_FILE "@PROJECT_NAME@.secret")
27 3
 set(DD "@DD@")
28 4
 set(BASE64 "@BASE64@")
5
+set(INSSERV "@INSSERV@")
6
+
7
+if(INIT_FLAVOR AND NOT EXISTS "$ENV{DESTDIR}/etc/default/@PROJECT_NAME@")
8
+	file(INSTALL "@CMAKE_CURRENT_SOURCE_DIR@/@PROJECT_NAME@.default" DESTINATION "/etc/default" RENAME "@PROJECT_NAME@")
9
+endif()
10
+
11
+if(INIT_FLAVOR STREQUAL "sysv")
12
+	file(INSTALL "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
13
+	if(INSSERV)
14
+		execute_process(
15
+			COMMAND ${INSSERV} -p "$ENV{DESTDIR}/etc/init.d" @PROJECT_NAME@
16
+		)
17
+	endif()
18
+elseif(INIT_FLAVOR STREQUAL "upstart")
19
+	file(INSTALL "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.upstart" DESTINATION "/etc/init" RENAME "@PROJECT_NAME@.conf")
20
+endif()
21
+
29 22
 if(DD AND BASE64 AND EXISTS "/dev/urandom" AND NOT EXISTS "$ENV{DESTDIR}/etc/${SECRET_FILE}")
30 23
 	message(STATUS "Generating secret key")
31 24
 	execute_process(
@@ -38,4 +31,3 @@ if(DD AND BASE64 AND EXISTS "/dev/urandom" AND NOT EXISTS "$ENV{DESTDIR}/etc/${S
38 31
 file(INSTALL "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}" DESTINATION "/etc" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
39 32
 file(REMOVE "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}")
40 33
 endif()
41
-

+ 20
- 0
postsrsd.upstart.in View File

@@ -0,0 +1,20 @@
1
+description "Postfix Sender Rewriting Scheme daemon"
2
+author "Timo Röhling <timo.roehling@gmx.de>"
3
+
4
+start on (filesystem and net-device-up)
5
+stop on runlevel [!2345]
6
+respawn
7
+
8
+env DEFAULTFILE=/etc/default/@PROJECT_NAME@
9
+
10
+script
11
+	SRS_DOMAIN=`postconf -h mydomain || true`
12
+	SRS_FORWARD_PORT=10001
13
+	SRS_REVERSE_PORT=10002
14
+	SRS_SECRET=/etc/@PROJECT_NAME@.secret
15
+	RUN_AS=nobody
16
+	if [ -r "$DEFAULTFILE" ]; then
17
+		. "$DEFAULTFILE"
18
+	fi
19
+	exec @CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -4 -f$SRS_FORWARD_PORT -r$SRS_REVERSE_PORT -d$SRS_DOMAIN -s$SRS_SECRET -u$RUN_AS
20
+end script

Loading…
Cancel
Save