From 6c83e329e99f289dd82de9482709760d51b7a735 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Sat, 30 Nov 2019 22:41:19 -0800 Subject: [PATCH] bug fixes --- cookbooks/clean-up/attributes/default.bash | 5 +++++ cookbooks/clean-up/recipes/install-delete-old-logs.bash | 7 ++++++- .../delete-old-logs => templates/delete-old-logs.bash} | 2 +- libraries/util.bash | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 cookbooks/clean-up/attributes/default.bash rename cookbooks/clean-up/{files/delete-old-logs => templates/delete-old-logs.bash} (98%) diff --git a/cookbooks/clean-up/attributes/default.bash b/cookbooks/clean-up/attributes/default.bash new file mode 100755 index 00000000..7d08e5e0 --- /dev/null +++ b/cookbooks/clean-up/attributes/default.bash @@ -0,0 +1,5 @@ +#!/bin/bash -e + +export CLEAN_UP_OLD_LOG_FOLDER_PATHS=( + '/var/log' +) \ No newline at end of file diff --git a/cookbooks/clean-up/recipes/install-delete-old-logs.bash b/cookbooks/clean-up/recipes/install-delete-old-logs.bash index 21fc46a6..e9ffde1b 100755 --- a/cookbooks/clean-up/recipes/install-delete-old-logs.bash +++ b/cookbooks/clean-up/recipes/install-delete-old-logs.bash @@ -4,7 +4,11 @@ function install() { umask '0022' - cp -f "$(dirname "${BASH_SOURCE[0]}")/../files/delete-old-logs" '/etc/cron.hourly' + createFileFromTemplate \ + "$(dirname "${BASH_SOURCE[0]}")/../templates/delete-old-logs.bash" \ + '/etc/cron.hourly/delete-old-logs' \ + '__LOG_FOLDER_PATHS__' "$(arrayToParameters "${CLEAN_UP_OLD_LOG_FOLDER_PATHS[@]}")" + chmod 755 '/etc/cron.hourly/delete-old-logs' cat '/etc/cron.hourly/delete-old-logs' echo @@ -15,6 +19,7 @@ function install() function main() { source "$(dirname "${BASH_SOURCE[0]}")/../../../libraries/util.bash" + source "$(dirname "${BASH_SOURCE[0]}")/../attributes/default.bash" header 'INSTALLING DELETE-OLD-LOGS' diff --git a/cookbooks/clean-up/files/delete-old-logs b/cookbooks/clean-up/templates/delete-old-logs.bash similarity index 98% rename from cookbooks/clean-up/files/delete-old-logs rename to cookbooks/clean-up/templates/delete-old-logs.bash index d1228afb..4b18c335 100644 --- a/cookbooks/clean-up/files/delete-old-logs +++ b/cookbooks/clean-up/templates/delete-old-logs.bash @@ -40,4 +40,4 @@ function main() done } -main "${@}" \ No newline at end of file +main __LOG_FOLDER_PATHS__ \ No newline at end of file diff --git a/libraries/util.bash b/libraries/util.bash index b69bfd43..c142f45e 100755 --- a/libraries/util.bash +++ b/libraries/util.bash @@ -4,6 +4,13 @@ # ARRAY UTILITIES # ################### +function arrayToParameters() +{ + local -r array=("${@}") + + printf "'%s' " "${array[@]}" +} + function arrayToString() { local -r array=("${@}")