From: Dustin Kirkland Date: Fri, 19 Sep 2008 20:57:03 +0000 (-0500) Subject: updated to version 1.2 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=714f2e54377ec2ce1e96e93b4569d33c49dbf88f;p=update-motd.git updated to version 1.2 --- diff --git a/debian/changelog b/debian/changelog index 3b9ab1b..36bee8c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,24 @@ +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 Mon, 15 Sep 2008 14:55:18 -0500 + update-motd (1.1) intrepid; urgency=low * debian/control: Description line was too long (LP: #260441). diff --git a/debian/config b/debian/config index 396b3dd..6396b7b 100644 --- a/debian/config +++ b/debian/config @@ -9,6 +9,7 @@ set -e # 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. diff --git a/debian/init.d b/debian/init.d index ab4e12f..49a1a8c 100755 --- a/debian/init.d +++ b/debian/init.d @@ -36,6 +36,7 @@ DAEMON=/usr/sbin/update-motd NAME=update-motd DESC="Update Message-of-the-Day" CRON=/etc/cron.d/$NAME +ENABLED=/var/run/$NAME.enabled test -x $DAEMON || exit 0 @@ -46,65 +47,58 @@ if [ -f /etc/default/$NAME ] ; then . /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 diff --git a/debian/postinst b/debian/postinst index 542d963..bd57b61 100644 --- a/debian/postinst +++ b/debian/postinst @@ -13,21 +13,26 @@ case "$1" in 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 ;; @@ -39,5 +44,3 @@ esac #DEBHELPER# exit 0 - - diff --git a/update-motd b/update-motd index 76f6596..ea22b30 100755 --- a/update-motd +++ b/update-motd @@ -27,10 +27,13 @@ # 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 @@ -39,6 +42,22 @@ if [ -f "$NEW" ]; then 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 diff --git a/update-motd.1 b/update-motd.1 index 9dc291e..90695be 100644 --- a/update-motd.1 +++ b/update-motd.1 @@ -6,15 +6,19 @@ update\-motd \- Automatically update the message-of-the-day (MOTD) .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" diff --git a/update-motd.cron b/update-motd.cron index f382664..4aedd14 100644 --- a/update-motd.cron +++ b/update-motd.cron @@ -1,13 +1,11 @@ # /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 diff --git a/update-motd.default b/update-motd.default index 934f770..3c703d6 100644 --- a/update-motd.default +++ b/update-motd.default @@ -11,7 +11,3 @@ # 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