Author: branden Date: 2003-09-10 05:28:42 -0500 (Wed, 10 Sep 2003) New Revision: 494
Modified: trunk/debian/changelog trunk/debian/shell-lib.sh Log: debian/shell-lib.sh: various enhancements; - Use special abnormal exit codes so that problems with this library are more easily tracked down. - Abort if the variables $THIS_PACKAGE or $THIS_SCRIPT are not defined, so that we can do better error reporting. - errormsg(): report package and script name in error messages - internal_errormsg(): report package name, script name, and package version in error message; also, tell people about reportbug - usage_errormsg(): new; basically a version of internal_errormsg() that doesn't care if the package was an unofficial build or not - find_culprits(): exit with status $SHELL_LIB_THROWN_ERROR instead of 1 when packages obstructing an upgrade are found - remove_conffile_prepare(), remove_conffile_commit(), remove_conffile_rollback(): new functions to handle the obsoletion of conffiles across upgrades Modified: trunk/debian/changelog =================================================================== --- trunk/debian/changelog 2003-09-10 09:24:39 UTC (rev 493) +++ trunk/debian/changelog 2003-09-10 10:28:42 UTC (rev 494) @@ -44,8 +44,24 @@ package prior to 4.0.3 and that alternative is actually registered (see bug #164021 for a similar issue with another package) - -- Branden Robinson <[EMAIL PROTECTED]> Wed, 10 Sep 2003 04:23:00 -0500 + * debian/shell-lib.sh: various enhancements; + - Use special abnormal exit codes so that problems with this library are + more easily tracked down. + - Abort if the variables $THIS_PACKAGE or $THIS_SCRIPT are not defined, so + that we can do better error reporting. + - errormsg(): report package and script name in error messages + - internal_errormsg(): report package name, script name, and package + version in error message; also, tell people about reportbug + - usage_errormsg(): new; basically a version of internal_errormsg() that + doesn't care if the package was an unofficial build or not + - find_culprits(): exit with status $SHELL_LIB_THROWN_ERROR instead of 1 + when packages obstructing an upgrade are found + - remove_conffile_prepare(), remove_conffile_commit(), + remove_conffile_rollback(): new functions to handle the obsoletion of + conffiles across upgrades + -- Branden Robinson <[EMAIL PROTECTED]> Wed, 10 Sep 2003 05:22:22 -0500 + xfree86 (4.2.1-11) unstable; urgency=medium * urgency set to medium because bug #206790 bites a lot of people (but, Modified: trunk/debian/shell-lib.sh =================================================================== --- trunk/debian/shell-lib.sh 2003-09-10 09:24:39 UTC (rev 493) +++ trunk/debian/shell-lib.sh 2003-09-10 10:28:42 UTC (rev 494) @@ -3,6 +3,39 @@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ +# Use special abnormal exit codes so that problems with this library are more +# easily tracked down. +SHELL_LIB_INTERNAL_ERROR=86 +SHELL_LIB_THROWN_ERROR=74 +SHELL_LIB_USAGE_ERROR=99 + +# initial sanity checks +if [ -z "$THIS_PACKAGE" ]; then + cat >&2 <<EOF +Error: package maintainer script attempted to use shell library without +definining \$THIS_PACKAGE shell variable. Please report the package name, +version, and the text of this error message to the Debian Bug Tracking System. +Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for +instructions, read the file /usr/share/doc/debian/bug-reporting.txt (from the +doc-debian package, or install the "reportbug" package and use the command of +the same name to file a report. +EOF + exit $SHELL_LIB_USAGE_ERROR +fi + +if [ -z "$THIS_SCRIPT" ]; then + cat >&2 <<EOF +Error: package maintainer script attempted to use shell library without +definining \$THIS_SCRIPT shell variable. Please report the package name, +version, and the text of this error message to the Debian Bug Tracking System. +Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for +instructions, read the file /usr/share/doc/debian/bug-reporting.txt (from the +doc-debian package, or install the "reportbug" package and use the command of +the same name to file a report. +EOF + exit $SHELL_LIB_USAGE_ERROR +fi + trap "message;\ message \"Received signal. Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\ message;\ @@ -20,24 +53,41 @@ errormsg () { # exit script with error - message "$*" - exit 1; + message "$THIS_PACKAGE $THIS_SCRIPT error: $*" + exit $SHELL_LIB_THROWN_ERROR } internal_errormsg() { # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message message "$*" if [ -n "$OFFICIAL_BUILD" ]; then - message "Please report the package name, version, and the text of the" \ - "above error message(s) to the Debian Bug Tracking System. " \ - "Visit <http://www.debian.org/Bugs/Reporting> on the World Wide" \ - "Web for instructions, or read the file" \ + message "Please report a bug in the $THIS_SCRIPT script of the" \ + "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \ + "Tracking System. Include all messages above that mention the" \ + "$THIS_PACKAGE package. Visit " \ + "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \ + "instructions, read the file" \ "/usr/share/doc/debian/bug-reporting.txt (from the doc-debian" \ - "package." + "package, or install the reportbug package and use the command of" \ + "the same name to file a report." \ fi - exit 1; + exit $SHELL_LIB_INTERNAL_ERROR } +usage_errormsg() { + message "$*" + message "Please report a bug in the $THIS_SCRIPT script of the" \ + "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \ + "Tracking System. Include all messages above that mention the" \ + "$THIS_PACKAGE package. Visit " \ + "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \ + "instructions, read the file" \ + "/usr/share/doc/debian/bug-reporting.txt (from the doc-debian" \ + "package, or install the reportbug package and use the command of" \ + "the same name to file a report." \ + exit $SHELL_LIB_USAGE_ERROR +} + maplink () { # returns what symlink should point to; i.e., what the "sane" answer is # Keep this in sync with the debian/*.links files. @@ -189,7 +239,7 @@ if [ -n "$PROBLEM" ]; then analyze_path $SYMLINK $(readlink $SYMLINK) find_culprits $SYMLINK - exit 1 + exit $SHELL_LIB_THROWN_ERROR fi done else @@ -231,3 +281,97 @@ done done; } + +remove_conffile_prepare () { + # syntax: remove_conffile_prepare filename official_md5sum ... + # + # Check a conffile "filename" against a list of canonical MD5 checksums. + # If the file's current MD5 checksum matches one of the "official_md5sum" + # operands provided, then prepare the conffile for removal from the system. + # We defer actual deletion until the package is configured so that we can + # roll this operation back if package installation fails. + # + # Call this function from a preinst script in the event $1 is "upgrade" or + # "install" and verify $2 to ensure the package is being upgraded from a + # version (or installed over a version removed-but-not-purged) prior to the + # one in which the conffile was obsoleted. + + local conffile current_checksum + + # validate arguments + if [ $# -lt 2 ]; then + usage_errormsg "remove_conffile_prepare() called with wrong number of" \ + "arguments; expected at least 2, got $#" + exit $SHELL_LIB_USAGE_ERROR + fi + + conffile="$1" + shift + + # does the conffile even exist? + if [ -e "$conffile" ]; then + # calculate its checksum + current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//') + # compare it to each supplied checksum + while [ -n "$1" ]; do + if [ "$current_checksum" = "$1" ]; then + # we found a match; move the confffile and stop looking + mv "$conffile" "$conffile.$THIS_PACKAGE-tmp" + break + fi + shift + done + fi +} + +remove_conffile_commit () { + # syntax: remove_conffile_commit filename + # + # Complete the removal of a conffile "filename" that has become obsolete. + # + # Call this function from a postinst script after having used + # remove_conffile_prepare() in the preinst. + + local conffile + + # validate arguments + if [ $# -ne 1 ]; then + usage_errormsg "remove_conffile_commit() called with wrong number of" \ + "arguments; expected 1, got $#" + exit $SHELL_LIB_USAGE_ERROR + fi + + conffile="$1" + + # if the temporary file created by remove_conffile_prepare() exists, remove it + if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then + rm "$conffile.$THIS_PACKAGE-tmp" + fi +} + +remove_conffile_rollback () { + # syntax: remove_conffile_rollback filename + # + # Roll back the removal of a conffile "filename". + # + # Call this function from a postrm script in the event $1 is "abort-upgrade" + # or "abort-install" is after having used remove_conffile_prepare() in the + # preinst. + + local conffile + + # validate arguments + if [ $# -ne 1 ]; then + usage_errormsg "remove_conffile_commit() called with wrong number of" \ + "arguments; expected 1, got $#" + exit $SHELL_LIB_USAGE_ERROR + fi + + conffile="$1" + + # if the temporary file created by remove_conffile_prepare() exists, move it + # back + if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then + mv "$conffile.$THIS_PACKAGE-tmp" "$conffile" + fi +} -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]