From 6fd7e0311cd14a24c8b600268b944a53ab65ff8e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 27 Jan 2017 14:16:24 +0100 Subject: [PATCH 1/2] Install customized version of logrotate script --- advanced/Scripts/piholeLogFlush.sh | 2 +- advanced/pihole.cron | 2 +- automated install/basic-install.sh | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 64833b64..d8f4fd79 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -13,7 +13,7 @@ echo -n "::: Flushing /var/log/pihole.log ..." # Test if logrotate is available on this system if command -v /usr/sbin/logrotate &> /dev/null; then - /usr/sbin/logrotate --force /etc/.pihole/advanced/logrotate + /usr/sbin/logrotate --force /etc/pihole/logrotate else echo " " > /var/log/pihole.log fi diff --git a/advanced/pihole.cron b/advanced/pihole.cron index e8bc7ba9..854a9459 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -26,4 +26,4 @@ # The flush script will use logrotate if available 00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush -@reboot root /usr/sbin/logrotate /etc/.pihole/advanced/logrotate +@reboot root /usr/sbin/logrotate /etc/pihole/logrotate diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ef5c82c6..85bcd40a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -934,6 +934,18 @@ finalExports() { fi } +installLogrotate() { + # Install the logrotate script + echo ":::" + echo -n "::: Installing latest logrotate script..." + cp /etc/.pihole/advanced/logrotate /etc/pihole/logrotate + # Raspbian will use the default "su root root" + # Ubuntu will use a custom user/group "su root syslog" + # We read the global config file and copy what we find into our file + echo $(sed '/^su/!d' /etc/logrotate.conf) >> /etc/pihole/logrotate + echo " done!" +} + installPihole() { # Install base files and web interface create_pihole_user @@ -953,6 +965,7 @@ installPihole() { CreateLogFile installPiholeWeb installCron + installLogrotate configureFirewall finalExports runGravity @@ -983,6 +996,7 @@ updatePihole() { CreateLogFile installPiholeWeb installCron + installLogrotate finalExports #re-export setupVars.conf to account for any new vars added in new versions runGravity } From 2c16a75ef16087a071441153a45e5cb1db29e515 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 27 Jan 2017 14:28:59 +0100 Subject: [PATCH 2/2] Use stat to get owner of /var/log --- automated install/basic-install.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 85bcd40a..a98eb3aa 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -939,10 +939,16 @@ installLogrotate() { echo ":::" echo -n "::: Installing latest logrotate script..." cp /etc/.pihole/advanced/logrotate /etc/pihole/logrotate - # Raspbian will use the default "su root root" - # Ubuntu will use a custom user/group "su root syslog" - # We read the global config file and copy what we find into our file - echo $(sed '/^su/!d' /etc/logrotate.conf) >> /etc/pihole/logrotate + # Different operating systems have different user / group + # settings for logrotate that makes it impossible to create + # a static logrotate file that will work with e.g. + # Rasbian and Ubuntu at the same time. Hence, we have to + # customize the logrotate script here in order to reflect + # the local properties of the /var/log directory + logusergroup="$(stat -c '%U %G' /var/log)" + if [[ ! -z $logusergroup ]]; then + echo "su ${logusergroup}" >> /etc/pihole/logrotate + fi echo " done!" }