File: sysstat.postinst

package info (click to toggle)
sysstat 12.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,156 kB
  • sloc: ansic: 49,310; sh: 1,388; xml: 1,285; makefile: 768; tcl: 756; python: 277; perl: 257
file content (131 lines) | stat: -rw-r--r-- 3,626 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /bin/sh
# vim:ts=4:et:sw=4

set -e

S_VERSION="10.3.1-1~"
PACKAGE="sysstat"
DEFAULT="/etc/default/$PACKAGE"
ENABLED="false"

### manage_default_file: manages $DEFAULT file with ucf ###
manage_default_file() {
    ENABLED="$1"

    if [ "$ENABLED" != "true" ] && [ "$ENABLED" != "false" ] ; then
        echo "Internal error in the sysstat's postinst: \$ENABLED=$ENABLED" 1>&2;
        exit 1;
    fi

    # Generate temporary files
    def_file=`mktemp -t sstatXXXXXXXXX.def`

    # Fill new temporary default file
    cat > "$def_file" << EOF
#
# Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat
# and /etc/cron.daily/sysstat files
#

# Should sadc collect system activity informations? Valid values
# are "true" and "false". Please do not put other values, they
# will be overwritten by debconf!
ENABLED="$ENABLED"

EOF

    # Finally, run ucf
    ucf --three-way \
        --debconf-ok \
        "$def_file" "$DEFAULT"
    ucfr "$PACKAGE" "$DEFAULT"

    [ -e "$DEFAULT" ] && chmod 644 "$DEFAULT"
    rm -f "$def_file"
}

manage_systemd_services()
{
    ENABLED="$1"
    all_services='sysstat-collect.timer sysstat-summary.timer sysstat.service'
    num_all_services=3

    # deb-systemd-helper does not have the --now option
    sysctl='/bin/systemctl'
    num_disabled=0

    [ -x "$sysctl" ] && [ -d /run/systemd/system ] || return 0

    for service in $all_services; do
        "$sysctl" --quiet is-enabled "$service" || num_disabled=$(expr $num_disabled + 1)
    done

    if [ $num_disabled != 0 ] && [ $num_disabled !=  $num_all_services ]; then
        # Do not override local administator choice to enable only some of systemd files
        return 0
    fi

    [ $num_disabled = 0 ] && is_enabled="true" || is_enabled="false"
    [ "$ENABLED" != "$is_enabled" ] || return 0

    [ "$ENABLED" = "true" ] && enable_arg="enable" || enable_arg="disable"

    for service in $all_services; do
        case $service in
            *.timer) options="--now" ;;
            *)       options=""      ;;
        esac

        "$sysctl" "$enable_arg" $options "$service" >/dev/null 2>&1 || true
    done
}

### Main ###

. /usr/share/debconf/confmodule

ENABLED=""
if [ "$1" = "configure" ] ; then
    if dpkg --compare-versions "$2" lt-nl "$S_VERSION"; then
        RET=""
        db_get sysstat/remove_files || true

        if [ "$RET" = "true" ]; then
            echo "Removing old statistics from /var/log/sysstat." 1>&2
            find  /var/log/sysstat -maxdepth 2 \( -name 'sa[0-9][0-9]' -o -name 'sa[0-9][0-9].gz' \
                                                  -o -name 'sa[0-9][0-9].bz2' \) -exec rm -f {} \;
        fi
    fi

    # show the question next time
    db_reset sysstat/remove_files || true

    db_get sysstat/enable || true
    ENABLED="$RET"

    manage_default_file "$ENABLED"

    # must be called *after* manage_default_file, which uses ucf --debconf-ok
    db_stop || true


    if ! update-alternatives --display sar 2>/dev/null | grep -q '^/usr/bin/sar\.sysstat'; then
        update-alternatives --install /usr/bin/sar sar /usr/bin/sar.sysstat 0 \
                            --slave /usr/share/man/man1/sar.1.gz sar.1.gz \
                            /usr/share/man/man1/sar.sysstat.1.gz
    fi
fi

#DEBHELPER#

if [ "$1" = "configure" ] && [ -n "$ENABLED" ]; then
    manage_systemd_services "$ENABLED"

    # execute sa1 in a subshell not to clobber the postinst script with potentially
    # unsafe values from "$DEFAULT"
    if [ "$ENABLED" = "true" ] && [ -x /usr/libexec/sysstat/sa1 ] ; then
        ( set +e ; /usr/libexec/sysstat/sa1 1 1 )&
    fi
fi

exit 0