aboutsummaryrefslogtreecommitdiff
path: root/hooks/demos/elog.bash.in
blob: 3e23071444202ef38de7482421eedb778d734293 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/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_task_execute_pre/
#     @DATADIR@/paludis/hooks/install_task_execute_post/
#     @DATADIR@/paludis/hooks/uninstall_all_pre/
#     @DATADIR@/paludis/hooks/uninstall_all_post/
#     @DATADIR@/paludis/hooks/uninstall_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_task_execute_pre|install_all_pre|uninstall_all_pre)
    if [[ ${HOOK} = install_all_pre ]]; then
        paludis_ecmd \
            "ewarn" \
            "" \
            "`echo -ne " ${COLOUR_WARN}*${COLOUR_NORMAL} "`" \
            "Use of elog.bash in phase \"${HOOK}\" is deprecated, see comments at beginning of file for updated instructions"
    fi

    ${PRETEND} && exit 0

    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|install_task_execute_post)
    if [[ ${HOOK} = install_all_post || ${HOOK} = install_fail || ${HOOK} = clean_fail ]]; then
        paludis_ecmd \
            "ewarn" \
            "" \
            "`echo -ne " ${COLOUR_WARN}*${COLOUR_NORMAL} "`" \
            "Use of elog.bash in phase \"${HOOK}\" is deprecated, see comments at beginning of file for updated instructions"
    fi

    ${PRETEND} && exit 0

    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