| 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | configure() { |
| 6 | LOGDIR="/var/log/atop" |
| 7 | # this has been in place since at least buster. remove post-trixie |
| 8 | rm -f "${LOGDIR}/dummy_after" "${LOGDIR}/dummy_before" |
| 9 | # check whether atop will read its own latest file |
| 10 | # point atop to the latest file and check for output on stdout |
| 11 | # the pipe will prevent atop from going interactive, and if it |
| 12 | # won't read the file, stdout will be empty. |
| 13 | LATESTFILE="$(find "${LOGDIR}" -maxdepth 1 -type f \ |
| 14 | -regextype posix-egrep -regex '.*/atop_[0-9]+$' \ |
| 15 | -printf '%p\n' | sort | tail -n 1)" |
| 16 | if [ -n "${LATESTFILE}" ]; then |
| 17 | if ! atop -r "${LATESTFILE}" 2>/dev/null | head -n 5 | grep -q '.'; then |
| 18 | # updating from an older version which won't read |
| 19 | # the old log file format |
| 20 | # take a backup of the old file and convert it |
| 21 | BACKUPFILE="${LATESTFILE}_oldformat" |
| 22 | if [ -e "${BACKUPFILE}" ]; then |
| 23 | TIMESTAMP=$(date +%Y%m%dT%H%M%S) |
| 24 | BACKUPFILE="${LATESTFILE}_oldformat_${TIMESTAMP}" |
| 25 | fi |
| 26 | if mv "${LATESTFILE}" "${BACKUPFILE}"; then |
| 27 | if atopconvert "${BACKUPFILE}" "${LATESTFILE}" >/dev/null; then |
| 28 | if ! atop -r "${LATESTFILE}" 2>/dev/null | head -n 5 | grep -q '.'; then |
| 29 | printf >&2 "atop postinst: error reading converted log file %s.\\n" "${LATESTFILE}" |
| 30 | # remove generated file, we do without the converted file |
| 31 | rm -f "${LATESTFILE}" |
| 32 | fi |
| 33 | else |
| 34 | printf >&2 "atop postinst: conversion failed from %s to new atop raw file format %s" "${BACKUPFILE}" "${LATESTFILE}" |
| 35 | # remove generated file, we do without the converted file |
| 36 | rm -f "${LATESTFILE}" |
| 37 | fi |
| 38 | else |
| 39 | printf >&2 "atop postinst: failed to back up %s\\n" "${LATESTFILE}" |
| 40 | exit 1 |
| 41 | fi |
| 42 | fi |
| 43 | fi |
| 44 | } |
| 45 | |
| 46 | case "$1" in |
| 47 | configure) configure ;; |
| 48 | esac |
| 49 | |
| 50 | #DEBHELPER# |
| 51 | |
| 52 | # vim: tabstop=4 expandtab |
| 53 |