File: postinst

package info (click to toggle)
atop 2.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,328 kB
  • sloc: ansic: 35,620; python: 257; sh: 248; makefile: 193
file content (53 lines) | stat: -rw-r--r-- 2,129 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

set -e

configure() {
    LOGDIR="/var/log/atop"
    # this has been in place since at least buster. remove post-trixie
    rm -f "${LOGDIR}/dummy_after" "${LOGDIR}/dummy_before"
    # check whether atop will read its own latest file
    # point atop to the latest file and check for output on stdout
    # the pipe will prevent atop from going interactive, and if it
    # won't read the file, stdout will be empty.
    LATESTFILE="$(find "${LOGDIR}" -maxdepth 1 -type f \
            -regextype posix-egrep -regex '.*/atop_[0-9]+$' \
            -printf '%p\n' | sort | tail -n 1)"
    if [ -n "${LATESTFILE}" ]; then
        if ! atop -r "${LATESTFILE}" 2>/dev/null | head -n 5 | grep -q '.'; then
            # updating from an older version which won't read
            # the old log file format
            # take a backup of the old file and convert it
            BACKUPFILE="${LATESTFILE}_oldformat"
            if [ -e "${BACKUPFILE}" ]; then
                TIMESTAMP=$(date +%Y%m%dT%H%M%S)
                BACKUPFILE="${LATESTFILE}_oldformat_${TIMESTAMP}"
            fi
            if mv "${LATESTFILE}" "${BACKUPFILE}"; then
                if atopconvert "${BACKUPFILE}" "${LATESTFILE}" >/dev/null; then
                    if ! atop -r "${LATESTFILE}" 2>/dev/null | head -n 5 | grep -q '.'; then
                        printf >&2 "atop postinst: error reading converted log file %s.\\n" "${LATESTFILE}"
                        # remove generated file, we do without the converted file
                        rm -f "${LATESTFILE}"
                    fi
                else
                    printf >&2 "atop postinst: conversion failed from %s to new atop raw file format %s" "${BACKUPFILE}" "${LATESTFILE}"
                    # remove generated file, we do without the converted file
                    rm -f "${LATESTFILE}"
                fi
            else
                printf >&2 "atop postinst: failed to back up %s\\n" "${LATESTFILE}"
                exit 1
            fi
        fi
    fi
}

case "$1" in
    configure) configure ;;
esac

#DEBHELPER#

# vim: tabstop=4 expandtab