Changeset 3606


Ignore:
Timestamp:
05/04/08 19:59:47 (6 years ago)
Author:
alanbach-guest
Message:
  • New upstream stable release
    • refreshed 80-log-permissions
Location:
pkg/viola/main/hibernate/trunk/debian
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pkg/viola/main/hibernate/trunk/debian/changelog

    r3448 r3606  
     1hibernate (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 
    18hibernate (1.98.1-parsix1) unstable; urgency=low 
    29 
  • pkg/viola/main/hibernate/trunk/debian/patches/80-log-permissions.dpatch

    r3448 r3606  
    2525 # Redirect everything to a given VT if we've been given one 
    2626 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.orig 
    28 --- hibernate-script-1.98.1/hibernate.sh.orig   1970-01-01 01:00:00.000000000 +0100 
    29 +++ hibernate-script-1.98.1.new/hibernate.sh.orig       2008-03-31 09:40:29.000000000 +0200 
    30 @@ -0,0 +1,918 @@ 
    31 +#!/bin/sh 
    32 +# -*- sh -*- 
    33 +# vim:ft=sh:ts=8:sw=4:noet 
    34 +# 
    35 +# Hibernate Script 
    36 +# Copyright (C) 2004-2006 Bernard Blackham <bernard@blackham.com.au> 
    37 +# 
    38 +# The hibernate-script package is free software; you can redistribute it and/or 
    39 +# modify it under the terms of the GNU General Public License as published by 
    40 +# the Free Software Foundation; either version 2, or (at your option) any later 
    41 +# version. 
    42 +# 
    43 +# This program is distributed in the hope that it will be useful, but WITHOUT 
    44 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    45 +# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
    46 +# details. 
    47 +# 
    48 +# You should have received a copy of the GNU General Public License along with 
    49 +# this program.  If not, write to the Free Software Foundation, Inc., 59 Temple 
    50 +# Place - Suite 330, Boston, MA 02111-1307, USA. 
    51 +# 
    52 + 
    53 +umask 077 
    54 + 
    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 || true 
    62 +#   allows sourced files to know they're sourced in zsh. 
    63 +unsetopt FUNCTION_ARGZERO 2>/dev/null || true 
    64 + 
    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=1 
    67 +[ -n "$USING_BASH" ] && set +o posix 2>/dev/null 
    68 + 
    69 +[ -z "$USING_BASH$USING_ZSH" ] && NEED_POSIX=1 
    70 + 
    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 ; then 
    74 + 
    75 +    if [ "${0##*/}" = "$0" ] ; then 
    76 +       myself=`command -v $0` || myself= 
    77 +    elif [ -x "$0" ] ; then 
    78 +       myself=$0 
    79 +    fi 
    80 + 
    81 +    TRIED_DASH=1 
    82 +    export TRIED_DASH 
    83 +    [ -n "$myself" ] && exec dash $myself $* 
    84 +fi 
    85 +unset TRIED_DASH 
    86 + 
    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 PATH 
    96 + 
    97 +# vecho N <echo params>: acts like echo but with verbosity control - If it's 
    98 +# high enough to go to stdout, then it'll get logged as well.  Else write it to 
    99 +# the log file if it needs to. Otherwise, ignore it. 
    100 +vecho() { 
    101 +    local v 
    102 +    v="$1" 
    103 +    shift 
    104 +    [ "x$LOG_TIMESTAMP" = "x1" ] && set -- $(date "+%b %e %H:%M:%S.%2N") "$@" 
    105 +    if [ "$v" -le $VERBOSITY ] ; then 
    106 +       echo $@ 
    107 +    else 
    108 +       if [ "$v" -le $LOG_VERBOSITY -a "$LOGPIPE" != "cat" ] ; then 
    109 +           echo "$@" | $LOGPIPE > /dev/null 
    110 +       fi 
    111 +    fi 
    112 +} 
    113 + 
    114 +# vcat N <cat params>: acts like cat but with verbosity control - If it's 
    115 +# high enough to go to stdout, then it'll get logged as well.  Else write it to 
    116 +# the log file if it needs to. Otherwise, ignore it. 
    117 +vcat() { 
    118 +    local v 
    119 +    v="$1" 
    120 +    shift 
    121 +    if [ "$v" -le $VERBOSITY ] ; then 
    122 +       cat "$@" 
    123 +    else 
    124 +       if [ "$v" -le $LOG_VERBOSITY -a "$LOGPIPE" != "cat" ] ; then 
    125 +           cat "$@" | $LOGPIPE > /dev/null 
    126 +       else 
    127 +           cat > /dev/null 
    128 +       fi 
    129 +    fi 
    130 +} 
    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 a 
    137 +# number between 00 and 99, inclusive. Smaller numbers get called earlier on 
    138 +# 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 number 
    145 +# 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 of 
    152 +# 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 of 
    159 +# 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 of 
    166 +# functions to handle extra command line options. The scriptlet must also 
    167 +# register the options with AddShortOption or AddLongOption 
    168 +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 the 
    174 +# 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 the 
    182 +# 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 and 
    190 +# help text to the help screen. 
    191 +AddOptionHelp() { 
    192 +    [ -n "$DISABLE_HELP" ] && return 
    193 +    local ATEXT 
    194 +    local BIT 
    195 +    local WRAPPED_HELP 
    196 +    ATEXT="  $1" 
    197 +    [ -n "$CURRENT_SOURCED_SCRIPTLET" ] && ATEXT=`LeftRightPadText "$ATEXT" "[$CURRENT_SOURCED_SCRIPTLET]"` 
    198 +    WRAPPED_HELP="`echo \"$2\" | WrapHelpText`" 
    199 +    ATEXT="$ATEXT 
    200 +$WRAPPED_HELP 
    201 + 
    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 write 
    208 +# config help in --help 
    209 +AddConfigHelp() { 
    210 +    return 0 
    211 +} 
    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_RESULT 
    218 + 
    219 +    [ -z "$DISPLAY" ] && DISPLAY=:0 
    220 +    export DISPLAY 
    221 + 
    222 +    # See if we need to authenticate to this X server. 
    223 +    PATH=$PATH:/usr/bin/X11:/usr/X11R6/bin 
    224 +    export PATH 
    225 +    xhost=`command -v xhost 2>/dev/null` 
    226 +    if [ $? -ne 0 ] ; then 
    227 +       vecho 0 "$EXE: Could not find xhost program. Disabling X scriptlets." 
    228 +       FIND_X_SERVER_RESULT=1 
    229 +       return 1 
    230 +    fi 
    231 + 
    232 +    # Find a useful XAUTHORITY and ideally a username too if we can! 
    233 +    local xuser xauth xpid 
    234 +    for display in $(seq 0 8); do 
    235 +       xuser=$(last ":$display" | grep 'still logged in' | awk '{print $1}') || true 
    236 +       if [ -n "$xuser" ]; then 
    237 +           xhome=$(getent passwd "$xuser" | cut -d: -f 6) 
    238 +           if [ -n "$xhome" ]; then 
    239 +               xauth=$xhome/.Xauthority 
    240 +           fi 
    241 +       fi 
    242 +       if [ -z "$xhome" ] || [ -z "$xauth" ]; then 
    243 +           xauth= 
    244 +           xuser= 
    245 +           xhome= 
    246 +       else  
    247 +           break 
    248 +       fi 
    249 +    done 
    250 +    if [ -z $xuser ] ; then 
    251 +        for xpid in `pidof kwrapper ksmserver kdeinit gnome-session fvwm fvwm2 pwm blackbox fluxbox WindowMaker X XFree86 Xorg` ; do 
    252 +           # Ensure the process still exists, and we aren't hallucinating. 
    253 +           [ -d "/proc/$xpid/" ] || continue 
    254 + 
    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/.Xauthority 
    259 + 
    260 +           [ -z $xauth ] && continue 
    261 + 
    262 +           XAUTHORITY=$xauth su $xuser -c "$xhost" > /dev/null 2>&1 && break 
    263 + 
    264 +          xauth= 
    265 +          xuser= 
    266 +       done 
    267 +    fi 
    268 +    if [ -n $xuser ] ; then 
    269 +       XUSER=$xuser 
    270 +       if [ -n "$xauth" ] ; then 
    271 +           XAUTHORITY=$xauth 
    272 +           export XAUTHORITY 
    273 +       fi 
    274 +    else 
    275 +       FIND_X_SERVER_RESULT=1 
    276 +       vecho 0 "$EXE: Could not attach to X server on $DISPLAY. Disabling X scriptlets." 
    277 +       return 1 
    278 +    fi 
    279 + 
    280 +    FIND_X_SERVER_RESULT=0 
    281 +    return 0 
    282 +} 
    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 be 
    286 +# terminated with an error. 
    287 +UsingSuspendMethod() { 
    288 +    if [ -n "$HIBERNATE_SUSPEND_METHOD" ] ; then 
    289 +       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 1 
    292 +    fi 
    293 +    HIBERNATE_SUSPEND_METHOD=$1 
    294 +    return 0 
    295 +} 
    296 + 
    297 +############################################################################## 
    298 +### Helper functions                                                       ### 
    299 +############################################################################## 
    300 + 
    301 +# SortSuspendBits: Returns a list of functions registered in the correct order 
    302 +# to call for suspending, prefixed by their position number in the suspend 
    303 +# chain. 
    304 +SortSuspendBits() { 
    305 +    # explicit path required to be ash compatible. 
    306 +    /bin/echo -ne "$SUSPEND_BITS" | sort -n 
    307 +} 
    308 + 
    309 +# SortResumeBits: Returns a list of functions registered in the correct order 
    310 +# 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 -rn 
    314 +} 
    315 + 
    316 +# WrapHelpText: takes text from stdin, wraps it with an indent of 5 and width 
    317 +# of 70, and writes to stdout. 
    318 +WrapHelpText() { 
    319 +    awk ' 
    320 +BEGIN { 
    321 +    indent=5 
    322 +    width=70 
    323 +    ORS="" 
    324 +} 
    325 +{ 
    326 +    if (substr($0, 1, 1) == " ") 
    327 +       for(a=1;a<length($0);a++) { 
    328 +           if (substr($0,a,1) != " ") break 
    329 +           print " " 
    330 +       } 
    331 +    curpos=0 
    332 +    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=0 
    338 +           print "\n" 
    339 +           for (j=0; j < indent; j++) { print " " } 
    340 +       } 
    341 +       print $i " " 
    342 +       curpos = curpos + length($i) + 1 
    343 +    } 
    344 +    print "\n" 
    345 +} 
    346 +END { 
    347 +    print "\n" 
    348 +} 
    349 +' 
    350 +} 
    351 + 
    352 +# LeftRightPadText <left> <right>": returns a string comprised of the two 
    353 +# 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 +    getline 
    359 +    print 
    360 +    a=78-length() 
    361 +    getline 
    362 +    for(a-=length(); a>=0; a--) {print " "} 
    363 +    print 
    364 +}' 
    365 + 
    366 +} 
    367 + 
    368 +# PluginTermination <params>: queries all loaded scriptlets if they want to 
    369 +# handle the given event. Returns 0 if the option was handled, 1 otherwise. 
    370 +PluginTermination() { 
    371 +    local i 
    372 +    for i in $TERMINATION_HANDLERS ; do 
    373 +       $i $@ && return 0 
    374 +    done 
    375 +    return 1 
    376 +} 
    377 + 
    378 +# PluginConfigOption <params>: queries all loaded scriptlets if they want to 
    379 +# handle the given option. Returns 0 if the option was handled, 1 otherwise. 
    380 +PluginConfigOption() { 
    381 +    local i 
    382 +    for i in $CONFIG_OPTION_HANDLERS ; do 
    383 +       $i $@ && return 0 
    384 +    done 
    385 +    return 1 
    386 +} 
    387 + 
    388 +# EnsureHavePrerequisites: makes sure we have all the required utilities to run 
    389 +# the script. It exits the script if we don't. 
    390 +EnsureHavePrerequisites() { 
    391 +    local i 
    392 +    for i in awk grep sort getopt basename chvt ; do 
    393 +       if ! command -v $i > /dev/null; then 
    394 +           vecho 0 "Could not find required program \"$i\". Aborting." 
    395 +           exit 1 
    396 +       fi 
    397 +    done 
    398 +    # Improvise printf using awk if need be. 
    399 +    if ! command -v printf > /dev/null 2>&1 ; then 
    400 +       # 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_FMT 
    404 +           local AWK_PARAMS 
    405 +           AWK_FMT="$1" 
    406 +           shift 
    407 +           AWK_PARAMS="" 
    408 +           for i in "$@" ; do 
    409 +               AWK_PARAMS="$AWK_PARAMS, \"$i\"" 
    410 +           done 
    411 +           awk "BEGIN { printf ( \"$AWK_FMT\" $AWK_PARAMS ) }" 
    412 +       } 
    413 +    fi 
    414 +    # Improvise mktemp in case we need it too! 
    415 +    if ! command -v mktemp > /dev/null 2>&1 ; then 
    416 +       # Use a relatively safe equivalent of mktemp. Still suspectible to race 
    417 +       # conditions, but highly unlikely. 
    418 +       mktemp() { 
    419 +           local CNT 
    420 +           local D 
    421 +           local FN 
    422 +           local RND1 
    423 +           local RND2 
    424 +           CNT=1 
    425 +           if [ -z "$RANDOM" ] ; then 
    426 +               # A fix for shells that do not have this bash feature 
    427 +               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 +           else 
    430 +               RND1=$RANDOM 
    431 +               RND2=$RANDOM 
    432 +           fi 
    433 +           while true ; do 
    434 +               D=`date +%s` 
    435 +               FN=/tmp/tmp.hibernate.$$$D$RND1$RND2$CNT 
    436 +               [ -f $FN ] && continue 
    437 +               touch $FN && break 
    438 +               CNT=$(($CNT+1)) 
    439 +           done 
    440 +           echo $FN 
    441 +       } 
    442 +    fi 
    443 +    return 0 
    444 +} 
    445 + 
    446 +# Usage: dump the abridged usage options to stdout. 
    447 +Usage() { 
    448 +    cat <<EOT 
    449 +Usage: $EXE [options] 
    450 +Activates software suspend and control its parameters. 
    451 + 
    452 +$CMDLINE_OPTIONS_HELP 
    453 +For configuration file options for hibernate.conf, man hibernate.conf. 
    454 + 
    455 +Hibernate Script $VERSION                      (C) 2004-2006 Bernard Blackham 
    456 +EOT 
    457 +    return 
    458 +} 
    459 + 
    460 +# PluginGetOpt <params>: pass the given params to each scriplet in turn that 
    461 +# requested parameters until one accepts them. Return 0 if a scriplet did 
    462 +# accept them, and 1 otherwise. 
    463 +PluginGetOpt() { 
    464 +    local opthandler 
    465 +    for opthandler in $CMDLINE_OPTION_HANDLERS ; do 
    466 +       $opthandler $* && return 0 
    467 +    done 
    468 +    return 1 
    469 +} 
    470 + 
    471 +# DoGetOpt <getopt output>: consume getopt output and set options accordingly. 
    472 +DoGetOpt() { 
    473 +    local opt 
    474 +    local optdata 
    475 +    while [ -n "$*" ] ; do 
    476 +       opt="$1" 
    477 +       shift 
    478 +       case $opt in 
    479 +           -F|--config-file) 
    480 +               # Dealt with previously 
    481 +               shift 
    482 +               ;; 
    483 +           -f|--force) 
    484 +               FORCE_ALL=1 
    485 +               ;; 
    486 +           -k|--kill) 
    487 +               KILL_PROGRAMS=1 
    488 +               ;; 
    489 +           --dry-run) 
    490 +               OPT_DRY_RUN=1 
    491 +               ;; 
    492 +           -v|--verbosity) 
    493 +               OPT_VERBOSITY="${1#\'}" 
    494 +               OPT_VERBOSITY="${OPT_VERBOSITY%\'}" 
    495 +               EnsureNumeric "verbosity" $OPT_VERBOSITY && VERBOSITY="$OPT_VERBOSITY" 
    496 +               shift 
    497 +               ;; 
    498 +           -q) 
    499 +               ;; 
    500 +           --) 
    501 +               ;; 
    502 +           *) 
    503 +               # Pass off to scriptlets See if there's a parameter given. 
    504 +               case $1 in 
    505 +                   -*) 
    506 +                       optdata="" 
    507 +                       ;; 
    508 +                   *) 
    509 +                       optdata=${1#\'} 
    510 +                       optdata=${optdata%\'} 
    511 +                       shift 
    512 +               esac 
    513 +               if ! PluginGetOpt $opt $optdata ; then 
    514 +                   echo "Unknown option $opt on command line!" 
    515 +                   exit 1 
    516 +               fi 
    517 +               ;; 
    518 +       esac 
    519 +    done 
    520 +} 
    521 + 
    522 +# ParseOptions <options>: process all the command-line options given 
    523 +ParseOptions() { 
    524 +    local opts 
    525 +    opts="`getopt -n \"$EXE\" -o \"Vhfksv:nqF:$EXTRA_SHORT_OPTS\" -l \"help,force,kill,verbosity:,dry-run,config-file:,version$EXTRA_LONG_OPTS\" -- \"$@\"`" || exit 1 
    526 +    DoGetOpt $opts 
    527 +} 
    528 + 
    529 +# CheckImplicitAlternateConfig <$0> : checks $0 to see if we should be 
    530 +# 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 0 
    534 + 
    535 +    local self 
    536 +    self="${0##*/}" 
    537 +    case $self in 
    538 +       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 +    esac 
    546 +    return 0 
    547 +} 
    548 + 
    549 +# PreliminaryGetopt <options> : detects a few command-line options that need to 
    550 +# be dealt with before scriptlets and before other command-line options. 
    551 +PreliminaryGetopt() { 
    552 +    local opt 
    553 +    set -- `getopt -q -o hv:F: -l help,verbosity:,config-file:,version -- "$@"` 
    554 +    while [ -n "$*" ] ; do 
    555 +       opt="$1" 
    556 +       shift 
    557 + 
    558 +       case $opt in 
    559 +           -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 +               shift 
    569 +               ;; 
    570 +           --version) 
    571 +               echo "Hibernate Script $VERSION" 
    572 +               exit 0 
    573 +               ;; 
    574 +           --) return 0 ;; 
    575 +       esac 
    576 +    done 
    577 +    return 0 
    578 +} 
    579 + 
    580 +# LoadScriptlets: sources all scriptlets in $SCRIPTLET_PATH directories 
    581 +LoadScriptlets() { 
    582 +    local prev_pwd 
    583 +    local scriptlet 
    584 +    local scriptlet_name 
    585 +    local scriptlet_dir 
    586 +    local prev_path 
    587 +    CURRENT_SOURCED_SCRIPTLET="" 
    588 +    for scriptlet_dir in $SCRIPTLET_PATH ; do 
    589 +       [ -d "$scriptlet_dir" ] || continue 
    590 +       [ -z "`/bin/ls -1 $scriptlet_dir`" ] && continue 
    591 +       for scriptlet in $scriptlet_dir/* ; do 
    592 +           # Avoid editor backup files. 
    593 +           case "$scriptlet" in *~|*.bak) continue ;; esac 
    594 + 
    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" ] ; then 
    601 +               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 +               continue 
    604 +           fi 
    605 +           eval "HAVE_SOURCED_SCRIPTLET_$scriptlet_name=$scriptlet" 
    606 + 
    607 +           # And now source it! 
    608 + 
    609 +           CURRENT_SOURCED_SCRIPTLET="$scriptlet_name" 
    610 +           . $scriptlet 
    611 +       done 
    612 +    done 
    613 +    if [ -z "$CURRENT_SOURCED_SCRIPTLET" ] ; then 
    614 +       echo "WARNING: No directories in scriptlet search path contained any scriptlets." 
    615 +       echo "Hence, this script probably won't do anything." 
    616 +       return 0 
    617 +    fi 
    618 +    CURRENT_SOURCED_SCRIPTLET="" 
    619 +} 
    620 + 
    621 +# BoolIsOn <option> <value>: converts a "boolean" to either 1 or 0, and takes 
    622 +# into account yes/no, on/off, 1/0, etc. If it is not valid, it will complain 
    623 +# about the option and exit. Note, the *opposite* is actually returned, as true 
    624 +# is considered 0 in shell world. 
    625 +BoolIsOn() { 
    626 +    local val 
    627 +    val=`echo $2|tr '[A-Z]' '[a-z]'` 
    628 +    [ "$val" = "on" ] && return 0 
    629 +    [ "$val" = "off" ] && return 1 
    630 +    [ "$val" = "true" ] && return 0 
    631 +    [ "$val" = "false" ] && return 1 
    632 +    [ "$val" = "yes" ] && return 0 
    633 +    [ "$val" = "no" ] && return 1 
    634 +    [ "$val" = "1" ] && return 0 
    635 +    [ "$val" = "0" ] && return 1 
    636 +    echo "$EXE: Invalid boolean value ($2) for option $1 in configuration file" 
    637 +    exit 1 
    638 +} 
    639 + 
    640 +IsANumber() { 
    641 +    case "$1" in *[!0-9]*|"") return 1 ;; esac 
    642 +    return 0 
    643 +} 
    644 + 
    645 +EnsureNumeric() { 
    646 +    IsANumber "$2" && return 0 
    647 +    echo "$EXE: Invalid numeric value ($2) for option $1 in configuration file" 
    648 +    exit 1 
    649 +} 
    650 + 
    651 +# ProcessConfigOption: takes a configuration option and its parameters and 
    652 +# passes it out to the relevant scriptlet. 
    653 +ProcessConfigOption() { 
    654 +    local option 
    655 +    local params 
    656 +    option=`echo $1|tr '[A-Z]' '[a-z]'` 
    657 +    shift 
    658 +    params="$@" 
    659 +    case $option in 
    660 +       alwaysforce) 
    661 +           [ -z "$FORCE_ALL" ] && 
    662 +               BoolIsOn "$option" "$params" && FORCE_ALL=1 
    663 +           ;; 
    664 +       alwayskill) 
    665 +           [ -z "$KILL_PROGRAMS" ] && 
    666 +               BoolIsOn "$option" "$params" && KILL_PROGRAMS=1 
    667 +           ;; 
    668 +       logfile) 
    669 +           [ -z "$LOGFILE" ] && 
    670 +               LOGFILE="$params" 
    671 +           ;; 
    672 +       logtimestamp) 
    673 +           if BoolIsOn "$option" "$params" ; then 
    674 +               LOG_TIMESTAMP=1 
    675 +           else 
    676 +               LOG_TIMESTAMP=0 
    677 +           fi 
    678 +           ;; 
    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 DISPLAY 
    695 +           ;; 
    696 +        include) 
    697 +           vecho 3 "$EXE: Including configuration from $params" 
    698 +           if ! ReadConfigFile "$params" ; then 
    699 +               echo "$EXE: Unable to read configuration file $params (from Include directive)." 
    700 +               exit 1 
    701 +           fi 
    702 +           ;; 
    703 +       trymethod) 
    704 +           if [ -z "$HIBERNATE_SUSPEND_METHOD" ] ; then 
    705 +               NO_COMPLAIN_UNSUPPORTED=1 
    706 +               vecho 1 "$EXE: Trying method in $1..." 
    707 +               if ! ReadConfigFile "$params" ; then 
    708 +                   echo "$EXE: Unable to read configuration file $params (from TryMethod directive)." 
    709 +               fi 
    710 +               NO_COMPLAIN_UNSUPPORTED= 
    711 +           fi 
    712 +           ;; 
    713 +       *) 
    714 +           if ! PluginConfigOption $option $params ; then 
    715 +               # See if we're trying something new, and haven't yet got a suspend method 
    716 +               if [ -n "$NO_COMPLAIN_UNSUPPORTED" ] && [ -z "$HIBERNATE_SUSPEND_METHOD" ] ; then 
    717 +                   return 1 
    718 +               else 
    719 +                   echo "$EXE: Unknown configuration option ($option)" 
    720 +                   exit 1 
    721 +               fi 
    722 +           fi 
    723 +           ;; 
    724 +    esac 
    725 +    return 0 
    726 +} 
    727 + 
    728 +# ReadConfigFile: reads in a configuration file from stdin and sets the 
    729 +# appropriate variables in the script. Returns 0 on success, exits on errors 
    730 +conffiles_read= 
    731 +ReadConfigFile() { 
    732 +    local option params 
    733 +    local file_name; file_name="$1" 
    734 +     
    735 +    if [ ! -f "${file_name}" ] ; then 
    736 +       # Search in /etc/hibernate 
    737 +       if [ -f "$SWSUSP_D/$file_name" ] ; then 
    738 +           file_name="$SWSUSP_D/$file_name" 
    739 +       else 
    740 +           echo "WARNING: No configuration file found (${file_name})." 
    741 +           echo "This script probably won't do anything." 
    742 +           return 1 
    743 +       fi 
    744 +    fi 
    745 + 
    746 +    if [ "${conffiles_read#*$file_name}" != "$conffiles_read" ]; then 
    747 +       vecho 2 "$EXE: Skipping already included config file $file_name" 
    748 +       return 0 
    749 +    fi 
    750 + 
    751 +    while true ; do 
    752 +       # Doing the read this way allows means we don't require a new-line 
    753 +       # at the end of the file. 
    754 +       read option params 
    755 +       [ $? -ne 0 ] && [ -z "$option" ] && break 
    756 +       [ -z "$option" ] && continue 
    757 +       case $option in ""|\#*) continue ;; esac # avoids a function call (big speed hit) 
    758 +       ProcessConfigOption $option $params || break 
    759 +    done < ${file_name} 
    760 +    return 0 
    761 +} 
    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 errors 
    776 +   1: print steps 
    777 +   2: print steps in detail 
    778 +   3: print steps in lots of detail 
    779 +   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" ] ; then 
    792 +       echo "$EXE: You need to run this script as root." 
    793 +       exit 1 
    794 +    fi 
    795 +    return 0 
    796 +} 
    797 + 
    798 +# DoWork: Does the actual calling of scriptlet functions. We wrap this to make 
    799 +# it easy to decide whether or not to pipe its output to $LOGPIPE or not. 
    800 +DoWork() { 
    801 +    # Trap Ctrl+C 
    802 +    trap ctrlc_handler INT HUP 
    803 + 
    804 +    # Do everything we need to do to suspend. If anything fails, we don't 
    805 +    # suspend.  Suspend itself should be the last one in the sequence. 
    806 + 
    807 +    local ret 
    808 +    local CHAIN_UP_TO 
    809 +    local bit 
    810 + 
    811 +    CHAIN_UP_TO=0 
    812 +    for bit in `SortSuspendBits` ; do 
    813 +       local new_CHAIN_UP_TO 
    814 +       new_CHAIN_UP_TO="`awk \"BEGIN{print substr(\\\"$bit\\\", 1, 2)}\"`" || break 
    815 +       [ -n "$new_CHAIN_UP_TO" ] && CHAIN_UP_TO=$new_CHAIN_UP_TO || continue 
    816 +       bit=${bit##$CHAIN_UP_TO} 
    817 +       vecho 1 "$EXE: [$CHAIN_UP_TO] Executing $bit ... " 
    818 +       [ -n "$OPT_DRY_RUN" ] && continue 
    819 +       $bit 
    820 +       ret="$?" 
    821 +       # A return value >= 2 denotes we can't go any further, even with --force. 
    822 +       if [ $ret -ge 2 ] ; then 
    823 +           # If the return value is 3 or higher, be silent. 
    824 +           if [ $ret -eq 2 ] ; then 
    825 +               vecho 1 "$EXE: $bit refuses to let us continue." 
    826 +               vecho 0 "$EXE: Aborting." 
    827 +               EXIT_CODE=2 
    828 +           fi 
    829 +           break 
    830 +       fi 
    831 +       # A return value of 1 means we can't go any further unless --force is used 
    832 +       if [ $ret -gt 0 ] && [ x"$FORCE_ALL" != "x1" ] ; then 
    833 +           vecho 0 "$EXE: Aborting suspend due to errors in $bit (use --force to override)." 
    834 +           EXIT_CODE=2 
    835 +           break 
    836 +       fi 
    837 +       if [ -n "$SUSPEND_ABORT" ] ; then 
    838 +           vecho 0 "$EXE: Suspend aborted by user." 
    839 +           EXIT_CODE=3 
    840 +           break 
    841 +       fi 
    842 +    done 
    843 + 
    844 +    # Resume and cleanup and stuff. 
    845 +    for bit in `SortResumeBits` ; do 
    846 +       THIS_POS="`awk \"BEGIN{print substr(\\\"$bit\\\", 1, 2)}\"`" 
    847 +       [ -z "$THIS_POS" ] && continue 
    848 +       bit=${bit##$THIS_POS} 
    849 +       [ "$THIS_POS" -gt "$CHAIN_UP_TO" ] && continue 
    850 +       vecho 1 "$EXE: [$THIS_POS] Executing $bit ... " 
    851 +       [ -n "$OPT_DRY_RUN" ] && continue 
    852 +       $bit 
    853 +    done 
    854 +    return $EXIT_CODE 
    855 +} 
    856 + 
    857 +ctrlc_handler() { 
    858 +    SUSPEND_ABORT=1 
    859 +} 
    860 + 
    861 +# Gets the value of the environment variable in the environment space of the 
    862 +# 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=0 
    874 +LOG_VERBOSITY=1 
    875 +LOGPIPE="cat" 
    876 +ERROR_TEXT="" 
    877 + 
    878 +EnsureHavePrerequisites 
    879 + 
    880 +# Test for options that will affect future choices 
    881 +PreliminaryGetopt "$@" 
    882 + 
    883 +CheckImplicitAlternateConfig $0 
    884 + 
    885 +# Generating help text is slow. Avoid it if we can. 
    886 +if [ -n "$HELP_ONLY" ] ; then 
    887 +    AddInbuiltHelp 
    888 +    LoadScriptlets 
    889 +    Usage 
    890 +    exit 0 
    891 +fi 
    892 +DISABLE_HELP=1 
    893 + 
    894 +EnsureHaveRoot 
    895 +LoadScriptlets 
    896 +ReadConfigFile "${CONFIG_FILE}" 
    897 +# Verify we actually got a suspend method we could use. 
    898 +if [ -z "$HIBERNATE_SUSPEND_METHOD" ] ; then 
    899 +    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 1 
    903 +fi 
    904 +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 one 
    910 +if [ -n "$SWSUSPVT" ] && [ -c /dev/tty$SWSUSPVT ] ; then 
    911 +    exec >/dev/tty$SWSUSPVT 2>&1 
    912 +fi 
    913 + 
    914 +# Use -x if we're being really verbose! 
    915 +[ $VERBOSITY -ge 4 ] && set -x 
    916 + 
    917 +echo "Starting suspend at "`date` | $LOGPIPE > /dev/null 
    918 + 
    919 +EXIT_CODE=0 
    920 + 
    921 +if [ "$LOGPIPE" = "cat" ] ; then 
    922 +    DoWork 
    923 +else 
    924 +    # Sigh. Our portable way to obtain exit codes has issues in bash, so if 
    925 +    # we're using bash, we do it the not-so-portable way :) 
    926 +    if [ -n "$USING_BASH" ] ; then 
    927 +       DoWork | $LOGPIPE 
    928 +       eval 'EXIT_CODE=${PIPESTATUS[0]}' 
    929 +    else 
    930 +       # Evilness required to pass the exit code back to us in a pipe. 
    931 +       trap "" INT 
    932 +       exec 3>&1 
    933 +       eval ` 
    934 +           exec 4>&1 >&3 3>&- 
    935 +           { 
    936 +               DoWork 4>&- 
    937 +               echo "EXIT_CODE=$EXIT_CODE" >&4 
    938 +           } | $LOGPIPE` 
    939 +    fi 
    940 +fi 
    941 + 
    942 +PluginTermination 
    943 + 
    944 +echo "Resumed at "`date` | $LOGPIPE > /dev/null 
    945 + 
    946 +exit $EXIT_CODE 
    947 + 
    948 +# $Id$ 
    94927diff -urN hibernate-script-1.98.1/logrotate.d-hibernate-script hibernate-script-1.98.1.new/logrotate.d-hibernate-script 
    95028--- 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.