--- /etc/init.d/fetchmail 2011-08-24 03:53:16.000000000 +0700 +++ /etc/init.d/fetchmail.new 2011-10-13 21:00:30.000000000 +0700 @@ -1,19 +1,52 @@ #!/sbin/runscript pidfile="/var/run/fetchmail/${RC_SVCNAME}.pid" -rcfile="/etc/${RC_SVCNAME}rc" fidfile="/var/lib/fetchmail/${RC_SVCNAME}.fetchids" +# Need to define this variable here to make it global instead of local +rcfile="" + depend() { need net use mta } checkconfig() { - if [ ! -f ${rcfile} ]; then - eerror "Configuration file ${rcfile} not found" - return 1 - fi + if [ -z "${fetchmail_config}" ]; then + # Config is not explicitly set in the relevant conf.d file + if [ -z "${fetchmail_rc}" ]; then + # User does not specify which file to use. Let's go find the right one + if [ -f /etc/${RC_SVCNAME}.rc ]; then + # Newer naming system + rcfile="/etc/${RC_SVCNAME}.rc" + elif [ -f /etc/${RC_SVCNAME}rc ]; then + # Older naming system + rcfile="/etc/${RC_SVCNAME}rc" + else + [ "x$1" != "xquiet" ] && eerror "Can't find any proper configuration for ${RC_SVCNAME}" + return 1 + fi + else + if [ -f ${fetchmail_rc} ]; then + rcfile="${fetchmail_rc}" + else + [ "x$1" != "xquiet" ] && eerror "Can't find ${fetchmail_rc} configuration file for ${RC_SVCNAME}" + return 1 + fi + fi + [ "x$1" != "xquiet" ] && einfo "Using configuration file: ${rcfile}" + else + [ "x$1" != "xquiet" ] && einfo "Using provided configuration in /etc/conf.d/${RC_SVCNAME}" + # Config is explicitly specified. Let's dump it into a file to be read back by fetchmail + # Why dumping it into a file instead of other methods (e.g., named pipe)? This allows + # troubleshooting. + rcfile="/var/run/fetchmail/${RC_SVCNAME}.rc" + echo "${fetchmail_config}" > $rcfile + fi + + # Ensure ownership and permissions to prevent fetchmail from complaining + chown fetchmail:root $rcfile + chmod 0700 $rcfile } start() { @@ -32,5 +65,13 @@ ebegin "Stopping ${RC_SVCNAME}" start-stop-daemon --stop --quiet --pidfile ${pidfile} eend ${?} + + # To assist troubleshooting (e.g., starting from shell using + # 'fetchmail -v -f $rcfile'), we do the courtesy of changing + # $rcfile's owner. + if checkconfig quiet ; then + chown root:root $rcfile + chmod 0700 $rcfile + fi }