summarylogtreecommitdiffstats
path: root/crowdsec-bin.install
blob: 9eb261213fc9b895b2518a27ad59c01d0a855fa0 (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
# https://docs.crowdsec.net/docs/user_guides/building#binary-installation

post_install() {
    cscli hub update
    # readarray -t collections < <(cscli collections list --output json --all | jq -r '.[] | map(select(.status | contains ("disabled")) | .name) | unique | .[]')
    # if [ ${#collections} -gt 0 ]; then
    #     cscli collections install ${collections[@]} >/dev/null 2>&1
    # fi
    cscli collections install crowdsecurity/linux crowdsecurity/whitelist-good-actors
    cscli machines add --force "$(</etc/machine-id)" --auto
    cscli capi register
    if systemctl is-active -q crowdsec; then
        systemctl reload crowdsec
    else
        systemctl daemon-reload
        systemctl enable --now crowdsec
    fi
}

pre_upgrade() {
    # dashboard deprecated in version 1.7.0
    # see https://docs.crowdsec.net/blog/cscli_dashboard_deprecation/
    if (( $(vercmp "$2" '1.7.0') < 0 )); then
        cscli dashboard stop --error
    fi
}

post_upgrade() {
    cscli hub update
    cscli collections upgrade --error --all

    if (( $(vercmp "$2" '1.7.0') < 0 )); then
        if systemctl is-active -q crowdsec; then
            systemctl stop crowdsec
        fi
        echo -e '\t** Please use the pacdiff command to merge the new configuration files **\n'
        echo -e '\t** before restarting crowdsec. **\n'
    fi

    systemctl daemon-reload
    if systemctl is-active -q crowdsec; then
        systemctl reload crowdsec
    fi
}

post_remove() {
    rm -f /var/log/crowdsec*.log
    systemctl daemon-reload
}