+update-motd (1.2) intrepid; urgency=low
+
+ * debian/config: extract FREQ_IN_MIN from /etc/cron.d/update-motd
+ * debian/init.d:
+ - check that RUN=yes before starting, and that the cronjob exists
+ - ditto for the status action
+ - touch /var/run/update-motd.enabled if running
+ - use proper log_daemon_msg/log_end_msg for start/stop/refresh
+ * debian/postinst
+ - update the default file on RUN=yes|no
+ - create cronjob from template, using FREQ_IN_MIN debconf selection
+ * update-motd:
+ - check that update-motd is enabled (/var/run/update-motd.enabled)
+ - add argument handling and support for --force
+ * update-motd.1:
+ - added documentation about --force
+ - improved manpage formatting
+ * update-motd.default: remove FREQ_IN_MIN, as it's no longer set here
+
+ -- Dustin Kirkland <kirkland@ubuntu.com> Mon, 15 Sep 2008 14:55:18 -0500
+
update-motd (1.1) intrepid; urgency=low
* debian/control: Description line was too long (LP: #260441).
# Load config file, if it exists.
if [ -e $CONFIGFILE ]; then
. $CONFIGFILE || true
+ FREQ_IN_MIN=`grep "^\*\/" /etc/cron.d/update-motd 2>/dev/null| sed "s/^\*\///" | sed "s/\s.*//"`
# Store values from config file into
# debconf db.
NAME=update-motd
DESC="Update Message-of-the-Day"
CRON=/etc/cron.d/$NAME
+ENABLED=/var/run/$NAME.enabled
test -x $DAEMON || exit 0
. /etc/default/$NAME
fi
-# Use this if you want the user to explicitly set 'RUN' in /etc/default/
-if [ "$RUN" != "yes" ] ; then
- log_failure_msg "$NAME disabled, please adjust the configuration to your needs"
- log_failure_msg "and then set RUN='yes' in /etc/default/$NAME to enable it."
- exit 1
-fi
-
-# Default refresh frequency is every 10 minutes
-if [ "x$FREQ_IN_MIN" = "x" ]; then
- FREQ_IN_MIN="10"
-fi
-
set -e
case "$1" in
start)
- # Install update-motd cronjob
- touch "$CRON"
- chmod 755 "$CRON"
- sed "s/FREQ_IN_MIN/$FREQ_IN_MIN/" "/usr/share/$NAME/$NAME.cron" >"$CRON"
-
+ if [ "$RUN" != "yes" ]; then
+ log_warning_msg "$NAME is disabled (see /etc/default/$NAME)"
+ exit 0
+ fi
+ if [ ! -f "$CRON" ]; then
+ log_warning_msg "$NAME is missing its cron job"
+ exit 0
+ fi
+ log_daemon_msg "Starting $NAME"
# Run update-motd immediately
+ touch $ENABLED
$DAEMON && rc=0 || rc=$?
if [ "$rc" = 0 ]; then
- log_success_msg "Starting $NAME succeeded."
+ log_end_msg 0
else
- log_failure_msg "Starting $NAME failed."
+ log_end_msg 1
fi
exit "$rc"
;;
stop)
- rm -f "$CRON" && rc=0 || rc=$?
+ log_daemon_msg "Stopping $NAME"
+ rm -f "$ENABLED" && rc=0 || rc=$?
if [ "$rc" = "0" ]; then
- log_success_msg "Stopping $NAME succeeded."
+ log_end_msg 0
else
- log_failure_msg "Stopping $NAME failed."
+ log_end_msg 1
fi
exit "$rc"
;;
restart|reload|force-reload)
- # These will re-write the FREQ_IN_MIN to the cronjob
$0 stop
$0 start
exit "$?"
;;
refresh)
# Run /usr/bin/update-motd immediately
- $DAEMON && rc=0 || rc=$?
+ log_daemon_msg "Running $NAME"
+ $DAEMON && rc=0 || rc=$?
if [ "$rc" = "0" ]; then
- log_success_msg "Running $NAME succeeded."
+ log_end_msg 0
else
- log_failure_msg "Running $NAME failed."
+ log_end_msg 1
fi
exit "$rc"
;;
status)
- # Determine if cronjob exists
- ls $CRON >/dev/null 2>&1 && rc=0 || rc=$?
- if [ "$rc" = "0" ]; then
+ # Determine if cronjob and run file exist
+ if [ -f "$CRON" ] && [ -f "$ENABLED" ]; then
log_success_msg "$NAME is running."
exit 0
else
configure)
DEBIANCONFIG=/etc/default/$PACKAGE
- # load current settings, most of which will be overwritten.
+ # Update RUN=yes|no
[ -f $DEBIANCONFIG ] && . $DEBIANCONFIG
-
db_get $PACKAGE/enable
RUN="${RET:-true}"
- if [ $RUN = 'true' ]; then
- RUN='yes'
- fi
+ case $RUN in
+ "true"|"yes"|"1")
+ RUN='yes'
+ ;;
+ *)
+ RUN='no'
+ ;;
+ esac
+ sed -i "s/^\s*RUN=.*/RUN=$RUN/" $DEBIANCONFIG
+ # Update cronjob frequency
db_get $PACKAGE/freq-in-min
FREQ_IN_MIN="${RET:-10}"
-
- sed -i "s/^\s*RUN=.*/RUN=$RUN/" $DEBIANCONFIG
- sed -i "s/^\s*FREQ_IN_MIN=.*/FREQ_IN_MIN=$FREQ_IN_MIN/" $DEBIANCONFIG
+ CRONCONFIG=/etc/cron.d/$PACKAGE
+ sed "s/FREQ_IN_MIN/$FREQ_IN_MIN/" /usr/share/$PACKAGE/$PACKAGE.cron > $CRONCONFIG
db_stop
;;
#DEBHELPER#
exit 0
-
-
# Public License can be found in `/usr/share/common-licenses/GPL'.
###########################################################################
+NAME="update-motd"
NEW=/var/run/motd.new
SKEL=/etc/motd.tail
REAL=/var/run/motd
-DIR=/etc/update-motd.d
+DIR=/etc/$NAME.d
+ENABLED=/var/run/$NAME.enabled
+FORCE=0
if [ -f "$NEW" ]; then
# If /var/run/motd.new exists, then another instance of update-motd
exit 0
fi
+for arg in $@; do
+ case $arg in
+ "--force")
+ FORCE=1
+ ;;
+ esac
+done
+
+if [ ! -f "$ENABLED" ] && [ "$FORCE" != "1" ]; then
+ echo "$NAME is disabled. You can run:"
+ echo " * $NAME --force"
+ echo " * service update-motd start"
+ echo " * dpkg-reconfigure update-motd"
+ exit 1
+fi
+
# Make sure we clean up the motd.new lock file if we exit for any reason
trap "rm -f $NEW 2>/dev/null || true" EXIT HUP INT QUIT TERM
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-update\-motd
+update\-motd [\-\-force]
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
-This script executes each script in /etc/update-motd.d in lexical order, concatenating the status with /etc/motd.tail, and writing the output to /var/lib/motd.
+This script executes each script in \fI/etc/update-motd.d\fP in lexical order, concatenating the status with \fI/etc/motd.tail\fP, and writing the output to \fI/var/lib/motd\fP, which is usually a symbolic link to \fI/etc/motd\fP.
+
+Users and/or packages should add symlinks to \fI/etc/update-motd.d\fP, prepended with a two-digit number to define the execution order, as obeyed by \fBrun-parts(8)\fP.
+
+The update-motd script will only execute if the file \fI/var/run/update-motd.enabled\fP is present. One can override this using the \fB--force\fP option. To permanently enable/disable \fBupdate-motd\fP, use:
+ $ sudo dpkg-reconfigure update-motd
-Users and/or packages should add symlinks to /etc/update-motd.d, prepended with a two-digit number to define the execution order.
.SH FILES
-\fI/etc/update-motd.d/\fP, \fI/etc/motd.tail\fP, \fI/var/run/motd\fP
+\fI/etc/update-motd.d/\fP, \fI/etc/motd.tail\fP, \fI/var/run/motd\fP, \fI/var/run/update-motd.enabled\fP
.SH "AUTHOR"
.IX Header "AUTHOR"
# /etc/cron.d/update-motd: crontab fragment for update-motd
#
-# THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT DIRECTLY.
+# THIS FILE IS AUTOMATICALLY GENERATED, YOU SHOULD NOT EDIT DIRECTLY.
+#
# To change, use:
# dpkg-reconfigure update-motd
#
# This updates the /etc/motd with a concatenation of output from each
# script in /etc/update-motd.d
-#
-# This file is automatically generated by /etc/init.d/update-motd, which
-# uses /usr/share/update-motd/update-motd.cron as a template.
*/FREQ_IN_MIN * * * * root /usr/sbin/update-motd 2>/dev/null
# RUN:
# Should we actually run and update the MOTD?
RUN=yes
-
-# FREQ_IN_MIN:
-# How frequently should the update-motd script run, in minutes?
-FREQ_IN_MIN=10