aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/bsdstats/pkg-install
blob: 1b05fa7b3e99b63255d1b3b93b702e61555bdec5 (plain) (blame)
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
#!/bin/sh
#
# pkg-install : based off ${PORTSDIR}/mail/courier/files/pkg-install.in
#

ask() {
    local question default answer

    question=$1
    default=$2
    if [ -z "${PACKAGE_BUILDING}" ]; then
        read -p "${question} [${default}]? " answer
    fi
    if [ -z "${answer}" ]; then
        answer=${default}
    fi
    echo ${answer}
}

yesno() {
    local question default answer

    question=$1
    default=$2
    while :; do
        answer=$(ask "${question}" "${default}")
        case "${answer}" in
        [Yy]*)  return 0;;
        [Nn]*)  return 1;;
        esac
        echo "Please answer yes or no."
    done
}

if [ ":$2" = ":POST-INSTALL" ]; then
    if [ -f "/etc/periodic.conf" ]; then
        if [ `grep monthly_statistics /etc/periodic.conf | wc -l` = 0 ]; then
            if yesno "Would you like to activate monthly reporting in /etc/periodic.conf" n; then
                echo "monthly_statistics_enable=\"YES\"" >> /etc/periodic.conf
                echo "bsdstats_enable=\"YES\"" >> /etc/rc.conf
                if yesno "Would you like to send a list of installed hardware as well" n; then
                    echo "monthly_statistics_report_devices=\"YES\"" >> /etc/periodic.conf
                fi
                if yesno "Would you like to send a list of installed ports as well" n; then
                    echo "monthly_statistics_report_ports=\"YES\"" >> /etc/periodic.conf
                fi
                if yesno "Would you like to run it now" y; then
                   ${PKG_PREFIX}/etc/periodic/monthly/300.statistics -nodelay
                fi
            fi
        else
            if [ `grep 'monthly_statistics_enable="YES"' /etc/periodic.conf | wc -l` = 1 ]; then
                if [ `grep 'bsdstats_enable="YES"' /etc/rc.conf | wc -l` = 0 ]; then
                    echo "bsdstats_enable=\"YES\"" >> /etc/rc.conf
                fi
            fi
        fi
    elif [ ! -f "/etc/periodic.conf" ]; then
        if yesno "Would you like to activate monthly reporting in /etc/periodic.conf" n; then
            echo "monthly_statistics_enable=\"YES\"" >> /etc/periodic.conf
            echo "bsdstats_enable=\"YES\"" >> /etc/rc.conf
            if yesno "Would you like to send a list of installed hardware as well" n; then
                echo "monthly_statistics_report_devices=\"YES\"" >> /etc/periodic.conf
            fi
            if yesno "Would you like to send a list of installed ports as well" n; then
                echo "monthly_statistics_report_ports=\"YES\"" >> /etc/periodic.conf
            fi
            if yesno "Would you like to run it now" y; then
               ${PKG_PREFIX}/etc/periodic/monthly/300.statistics -nodelay
            fi
        fi
    fi
fi