summarylogtreecommitdiffstats
path: root/crowdsec-bin.install
blob: 7443ae40bb372f5137a04298f897d52d53478cf0 (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
# 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() {
    config_backup="/tmp/crowdsec_upgrade_$1_$2"
    rm -rf "$config_backup"
    cscli config backup "$config_backup" --error
}

post_upgrade() {
    cscli hub update
    config_backup="/tmp/crowdsec_upgrade_$1_$2"
    if [ -d "$config_backup" ]; then
        cscli config restore "$config_backup" --error &&
            rm -rf "$config_backup" || echo -e "\n**Config backup restore failed: ${config_backup}**\n"
    fi
    cscli collections upgrade --error --all
    systemctl daemon-reload
    systemctl reload crowdsec
}

pre_remove() {
    cscli dashboard stop --error
}

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