Changeset 3606
- Timestamp:
- 05/04/08 19:59:47 (5 years ago)
- Location:
- pkg/viola/main/hibernate/trunk/debian
- Files:
-
- 2 edited
-
changelog (modified) (1 diff)
-
patches/80-log-permissions.dpatch (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
pkg/viola/main/hibernate/trunk/debian/changelog
r3448 r3606 1 hibernate (1.99-parsix1) unstable; urgency=low 2 3 * New upstream stable release 4 - refreshed 80-log-permissions 5 6 -- Alan Baghumian <alan@technotux.org> Sun, 04 May 2008 11:18:46 +0200 7 1 8 hibernate (1.98.1-parsix1) unstable; urgency=low 2 9 -
pkg/viola/main/hibernate/trunk/debian/patches/80-log-permissions.dpatch
r3448 r3606 25 25 # Redirect everything to a given VT if we've been given one 26 26 if [ -n "$SWSUSPVT" ] && [ -c /dev/tty$SWSUSPVT ] ; then 27 diff -urN hibernate-script-1.98.1/hibernate.sh.orig hibernate-script-1.98.1.new/hibernate.sh.orig28 --- hibernate-script-1.98.1/hibernate.sh.orig 1970-01-01 01:00:00.000000000 +010029 +++ hibernate-script-1.98.1.new/hibernate.sh.orig 2008-03-31 09:40:29.000000000 +020030 @@ -0,0 +1,918 @@31 +#!/bin/sh32 +# -*- sh -*-33 +# vim:ft=sh:ts=8:sw=4:noet34 +#35 +# Hibernate Script36 +# Copyright (C) 2004-2006 Bernard Blackham <bernard@blackham.com.au>37 +#38 +# The hibernate-script package is free software; you can redistribute it and/or39 +# modify it under the terms of the GNU General Public License as published by40 +# the Free Software Foundation; either version 2, or (at your option) any later41 +# version.42 +#43 +# This program is distributed in the hope that it will be useful, but WITHOUT44 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS45 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more46 +# details.47 +#48 +# You should have received a copy of the GNU General Public License along with49 +# this program. If not, write to the Free Software Foundation, Inc., 59 Temple50 +# Place - Suite 330, Boston, MA 02111-1307, USA.51 +#52 +53 +umask 07754 +55 +USING_ZSH=56 +USING_BASH=57 +NEED_POSIX=58 +59 +# For zsh sanity...60 +# allows splitting strings on whitespace in zsh.61 +setopt SH_WORD_SPLIT 2>/dev/null && USING_ZSH=1 || true62 +# allows sourced files to know they're sourced in zsh.63 +unsetopt FUNCTION_ARGZERO 2>/dev/null || true64 +65 +# Detect bash and tell it not to be POSIX, because we like it better that way.66 +shopt > /dev/null 2>&1 && USING_BASH=167 +[ -n "$USING_BASH" ] && set +o posix 2>/dev/null68 +69 +[ -z "$USING_BASH$USING_ZSH" ] && NEED_POSIX=170 +71 +# We prefer to use dash if we've got it.72 +if [ -z "$NEED_POSIX" ] && [ -z "$TRIED_DASH" ] &&73 + command -v dash > /dev/null 2>&1 ; then74 +75 + if [ "${0##*/}" = "$0" ] ; then76 + myself=`command -v $0` || myself=77 + elif [ -x "$0" ] ; then78 + myself=$079 + fi80 +81 + TRIED_DASH=182 + export TRIED_DASH83 + [ -n "$myself" ] && exec dash $myself $*84 +fi85 +unset TRIED_DASH86 +87 +SWSUSP_D="/etc/hibernate"88 +SCRIPTLET_PATH="$SWSUSP_D/scriptlets.d /usr/local/share/hibernate/scriptlets.d /usr/share/hibernate/scriptlets.d"89 +DEFAULT_CONFIG_FILE="$SWSUSP_D/hibernate.conf"90 +EXE="${0##*/}"91 +VERSION="1.98.1"92 +93 +# Add these to the $PATH just in case.94 +PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin"95 +export PATH96 +97 +# vecho N <echo params>: acts like echo but with verbosity control - If it's98 +# high enough to go to stdout, then it'll get logged as well. Else write it to99 +# the log file if it needs to. Otherwise, ignore it.100 +vecho() {101 + local v102 + v="$1"103 + shift104 + [ "x$LOG_TIMESTAMP" = "x1" ] && set -- $(date "+%b %e %H:%M:%S.%2N") "$@"105 + if [ "$v" -le $VERBOSITY ] ; then106 + echo $@107 + else108 + if [ "$v" -le $LOG_VERBOSITY -a "$LOGPIPE" != "cat" ] ; then109 + echo "$@" | $LOGPIPE > /dev/null110 + fi111 + fi112 +}113 +114 +# vcat N <cat params>: acts like cat but with verbosity control - If it's115 +# high enough to go to stdout, then it'll get logged as well. Else write it to116 +# the log file if it needs to. Otherwise, ignore it.117 +vcat() {118 + local v119 + v="$1"120 + shift121 + if [ "$v" -le $VERBOSITY ] ; then122 + cat "$@"123 + else124 + if [ "$v" -le $LOG_VERBOSITY -a "$LOGPIPE" != "cat" ] ; then125 + cat "$@" | $LOGPIPE > /dev/null126 + else127 + cat > /dev/null128 + fi129 + fi130 +}131 +132 +##############################################################################133 +### The following functions can be called safely from within scriptlets ######134 +##############################################################################135 +136 +# AddSuspendHook NN name: Adds a function to the suspend chain. NN must be a137 +# number between 00 and 99, inclusive. Smaller numbers get called earlier on138 +# suspend.139 +AddSuspendHook() {140 + SUSPEND_BITS="$1$2\\n$SUSPEND_BITS"141 +}142 +SUSPEND_BITS=""143 +144 +# AddResumeHook NN name: Adds a function to the resume chain. NN must be a number145 +# between 00 and 99, inclusive. Smaller numbers get called later on resume.146 +AddResumeHook() {147 + RESUME_BITS="$1$2\\n$RESUME_BITS"148 +}149 +RESUME_BITS=""150 +151 +# AddTerminationHandler <function name>: adds the given function to the chain of152 +# functions to handle termination cleanups.153 +AddTerminationHandler() {154 + TERMINATION_HANDLERS="$TERMINATIONS_HANDLERS $1"155 +}156 +TERMINATION_HANDLERS=""157 +158 +# AddConfigHandler <function name>: adds the given function to the chain of159 +# functions to handle extra configuration options.160 +AddConfigHandler() {161 + CONFIG_OPTION_HANDLERS="$CONFIG_OPTION_HANDLERS $1"162 +}163 +CONFIG_OPTION_HANDLERS=""164 +165 +# AddOptionHandler <function name>: adds the given function to the chain of166 +# functions to handle extra command line options. The scriptlet must also167 +# register the options with AddShortOption or AddLongOption168 +AddOptionHandler() {169 + CMDLINE_OPTION_HANDLERS="$CMDLINE_OPTION_HANDLERS $1"170 +}171 +CMDLINE_OPTION_HANDLERS=""172 +173 +# AddShortOption <option char>: adds the given option character to the174 +# list of possible short options. The option may be followed by : or ::175 +# (: for a mandatory parameter, :: for an optional parameter)176 +AddShortOption() {177 + EXTRA_SHORT_OPTS="$EXTRA_SHORT_OPTS$1"178 +}179 +EXTRA_SHORT_OPTS=""180 +181 +# AddLongOption <option char>: adds the given option character to the182 +# list of possible long options. The option may be followed by : or ::183 +# (: for a mandatory parameter, :: for an optional parameter)184 +AddLongOption() {185 + EXTRA_LONG_OPTS="$EXTRA_LONG_OPTS,$1"186 +}187 +EXTRA_LONG_OPTS=""188 +189 +# AddOptionHelp <option name> <option help>: Adds the given option name and190 +# help text to the help screen.191 +AddOptionHelp() {192 + [ -n "$DISABLE_HELP" ] && return193 + local ATEXT194 + local BIT195 + local WRAPPED_HELP196 + ATEXT=" $1"197 + [ -n "$CURRENT_SOURCED_SCRIPTLET" ] && ATEXT=`LeftRightPadText "$ATEXT" "[$CURRENT_SOURCED_SCRIPTLET]"`198 + WRAPPED_HELP="`echo \"$2\" | WrapHelpText`"199 + ATEXT="$ATEXT200 +$WRAPPED_HELP201 +202 +"203 + CMDLINE_OPTIONS_HELP="$CMDLINE_OPTIONS_HELP$ATEXT"204 +}205 +CMDLINE_OPTIONS_HELP=""206 +207 +# AddConfigHelp <item name> <item help>: Deprecated. We no longer write208 +# config help in --help209 +AddConfigHelp() {210 + return 0211 +}212 +213 +# FindXServer: Tries to find a running X server on the system. If one is found,214 +# will set DISPLAY, XAUTHORITY and the XUSER variable, and return 0.215 +# Otherwise, returns 1.216 +FindXServer() {217 + [ -n "$FIND_X_SERVER_RESULT" ] && return $FIND_X_SERVER_RESULT218 +219 + [ -z "$DISPLAY" ] && DISPLAY=:0220 + export DISPLAY221 +222 + # See if we need to authenticate to this X server.223 + PATH=$PATH:/usr/bin/X11:/usr/X11R6/bin224 + export PATH225 + xhost=`command -v xhost 2>/dev/null`226 + if [ $? -ne 0 ] ; then227 + vecho 0 "$EXE: Could not find xhost program. Disabling X scriptlets."228 + FIND_X_SERVER_RESULT=1229 + return 1230 + fi231 +232 + # Find a useful XAUTHORITY and ideally a username too if we can!233 + local xuser xauth xpid234 + for display in $(seq 0 8); do235 + xuser=$(last ":$display" | grep 'still logged in' | awk '{print $1}') || true236 + if [ -n "$xuser" ]; then237 + xhome=$(getent passwd "$xuser" | cut -d: -f 6)238 + if [ -n "$xhome" ]; then239 + xauth=$xhome/.Xauthority240 + fi241 + fi242 + if [ -z "$xhome" ] || [ -z "$xauth" ]; then243 + xauth=244 + xuser=245 + xhome=246 + else247 + break248 + fi249 + done250 + if [ -z $xuser ] ; then251 + for xpid in `pidof kwrapper ksmserver kdeinit gnome-session fvwm fvwm2 pwm blackbox fluxbox WindowMaker X XFree86 Xorg` ; do252 + # Ensure the process still exists, and we aren't hallucinating.253 + [ -d "/proc/$xpid/" ] || continue254 +255 + xauth="`get_env_var_of_process $xpid XAUTHORITY`"256 + xhome="`get_env_var_of_process $xpid HOME`"257 + xuser=`/bin/ls -ld /proc/$xpid/ | awk '{print $3}'`258 + [ -z $xauth ] && [ -n $xhome ] && [ -f $xhome/.Xauthority ] && xauth=$xhome/.Xauthority259 +260 + [ -z $xauth ] && continue261 +262 + XAUTHORITY=$xauth su $xuser -c "$xhost" > /dev/null 2>&1 && break263 +264 + xauth=265 + xuser=266 + done267 + fi268 + if [ -n $xuser ] ; then269 + XUSER=$xuser270 + if [ -n "$xauth" ] ; then271 + XAUTHORITY=$xauth272 + export XAUTHORITY273 + fi274 + else275 + FIND_X_SERVER_RESULT=1276 + vecho 0 "$EXE: Could not attach to X server on $DISPLAY. Disabling X scriptlets."277 + return 1278 + fi279 +280 + FIND_X_SERVER_RESULT=0281 + return 0282 +}283 +284 +# UsingSuspendMethod <method name>: is called when a suspend method is chosen.285 +# If a suspend method has already been chosen, the hibernate script will be286 +# terminated with an error.287 +UsingSuspendMethod() {288 + if [ -n "$HIBERNATE_SUSPEND_METHOD" ] ; then289 + vecho 0 "$EXE: More than one suspend method has been chosen."290 + vecho 0 "Please edit your config file so only one method is used."291 + exit 1292 + fi293 + HIBERNATE_SUSPEND_METHOD=$1294 + return 0295 +}296 +297 +##############################################################################298 +### Helper functions ###299 +##############################################################################300 +301 +# SortSuspendBits: Returns a list of functions registered in the correct order302 +# to call for suspending, prefixed by their position number in the suspend303 +# chain.304 +SortSuspendBits() {305 + # explicit path required to be ash compatible.306 + /bin/echo -ne "$SUSPEND_BITS" | sort -n307 +}308 +309 +# SortResumeBits: Returns a list of functions registered in the correct order310 +# to call for resuming, prefixed by their position number.311 +SortResumeBits() {312 + # explicit path required to be ash compatible.313 + /bin/echo -ne "$RESUME_BITS" | sort -rn314 +}315 +316 +# WrapHelpText: takes text from stdin, wraps it with an indent of 5 and width317 +# of 70, and writes to stdout.318 +WrapHelpText() {319 + awk '320 +BEGIN {321 + indent=5322 + width=70323 + ORS=""324 +}325 +{326 + if (substr($0, 1, 1) == " ")327 + for(a=1;a<length($0);a++) {328 + if (substr($0,a,1) != " ") break329 + print " "330 + }331 + curpos=0332 + for (i=1; i <= NF; i++) {333 + if ($i != "" && i == 1) {334 + for (j=0; j < indent; j++) { print " " }335 + }336 + if (curpos + length($i) > width) {337 + curpos=0338 + print "\n"339 + for (j=0; j < indent; j++) { print " " }340 + }341 + print $i " "342 + curpos = curpos + length($i) + 1343 + }344 + print "\n"345 +}346 +END {347 + print "\n"348 +}349 +'350 +}351 +352 +# LeftRightPadText <left> <right>": returns a string comprised of the two353 +# arguments with padding in between to make the string 78 characters long.354 +LeftRightPadText() {355 + (echo "$1" ; echo "$2") | awk '356 +BEGIN {357 + OFS=""; ORS="";358 + getline359 + print360 + a=78-length()361 + getline362 + for(a-=length(); a>=0; a--) {print " "}363 + print364 +}'365 +366 +}367 +368 +# PluginTermination <params>: queries all loaded scriptlets if they want to369 +# handle the given event. Returns 0 if the option was handled, 1 otherwise.370 +PluginTermination() {371 + local i372 + for i in $TERMINATION_HANDLERS ; do373 + $i $@ && return 0374 + done375 + return 1376 +}377 +378 +# PluginConfigOption <params>: queries all loaded scriptlets if they want to379 +# handle the given option. Returns 0 if the option was handled, 1 otherwise.380 +PluginConfigOption() {381 + local i382 + for i in $CONFIG_OPTION_HANDLERS ; do383 + $i $@ && return 0384 + done385 + return 1386 +}387 +388 +# EnsureHavePrerequisites: makes sure we have all the required utilities to run389 +# the script. It exits the script if we don't.390 +EnsureHavePrerequisites() {391 + local i392 + for i in awk grep sort getopt basename chvt ; do393 + if ! command -v $i > /dev/null; then394 + vecho 0 "Could not find required program \"$i\". Aborting."395 + exit 1396 + fi397 + done398 + # Improvise printf using awk if need be.399 + if ! command -v printf > /dev/null 2>&1 ; then400 + # This implementation fails on strings that contain double quotes.401 + # It does the job for the help screen at least.402 + printf() {403 + local AWK_FMT404 + local AWK_PARAMS405 + AWK_FMT="$1"406 + shift407 + AWK_PARAMS=""408 + for i in "$@" ; do409 + AWK_PARAMS="$AWK_PARAMS, \"$i\""410 + done411 + awk "BEGIN { printf ( \"$AWK_FMT\" $AWK_PARAMS ) }"412 + }413 + fi414 + # Improvise mktemp in case we need it too!415 + if ! command -v mktemp > /dev/null 2>&1 ; then416 + # Use a relatively safe equivalent of mktemp. Still suspectible to race417 + # conditions, but highly unlikely.418 + mktemp() {419 + local CNT420 + local D421 + local FN422 + local RND1423 + local RND2424 + CNT=1425 + if [ -z "$RANDOM" ] ; then426 + # A fix for shells that do not have this bash feature427 + RND1=$(dd if=/dev/urandom count=1 2>/dev/null|cksum|cut -c"1-5")428 + RND2=$(dd if=/dev/urandom count=1 2>/dev/null|cksum|cut -c"1-5")429 + else430 + RND1=$RANDOM431 + RND2=$RANDOM432 + fi433 + while true ; do434 + D=`date +%s`435 + FN=/tmp/tmp.hibernate.$$$D$RND1$RND2$CNT436 + [ -f $FN ] && continue437 + touch $FN && break438 + CNT=$(($CNT+1))439 + done440 + echo $FN441 + }442 + fi443 + return 0444 +}445 +446 +# Usage: dump the abridged usage options to stdout.447 +Usage() {448 + cat <<EOT449 +Usage: $EXE [options]450 +Activates software suspend and control its parameters.451 +452 +$CMDLINE_OPTIONS_HELP453 +For configuration file options for hibernate.conf, man hibernate.conf.454 +455 +Hibernate Script $VERSION (C) 2004-2006 Bernard Blackham456 +EOT457 + return458 +}459 +460 +# PluginGetOpt <params>: pass the given params to each scriplet in turn that461 +# requested parameters until one accepts them. Return 0 if a scriplet did462 +# accept them, and 1 otherwise.463 +PluginGetOpt() {464 + local opthandler465 + for opthandler in $CMDLINE_OPTION_HANDLERS ; do466 + $opthandler $* && return 0467 + done468 + return 1469 +}470 +471 +# DoGetOpt <getopt output>: consume getopt output and set options accordingly.472 +DoGetOpt() {473 + local opt474 + local optdata475 + while [ -n "$*" ] ; do476 + opt="$1"477 + shift478 + case $opt in479 + -F|--config-file)480 + # Dealt with previously481 + shift482 + ;;483 + -f|--force)484 + FORCE_ALL=1485 + ;;486 + -k|--kill)487 + KILL_PROGRAMS=1488 + ;;489 + --dry-run)490 + OPT_DRY_RUN=1491 + ;;492 + -v|--verbosity)493 + OPT_VERBOSITY="${1#\'}"494 + OPT_VERBOSITY="${OPT_VERBOSITY%\'}"495 + EnsureNumeric "verbosity" $OPT_VERBOSITY && VERBOSITY="$OPT_VERBOSITY"496 + shift497 + ;;498 + -q)499 + ;;500 + --)501 + ;;502 + *)503 + # Pass off to scriptlets See if there's a parameter given.504 + case $1 in505 + -*)506 + optdata=""507 + ;;508 + *)509 + optdata=${1#\'}510 + optdata=${optdata%\'}511 + shift512 + esac513 + if ! PluginGetOpt $opt $optdata ; then514 + echo "Unknown option $opt on command line!"515 + exit 1516 + fi517 + ;;518 + esac519 + done520 +}521 +522 +# ParseOptions <options>: process all the command-line options given523 +ParseOptions() {524 + local opts525 + opts="`getopt -n \"$EXE\" -o \"Vhfksv:nqF:$EXTRA_SHORT_OPTS\" -l \"help,force,kill,verbosity:,dry-run,config-file:,version$EXTRA_LONG_OPTS\" -- \"$@\"`" || exit 1526 + DoGetOpt $opts527 +}528 +529 +# CheckImplicitAlternateConfig <$0> : checks $0 to see if we should be530 +# implicitly using a different configuration file.531 +CheckImplicitAlternateConfig() {532 + # Don't find one if we've already been specified one.533 + [ -n "$CONFIG_FILE" ] && return 0534 +535 + local self536 + self="${0##*/}"537 + case $self in538 + hibernate-*)539 + CONFIG_FILE="$SWSUSP_D/${self#hibernate-}.conf"540 + vecho 3 "$EXE: Using implicit configuration file $CONFIG_FILE"541 + ;;542 + *)543 + CONFIG_FILE="${DEFAULT_CONFIG_FILE}"544 + ;;545 + esac546 + return 0547 +}548 +549 +# PreliminaryGetopt <options> : detects a few command-line options that need to550 +# be dealt with before scriptlets and before other command-line options.551 +PreliminaryGetopt() {552 + local opt553 + set -- `getopt -q -o hv:F: -l help,verbosity:,config-file:,version -- "$@"`554 + while [ -n "$*" ] ; do555 + opt="$1"556 + shift557 +558 + case $opt in559 + -h|--help) HELP_ONLY=1 ;;560 + -F|--config-file)561 + CONFIG_FILE="${1#\'}"562 + CONFIG_FILE="${CONFIG_FILE%\'}"563 + ;;564 + -v|--verbosity)565 + OPT_VERBOSITY="${1#\'}"566 + OPT_VERBOSITY="${OPT_VERBOSITY%\'}"567 + EnsureNumeric "verbosity" $OPT_VERBOSITY && VERBOSITY="$OPT_VERBOSITY"568 + shift569 + ;;570 + --version)571 + echo "Hibernate Script $VERSION"572 + exit 0573 + ;;574 + --) return 0 ;;575 + esac576 + done577 + return 0578 +}579 +580 +# LoadScriptlets: sources all scriptlets in $SCRIPTLET_PATH directories581 +LoadScriptlets() {582 + local prev_pwd583 + local scriptlet584 + local scriptlet_name585 + local scriptlet_dir586 + local prev_path587 + CURRENT_SOURCED_SCRIPTLET=""588 + for scriptlet_dir in $SCRIPTLET_PATH ; do589 + [ -d "$scriptlet_dir" ] || continue590 + [ -z "`/bin/ls -1 $scriptlet_dir`" ] && continue591 + for scriptlet in $scriptlet_dir/* ; do592 + # Avoid editor backup files.593 + case "$scriptlet" in *~|*.bak) continue ;; esac594 +595 + # Don't source a scriptlet by name more than once.596 + scriptlet_name="${scriptlet##*/}"597 +598 + eval "prev_path=\"\${HAVE_SOURCED_SCRIPTLET_$scriptlet_name}\""599 +600 + if [ -n "$prev_path" ] ; then601 + vecho 0 "$EXE: Scriptlet $scriptlet_name exists in both $scriptlet and $prev_path"602 + vecho 0 "$EXE: Cowardly refusing to load $scriptlet_name a second time."603 + continue604 + fi605 + eval "HAVE_SOURCED_SCRIPTLET_$scriptlet_name=$scriptlet"606 +607 + # And now source it!608 +609 + CURRENT_SOURCED_SCRIPTLET="$scriptlet_name"610 + . $scriptlet611 + done612 + done613 + if [ -z "$CURRENT_SOURCED_SCRIPTLET" ] ; then614 + echo "WARNING: No directories in scriptlet search path contained any scriptlets."615 + echo "Hence, this script probably won't do anything."616 + return 0617 + fi618 + CURRENT_SOURCED_SCRIPTLET=""619 +}620 +621 +# BoolIsOn <option> <value>: converts a "boolean" to either 1 or 0, and takes622 +# into account yes/no, on/off, 1/0, etc. If it is not valid, it will complain623 +# about the option and exit. Note, the *opposite* is actually returned, as true624 +# is considered 0 in shell world.625 +BoolIsOn() {626 + local val627 + val=`echo $2|tr '[A-Z]' '[a-z]'`628 + [ "$val" = "on" ] && return 0629 + [ "$val" = "off" ] && return 1630 + [ "$val" = "true" ] && return 0631 + [ "$val" = "false" ] && return 1632 + [ "$val" = "yes" ] && return 0633 + [ "$val" = "no" ] && return 1634 + [ "$val" = "1" ] && return 0635 + [ "$val" = "0" ] && return 1636 + echo "$EXE: Invalid boolean value ($2) for option $1 in configuration file"637 + exit 1638 +}639 +640 +IsANumber() {641 + case "$1" in *[!0-9]*|"") return 1 ;; esac642 + return 0643 +}644 +645 +EnsureNumeric() {646 + IsANumber "$2" && return 0647 + echo "$EXE: Invalid numeric value ($2) for option $1 in configuration file"648 + exit 1649 +}650 +651 +# ProcessConfigOption: takes a configuration option and its parameters and652 +# passes it out to the relevant scriptlet.653 +ProcessConfigOption() {654 + local option655 + local params656 + option=`echo $1|tr '[A-Z]' '[a-z]'`657 + shift658 + params="$@"659 + case $option in660 + alwaysforce)661 + [ -z "$FORCE_ALL" ] &&662 + BoolIsOn "$option" "$params" && FORCE_ALL=1663 + ;;664 + alwayskill)665 + [ -z "$KILL_PROGRAMS" ] &&666 + BoolIsOn "$option" "$params" && KILL_PROGRAMS=1667 + ;;668 + logfile)669 + [ -z "$LOGFILE" ] &&670 + LOGFILE="$params"671 + ;;672 + logtimestamp)673 + if BoolIsOn "$option" "$params" ; then674 + LOG_TIMESTAMP=1675 + else676 + LOG_TIMESTAMP=0677 + fi678 + ;;679 + logverbosity)680 + EnsureNumeric "$option" "$params" && LOG_VERBOSITY="$params"681 + ;;682 + swsuspvt|hibernatevt)683 + EnsureNumeric "$option" "$params" && SWSUSPVT="$params"684 + ;;685 + verbosity)686 + [ -z "$OPT_VERBOSITY" ] && EnsureNumeric "$option" "$params" &&687 + VERBOSITY="$params"688 + ;;689 + distribution)690 + [ -z "$DISTRIBUTION" ] && DISTRIBUTION=`echo $params | tr '[A-Z]' '[a-z]'`691 + ;;692 + xdisplay)693 + DISPLAY="$params"694 + export DISPLAY695 + ;;696 + include)697 + vecho 3 "$EXE: Including configuration from $params"698 + if ! ReadConfigFile "$params" ; then699 + echo "$EXE: Unable to read configuration file $params (from Include directive)."700 + exit 1701 + fi702 + ;;703 + trymethod)704 + if [ -z "$HIBERNATE_SUSPEND_METHOD" ] ; then705 + NO_COMPLAIN_UNSUPPORTED=1706 + vecho 1 "$EXE: Trying method in $1..."707 + if ! ReadConfigFile "$params" ; then708 + echo "$EXE: Unable to read configuration file $params (from TryMethod directive)."709 + fi710 + NO_COMPLAIN_UNSUPPORTED=711 + fi712 + ;;713 + *)714 + if ! PluginConfigOption $option $params ; then715 + # See if we're trying something new, and haven't yet got a suspend method716 + if [ -n "$NO_COMPLAIN_UNSUPPORTED" ] && [ -z "$HIBERNATE_SUSPEND_METHOD" ] ; then717 + return 1718 + else719 + echo "$EXE: Unknown configuration option ($option)"720 + exit 1721 + fi722 + fi723 + ;;724 + esac725 + return 0726 +}727 +728 +# ReadConfigFile: reads in a configuration file from stdin and sets the729 +# appropriate variables in the script. Returns 0 on success, exits on errors730 +conffiles_read=731 +ReadConfigFile() {732 + local option params733 + local file_name; file_name="$1"734 +735 + if [ ! -f "${file_name}" ] ; then736 + # Search in /etc/hibernate737 + if [ -f "$SWSUSP_D/$file_name" ] ; then738 + file_name="$SWSUSP_D/$file_name"739 + else740 + echo "WARNING: No configuration file found (${file_name})."741 + echo "This script probably won't do anything."742 + return 1743 + fi744 + fi745 +746 + if [ "${conffiles_read#*$file_name}" != "$conffiles_read" ]; then747 + vecho 2 "$EXE: Skipping already included config file $file_name"748 + return 0749 + fi750 +751 + while true ; do752 + # Doing the read this way allows means we don't require a new-line753 + # at the end of the file.754 + read option params755 + [ $? -ne 0 ] && [ -z "$option" ] && break756 + [ -z "$option" ] && continue757 + case $option in ""|\#*) continue ;; esac # avoids a function call (big speed hit)758 + ProcessConfigOption $option $params || break759 + done < ${file_name}760 + return 0761 +}762 +763 +# AddInbuiltHelp: Documents the above in-built options.764 +AddInbuiltHelp() {765 + AddOptionHelp "-h, --help" "Shows this help screen."766 + AddOptionHelp "--version" "Shows the Hibernate Script version."767 + AddOptionHelp "-f, --force" "Ignore errors and suspend anyway."768 + AddOptionHelp "-k, --kill" "Kill processes if needed, in order to suspend."769 + AddOptionHelp "-v<n>, --verbosity=<n>" "Change verbosity level (0 = errors only, 3 = verbose, 4 = debug)"770 + AddOptionHelp "-F<file>, --config-file=<file>" "Use the given configuration file instead of the default ($CONFIG_FILE)"771 + AddOptionHelp "--dry-run" "Don't actually do anything."772 +773 + AddConfigHelp "HibernateVT N" "If specified, output from the suspend script is redirected to the given VT instead of stdout."774 + AddConfigHelp "Verbosity N" "Determines how verbose the output from the suspend script should be:775 + 0: silent except for errors776 + 1: print steps777 + 2: print steps in detail778 + 3: print steps in lots of detail779 + 4: print out every command executed (uses -x)"780 + AddConfigHelp "LogFile <filename>" "If specified, output from the suspend script will also be redirected to this file - useful for debugging purposes."781 + AddConfigHelp "LogTimestamp <boolean>" "If logging to file, will place timestamps on each log entry. This is only recommended if you are trying to optimise suspend/resume time, otherwise it will just slow the process down."782 + AddConfigHelp "LogVerbosity N" "Same as Verbosity, but controls what is written to the logfile."783 + AddConfigHelp "AlwaysForce <boolean>" "If set to yes, the script will always run as if --force had been passed."784 + AddConfigHelp "AlwaysKill <boolean>" "If set to yes, the script will always run as if --kill had been passed."785 + AddConfigHelp "Distribution <debian|fedora|mandrake|redhat|gentoo|suse|slackware>" "If specified, tweaks some scriptlets to be more integrated with the given distribution."786 + AddConfigHelp "Include <filename>" "Immediately include configuration directives from the given file."787 + AddConfigHelp "XDisplay <display location>" "Specifies where scriptlets that use the X server should find one. (Default: :0)"788 +}789 +790 +EnsureHaveRoot() {791 + if [ x"`id -u`" != "x0" ] ; then792 + echo "$EXE: You need to run this script as root."793 + exit 1794 + fi795 + return 0796 +}797 +798 +# DoWork: Does the actual calling of scriptlet functions. We wrap this to make799 +# it easy to decide whether or not to pipe its output to $LOGPIPE or not.800 +DoWork() {801 + # Trap Ctrl+C802 + trap ctrlc_handler INT HUP803 +804 + # Do everything we need to do to suspend. If anything fails, we don't805 + # suspend. Suspend itself should be the last one in the sequence.806 +807 + local ret808 + local CHAIN_UP_TO809 + local bit810 +811 + CHAIN_UP_TO=0812 + for bit in `SortSuspendBits` ; do813 + local new_CHAIN_UP_TO814 + new_CHAIN_UP_TO="`awk \"BEGIN{print substr(\\\"$bit\\\", 1, 2)}\"`" || break815 + [ -n "$new_CHAIN_UP_TO" ] && CHAIN_UP_TO=$new_CHAIN_UP_TO || continue816 + bit=${bit##$CHAIN_UP_TO}817 + vecho 1 "$EXE: [$CHAIN_UP_TO] Executing $bit ... "818 + [ -n "$OPT_DRY_RUN" ] && continue819 + $bit820 + ret="$?"821 + # A return value >= 2 denotes we can't go any further, even with --force.822 + if [ $ret -ge 2 ] ; then823 + # If the return value is 3 or higher, be silent.824 + if [ $ret -eq 2 ] ; then825 + vecho 1 "$EXE: $bit refuses to let us continue."826 + vecho 0 "$EXE: Aborting."827 + EXIT_CODE=2828 + fi829 + break830 + fi831 + # A return value of 1 means we can't go any further unless --force is used832 + if [ $ret -gt 0 ] && [ x"$FORCE_ALL" != "x1" ] ; then833 + vecho 0 "$EXE: Aborting suspend due to errors in $bit (use --force to override)."834 + EXIT_CODE=2835 + break836 + fi837 + if [ -n "$SUSPEND_ABORT" ] ; then838 + vecho 0 "$EXE: Suspend aborted by user."839 + EXIT_CODE=3840 + break841 + fi842 + done843 +844 + # Resume and cleanup and stuff.845 + for bit in `SortResumeBits` ; do846 + THIS_POS="`awk \"BEGIN{print substr(\\\"$bit\\\", 1, 2)}\"`"847 + [ -z "$THIS_POS" ] && continue848 + bit=${bit##$THIS_POS}849 + [ "$THIS_POS" -gt "$CHAIN_UP_TO" ] && continue850 + vecho 1 "$EXE: [$THIS_POS] Executing $bit ... "851 + [ -n "$OPT_DRY_RUN" ] && continue852 + $bit853 + done854 + return $EXIT_CODE855 +}856 +857 +ctrlc_handler() {858 + SUSPEND_ABORT=1859 +}860 +861 +# Gets the value of the environment variable in the environment space of the862 +# processes identified by its PID.863 +get_env_var_of_process()864 +{865 + local pid; pid="$1"866 + local envvar; envvar="$2"867 + tr '\0' '\n' </proc/$pid/environ | sed -ne "s/^$envvar=//p"868 +}869 +870 +############################### MAIN #########################################871 +872 +# Some starting values:873 +VERBOSITY=0874 +LOG_VERBOSITY=1875 +LOGPIPE="cat"876 +ERROR_TEXT=""877 +878 +EnsureHavePrerequisites879 +880 +# Test for options that will affect future choices881 +PreliminaryGetopt "$@"882 +883 +CheckImplicitAlternateConfig $0884 +885 +# Generating help text is slow. Avoid it if we can.886 +if [ -n "$HELP_ONLY" ] ; then887 + AddInbuiltHelp888 + LoadScriptlets889 + Usage890 + exit 0891 +fi892 +DISABLE_HELP=1893 +894 +EnsureHaveRoot895 +LoadScriptlets896 +ReadConfigFile "${CONFIG_FILE}"897 +# Verify we actually got a suspend method we could use.898 +if [ -z "$HIBERNATE_SUSPEND_METHOD" ] ; then899 + echo "$EXE: No suitable suspend methods were found on your machine."900 + echo "$EXE: You need to install a kernel with support for suspending to"901 + echo "$EXE: disk or RAM and reboot, then try again."902 + exit 1903 +fi904 +ParseOptions "$@"905 +906 +# Set a logfile if we need one.907 +[ -n "$LOGFILE" ] && LOGPIPE="tee -a -i $LOGFILE"908 +909 +# Redirect everything to a given VT if we've been given one910 +if [ -n "$SWSUSPVT" ] && [ -c /dev/tty$SWSUSPVT ] ; then911 + exec >/dev/tty$SWSUSPVT 2>&1912 +fi913 +914 +# Use -x if we're being really verbose!915 +[ $VERBOSITY -ge 4 ] && set -x916 +917 +echo "Starting suspend at "`date` | $LOGPIPE > /dev/null918 +919 +EXIT_CODE=0920 +921 +if [ "$LOGPIPE" = "cat" ] ; then922 + DoWork923 +else924 + # Sigh. Our portable way to obtain exit codes has issues in bash, so if925 + # we're using bash, we do it the not-so-portable way :)926 + if [ -n "$USING_BASH" ] ; then927 + DoWork | $LOGPIPE928 + eval 'EXIT_CODE=${PIPESTATUS[0]}'929 + else930 + # Evilness required to pass the exit code back to us in a pipe.931 + trap "" INT932 + exec 3>&1933 + eval `934 + exec 4>&1 >&3 3>&-935 + {936 + DoWork 4>&-937 + echo "EXIT_CODE=$EXIT_CODE" >&4938 + } | $LOGPIPE`939 + fi940 +fi941 +942 +PluginTermination943 +944 +echo "Resumed at "`date` | $LOGPIPE > /dev/null945 +946 +exit $EXIT_CODE947 +948 +# $Id$949 27 diff -urN hibernate-script-1.98.1/logrotate.d-hibernate-script hibernate-script-1.98.1.new/logrotate.d-hibernate-script 950 28 --- hibernate-script-1.98.1/logrotate.d-hibernate-script 2008-03-31 09:40:29.000000000 +0200
Note: See TracChangeset
for help on using the changeset viewer.


