This file is indexed.

/usr/lib/pm-utils/sleep.d/01PulseAudio is in pulseaudio 1:1.1-0ubuntu15.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /bin/sh

. "${PM_FUNCTIONS}"

test_pulse_system() {
    getent passwd pulse | awk -F: '{print $3}'
}

get_pulse_users() {
    PULSE_SYSTEM_USER=$(test_pulse_system)
    if [ -z "${PULSE_SYSTEM_USER}" ]; then
        ps -C pulseaudio -o uid= | tr -d ' '
    else
        ps -C pulseaudio -o uid= | tr -d ' ' | sed s/${PULSE_SYSTEM_USER}//
    fi
}

# $1 = sink|source
# $2 = username
save_pulse_state() {
    su "${2}" -c -- "pacmd list-${1}s" | \
        sed -n "s/^[[:space:]*]*//; /\(index\|mute\)/p" | \
        (index="";
            while read field value; do
                if [ ${field%:} = "index" ]; then
                    index=${value}
                else
                    savestate pulse:"${2}":${1}${index} ${value}
                fi
            done)
}

# $1 = sink|source
# $2 = username
restore_pulse_state() {
    su "${2}" -c -- "pacmd list-${1}s" | \
        sed -n "s/^[[:space:]*]*index: //p" | \
        while read index; do
            if state_exists pulse:"${2}":${1}${index}; then
                su "${2}" -c -- "pacmd \
                    set-${1}-mute \
                    ${index} \
                    $(restorestate pulse:"${2}":${1}${index})"
            fi
        done
}

# $1 = sink|source
# $2 = username
mute_pulse() {
    su "${2}" -c -- "pacmd list-${1}s" | \
        sed -n "s/^[[:space:]*]*//; /\(index\|mute\)/p" | \
        (index="";
            while read field value; do
                if [ ${field%:} = "index" ]; then
                    index=${value}
                    su "${2}" -c -- "pacmd \
                        set-${1}-mute ${index} yes"
                fi
            done)
}

suspend_pulse() {
    for i in $(get_pulse_users); do
        THIS_USER="$(getent passwd ${i} | cut -f1 -d:)"
        save_pulse_state sink "${THIS_USER}"
        save_pulse_state source "${THIS_USER}"
        su "${THIS_USER}" -c -- 'pacmd suspend true' > /dev/null 2>&1
    done
    for i in $(get_pulse_users); do
        THIS_USER="$(getent passwd ${i} | cut -f1 -d:)"
        if su "${THIS_USER}" -c -- 'ck-list-sessions | grep "active = TRUE"' > /dev/null 2>&1; then
            mute_pulse sink "${THIS_USER}"
            mute_pulse source "${THIS_USER}"
            break
        fi
    done
}

resume_pulse() {
    for i in $(get_pulse_users); do
        THIS_USER="$(getent passwd ${i} | cut -f1 -d:)"
        restore_pulse_state sink "${THIS_USER}"
        restore_pulse_state source "${THIS_USER}"
        su "${THIS_USER}" -c -- 'pacmd suspend false' > /dev/null 2>&1
    done
}

case $1 in
    hibernate|suspend)
        suspend_pulse
        ;;
    thaw|resume)
        resume_pulse
        ;;
    *) exit $NA
        ;;
esac