aboutsummaryrefslogtreecommitdiff
path: root/hooks/demos/elog.bash.in
blob: 6e1598a4d4ef2a29699370a972afc13b36e8488a (plain)
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
#!/bin/bash
# vim: set et sw=4 sts=4 :

# This hook makes Paludis store messages generated by an ebuild in a file.
# These stored messages are then displayed to the user after a merge. To enable
# this functionality, this script should be copied or symlinked into:
#
#     @DATADIR@/paludis/hooks/elog/
#     @DATADIR@/paludis/hooks/install_all_pre/
#     @DATADIR@/paludis/hooks/install_all_post/
#     @DATADIR@/paludis/hooks/install_fail/
#     @DATADIR@/paludis/hooks/uninstall_all_pre/
#     @DATADIR@/paludis/hooks/uninstall_all_post/
#     @DATADIR@/paludis/hooks/uninstall_fail/
#     @DATADIR@/paludis/hooks/clean_fail/
#
# And optionally:
#
#     @DATADIR@/paludis/hooks/einfo/
#     @DATADIR@/paludis/hooks/ewarn/
#     @DATADIR@/paludis/hooks/eerror/
#
# You should ensure that it has execute permissions.

case "${EBUILD_PHASE}" in
    config|pretend|metadata) return
esac

source ${PALUDIS_ECHO_FUNCTIONS_DIR:-${PALUDIS_EBUILD_DIR}}/echo_functions.bash

logfile="${PALUDIS_HOOKS_TMPDIR:-${ROOT}/var/tmp/paludis}/elog.${PALUDIS_PID}"

case "${HOOK}" in
    elog)
    echo "L ${CATEGORY}/${PF} ${MESSAGE}" >> "${logfile}"
    ;;

    einfo)
    echo "I ${CATEGORY}/${PF} ${MESSAGE}" >> "${logfile}"
    ;;

    ewarn)
    echo "W ${CATEGORY}/${PF} ${MESSAGE}" >> "${logfile}"
    ;;

    eerror)
    echo "E ${CATEGORY}/${PF} ${MESSAGE}" >> "${logfile}"
    ;;

    install_all_pre|uninstall_all_pre)
    rm -f "${logfile}"
    touch "${logfile}" || die "Couldn't create '${logfile}' for elog hooks"
    if [[ -n "${PALUDIS_REDUCED_GID}" ]] ; then
        chgrp "${PALUDIS_REDUCED_GID}" "${logfile}" || die "Couldn't chgrp '${logfile}' for elog hooks"
        chmod g+rw "${logfile}" || die "Couldn't chmod '${logfile}' for elog hooks"
    fi
    ;;

    install_all_post|uninstall_all_post|install_fail|uninstall_fail|clean_fail)
    echo
    old_pf=""
    while read line ; do
        line_status=$(echo "${line}" | cut -d' ' -f1 )
        line_pf=$(echo "${line}" | cut -d' ' -f2 )
        line_message=$(echo "${line}" | cut -d' ' -f3- )

        if [[ "${old_pf}" != "${line_pf}" ]] ; then
            echo
            echo "${COLOUR_GOOD}Summary of messages from ${line_pf}:${COLOUR_NORMAL}"
            echo
            old_pf="${line_pf}"
        fi

        case "${line_status}" in
            L|I)
            echo -ne " ${COLOUR_GOOD}*${COLOUR_NORMAL} "
            ;;

            W)
            echo -ne " ${COLOUR_WARN}*${COLOUR_NORMAL} "
            ;;

            E)
            echo -ne " ${COLOUR_BAD}*${COLOUR_NORMAL} "
            ;;
        esac
        echo "${line_message}"

    done <"${logfile}"

    rm -f "${logfile}"
    ;;

    *)
    paludis_ecmd \
        "ewarn" \
        "" \
        "`echo -ne " ${COLOUR_WARN}*${COLOUR_NORMAL} "`" \
        "elog.bash doesn't know what to do for HOOK=\"${HOOK}\""
    ;;
esac