File: misclaunch

package info (click to toggle)
hibernate 2.0%2B15%2Bg88d54a8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 740 kB
  • ctags: 114
  • sloc: sh: 1,223; makefile: 17
file content (74 lines) | stat: -rw-r--r-- 1,951 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler MiscLaunchOptions
AddConfigHelp "OnSuspend NN <program to execute> [parameters for program]" "Executes a given program before suspending. NN is a two-digit number between 00 and 99, inclusive - a higher number means the program will be executed later in the suspend process. See the ORDERING section in the SCRIPTLET-API for details."
AddConfigHelp "OnResume NN <program to execute> [parameters for program]" "Executes a given program after resuming. NN is a number between 00 and 99, inclusive - a higher number means the program will be executed earlier in the resume process. See the ORDERING section in the SCRIPTLET-API for details."

MISC_LAUNCH_COUNT=0

MiscLaunchSuspendProg() {
    local tmpf
    MISC_LAUNCH_COUNT=$(($MISC_LAUNCH_COUNT+1))
    tmpf=`mktemp /tmp/tmp.hibernate.XXXXXX`
    AddSuspendHook $1 MiscLaunchAuxFunc$MISC_LAUNCH_COUNT
    shift
    cat <<EOT > $tmpf
MiscLaunchAuxFunc${MISC_LAUNCH_COUNT}() {
    vcat 1 <<EOT2
Executing $@...
EOT2
    $@
    [ \$? -ne 0 ] && return 1
    return 0
}
EOT
    . $tmpf
    rm -f $tmpf
}

MiscLaunchResumeProg() {
    local tmpf
    MISC_LAUNCH_COUNT=$(($MISC_LAUNCH_COUNT+1))
    tmpf=`mktemp /tmp/tmp.hibernate.XXXXXX`
    AddResumeHook $1 MiscLaunchAuxFunc$MISC_LAUNCH_COUNT
    shift
    cat <<EOT > $tmpf
MiscLaunchAuxFunc${MISC_LAUNCH_COUNT}() {
    vcat 1 <<EOT2
Executing $@...
EOT2
    $@
    [ \$? -ne 0 ] && return 1
    return 0
}
EOT
    . $tmpf
    rm -f $tmpf
}

MiscLaunchOptions() {
    case $1 in
	onsuspend)
	    shift
	    if ! IsANumber $1 ; then
		vecho 0 "First argument to OnSuspend must be a number between 00 and 99!"
		exit 1
	    fi
	    MiscLaunchSuspendProg $*
	    ;;
	onresume)
	    shift
	    if ! IsANumber $1 ; then
		vecho 0 "First argument to OnResume must be a number between 00 and 99!"
		exit 1
	    fi
	    MiscLaunchResumeProg $*
	    ;;
	*)
	    return 1
    esac
    return 0
}

# $Id$