From b01071f52f919821c6da8f60e87f5a13bff68bb9 Mon Sep 17 00:00:00 2001 From: Undercover1989 Date: Mon, 7 Oct 2019 21:04:49 +0200 Subject: [PATCH 01/12] Added optional file ./config/user-patches.sh which is executed between configuration and starting daemons (misc-section) --- config/user-patches.sh | 6 ++++++ target/start-mailserver.sh | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 config/user-patches.sh diff --git a/config/user-patches.sh b/config/user-patches.sh new file mode 100644 index 00000000..32f56c49 --- /dev/null +++ b/config/user-patches.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +## +# This user script will be executed between configuration and starting daemons +## + diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 0260002f..c89d6f89 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -195,6 +195,7 @@ function register_functions() { ################### >> misc funcs _register_misc_function "_misc_save_states" + _register_misc_function "_misc_user_patches" ################### << misc funcs @@ -1595,6 +1596,18 @@ function _misc_save_states() { fi } +function _misc_user_patches() { + notify 'inf' 'Executing user-patches.sh' + + if [ -f /tmp/docker-mailserver/user-patches.sh ]; then + chmod +x /tmp/docker-mailserver/user-patches.sh + bash /tmp/docker-mailserver/user-patches.sh + notify 'inf' "user-patches.sh executed" + else + notify 'inf' "user-patches.sh not executed because optional '/tmp/docker-mailserver/user-patches.sh' is not provided." + fi +} + ########################################################################## # >> Start Daemons ########################################################################## From b5c422c3c5f00f87d357a3ef77403c1fcb12feb9 Mon Sep 17 00:00:00 2001 From: Undercover1989 Date: Tue, 8 Oct 2019 15:08:01 +0200 Subject: [PATCH 02/12] start user-patches.sh native instead of explicit using the bash-command --- target/start-mailserver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index c89d6f89..36da4dc7 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -1601,7 +1601,7 @@ function _misc_user_patches() { if [ -f /tmp/docker-mailserver/user-patches.sh ]; then chmod +x /tmp/docker-mailserver/user-patches.sh - bash /tmp/docker-mailserver/user-patches.sh + /tmp/docker-mailserver/user-patches.sh notify 'inf' "user-patches.sh executed" else notify 'inf' "user-patches.sh not executed because optional '/tmp/docker-mailserver/user-patches.sh' is not provided." From 0975b71d725420327489ac731176237fc10fd40e Mon Sep 17 00:00:00 2001 From: Undercover1989 Date: Tue, 8 Oct 2019 19:24:01 +0200 Subject: [PATCH 03/12] chown docker:docker /tmp/docker-mailserver/user-patches.sh --- target/start-mailserver.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 36da4dc7..16f9c99f 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -1601,6 +1601,7 @@ function _misc_user_patches() { if [ -f /tmp/docker-mailserver/user-patches.sh ]; then chmod +x /tmp/docker-mailserver/user-patches.sh + chown -R docker:docker /tmp/docker-mailserver/user-patches.sh /tmp/docker-mailserver/user-patches.sh notify 'inf' "user-patches.sh executed" else From 275a83667a76fef1046fa3306a09f72aa4686352 Mon Sep 17 00:00:00 2001 From: Undercover1989 Date: Tue, 8 Oct 2019 21:22:12 +0200 Subject: [PATCH 04/12] base files --- config/user-patches.sh | 2 ++ target/start-mailserver.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 config/user-patches.sh diff --git a/config/user-patches.sh b/config/user-patches.sh new file mode 100644 index 00000000..aedb86be --- /dev/null +++ b/config/user-patches.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo "Default user-patches.sh successfully executed!" \ No newline at end of file diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 0260002f..e027ba4e 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -195,6 +195,7 @@ function register_functions() { ################### >> misc funcs _register_misc_function "_misc_save_states" + _register_misc_function "_misc_user_patches" ################### << misc funcs @@ -1595,6 +1596,18 @@ function _misc_save_states() { fi } +function _misc_user_patches() { + notify 'task' '_misc_user_patches start' + + if [ -f /tmp/docker-mailserver/user-patches.sh ]; then + chmod +x /tmp/docker-mailserver/user-patches.sh + /tmp/docker-mailserver/user-patches.sh + notify 'inf' "Executed 'config/user-patches.sh'" + else + notify 'inf' "No user patches executed because optional '/tmp/docker-mailserver/user-patches.sh' is not provided." + fi +} + ########################################################################## # >> Start Daemons ########################################################################## From c30c3bf5defe805f0604ae0dfe667003f4f5edbe Mon Sep 17 00:00:00 2001 From: Vortex Date: Wed, 16 Oct 2019 18:56:06 +0200 Subject: [PATCH 05/12] moved user_patches from misc to nearly the end of setups --- target/start-mailserver.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 87c87605..de8340d1 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -172,7 +172,8 @@ function register_functions() { if [ "$LOGWATCH_TRIGGER" != "none" ]; then _register_setup_function "_setup_logwatch" fi - + + _register_setup_function "_setup_user_patches" # Compute last as the config files are modified in-place _register_setup_function "_setup_chksum_file" @@ -195,7 +196,6 @@ function register_functions() { ################### >> misc funcs _register_misc_function "_misc_save_states" - _register_misc_function "_misc_user_patches" ################### << misc funcs @@ -1466,6 +1466,18 @@ function _setup_logwatch() { esac } +function _setup_user_patches() { + notify 'inf' 'Executing user-patches.sh' + + if [ -f /tmp/docker-mailserver/user-patches.sh ]; then + chmod +x /tmp/docker-mailserver/user-patches.sh + /tmp/docker-mailserver/user-patches.sh + notify 'inf' "Executed 'config/user-patches.sh'" + else + notify 'inf' "No user patches executed because optional '/tmp/docker-mailserver/user-patches.sh' is not provided." + fi +} + function _setup_environment() { notify 'task' 'Setting up /etc/environment' @@ -1596,18 +1608,6 @@ function _misc_save_states() { fi } -function _misc_user_patches() { - notify 'inf' 'Executing user-patches.sh' - - if [ -f /tmp/docker-mailserver/user-patches.sh ]; then - chmod +x /tmp/docker-mailserver/user-patches.sh - /tmp/docker-mailserver/user-patches.sh - notify 'inf' "Executed 'config/user-patches.sh'" - else - notify 'inf' "No user patches executed because optional '/tmp/docker-mailserver/user-patches.sh' is not provided." - fi -} - ########################################################################## # >> Start Daemons ########################################################################## From 5e6969e594265e8747602ef92367c437d570df92 Mon Sep 17 00:00:00 2001 From: Vortex Date: Thu, 17 Oct 2019 13:13:20 +0200 Subject: [PATCH 06/12] Renamed the sample script in config, as it will be called if people make a copy. Better create a sample file with another name that has to be renamed to activate it. --- config/user-patches.sh | 2 -- config/user-patches.sh.dist | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) delete mode 100644 config/user-patches.sh create mode 100644 config/user-patches.sh.dist diff --git a/config/user-patches.sh b/config/user-patches.sh deleted file mode 100644 index aedb86be..00000000 --- a/config/user-patches.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo "Default user-patches.sh successfully executed!" \ No newline at end of file diff --git a/config/user-patches.sh.dist b/config/user-patches.sh.dist new file mode 100644 index 00000000..4b8163d2 --- /dev/null +++ b/config/user-patches.sh.dist @@ -0,0 +1,6 @@ +#!/bin/bash +## +# This user script will be executed between configuration and starting daemons +# To enable it you must save it in your config directory as "user-patches.sh" +## +echo "Default user-patches.sh successfully executed!" \ No newline at end of file From 437d3b74cc5b27a5eb94f62b08c14e80ddb289d2 Mon Sep 17 00:00:00 2001 From: Vortex Date: Thu, 31 Oct 2019 02:38:45 +0100 Subject: [PATCH 07/12] added test for "checking configuration: user-patches.sh executed" - should fail with this commit --- test/tests.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/tests.bats b/test/tests.bats index 54ee1acb..c64c73ad 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -27,6 +27,11 @@ function count_processed_changes() { # configuration checks # +@test "checking configuration: user-patches.sh executed" { + run docker logs mail | grep "Default user-patches.sh successfully executed!" + assert_output "Default user-patches.sh successfully executed!" +} + @test "checking configuration: hostname/domainname" { run docker run `docker inspect --format '{{ .Config.Image }}' mail` assert_success From def8400c1716c044df048cfbe9f03c69bc183c8a Mon Sep 17 00:00:00 2001 From: Vortex Date: Thu, 31 Oct 2019 09:01:44 +0100 Subject: [PATCH 08/12] added default "user-patches.sh" to the first container "mail" --- Makefile | 1 + test/config/user-patches/user-patches.sh | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 test/config/user-patches/user-patches.sh diff --git a/Makefile b/Makefile index e1aece17..d01131c3 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ + -v "`pwd`/test/config/user-patches/user-patches.sh:/tmp/docker-mailserver/user-patches.sh:ro \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ diff --git a/test/config/user-patches/user-patches.sh b/test/config/user-patches/user-patches.sh new file mode 100644 index 00000000..4b8163d2 --- /dev/null +++ b/test/config/user-patches/user-patches.sh @@ -0,0 +1,6 @@ +#!/bin/bash +## +# This user script will be executed between configuration and starting daemons +# To enable it you must save it in your config directory as "user-patches.sh" +## +echo "Default user-patches.sh successfully executed!" \ No newline at end of file From 2801a6a801f310ad86eaa952c2d4f08cd3f2fc53 Mon Sep 17 00:00:00 2001 From: vortex852456 Date: Thu, 31 Oct 2019 09:30:05 +0100 Subject: [PATCH 09/12] Update Makefile added missing qoute --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d01131c3..a6d0bf7f 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ - -v "`pwd`/test/config/user-patches/user-patches.sh:/tmp/docker-mailserver/user-patches.sh:ro \ + -v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh:ro \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ From 34f52c6ad08db0828a9d48dfdc083307439aac7b Mon Sep 17 00:00:00 2001 From: vortex852456 Date: Thu, 31 Oct 2019 09:51:40 +0100 Subject: [PATCH 10/12] only "assert_success" for user-patches.sh check --- test/tests.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.bats b/test/tests.bats index c64c73ad..63a71608 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -29,7 +29,7 @@ function count_processed_changes() { @test "checking configuration: user-patches.sh executed" { run docker logs mail | grep "Default user-patches.sh successfully executed!" - assert_output "Default user-patches.sh successfully executed!" + assert_success } @test "checking configuration: hostname/domainname" { From 37540509dcd9f3b4c4955776537c77a5b7933cc1 Mon Sep 17 00:00:00 2001 From: Sebastian Kaiser Date: Fri, 8 Nov 2019 02:22:33 +0100 Subject: [PATCH 11/12] - test for user-patches.sh --- Makefile | 2 +- test/config/user-patches/user-patches.sh | 2 +- test/tests.bats | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a6d0bf7f..b4bf98ac 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ - -v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh:ro \ + -v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ diff --git a/test/config/user-patches/user-patches.sh b/test/config/user-patches/user-patches.sh index 4b8163d2..2a315070 100644 --- a/test/config/user-patches/user-patches.sh +++ b/test/config/user-patches/user-patches.sh @@ -3,4 +3,4 @@ # This user script will be executed between configuration and starting daemons # To enable it you must save it in your config directory as "user-patches.sh" ## -echo "Default user-patches.sh successfully executed!" \ No newline at end of file +echo "Default user-patches.sh successfully executed" \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index 63a71608..bf3a0ddf 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -28,8 +28,8 @@ function count_processed_changes() { # @test "checking configuration: user-patches.sh executed" { - run docker logs mail | grep "Default user-patches.sh successfully executed!" - assert_success + run echo -n "`docker logs mail | grep 'user\-patches\.sh'`" + assert_output --partial "Default user-patches.sh successfully executed" } @test "checking configuration: hostname/domainname" { From ce0ec4b4a9ef3c5848cef591f0428eb411f23474 Mon Sep 17 00:00:00 2001 From: vortex852456 Date: Fri, 8 Nov 2019 12:24:28 +0100 Subject: [PATCH 12/12] Update user-patches.sh.dist Removed exclamation marker for consistency --- config/user-patches.sh.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/user-patches.sh.dist b/config/user-patches.sh.dist index 4b8163d2..0e374662 100644 --- a/config/user-patches.sh.dist +++ b/config/user-patches.sh.dist @@ -3,4 +3,4 @@ # This user script will be executed between configuration and starting daemons # To enable it you must save it in your config directory as "user-patches.sh" ## -echo "Default user-patches.sh successfully executed!" \ No newline at end of file +echo "Default user-patches.sh successfully executed"