2021-08-18 11:57:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
COLLECTIONS=false
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Source debconf library.
|
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
|
|
|
|
if [ "$1" = configure ]; then
|
|
|
|
if [[ ! -d /var/lib/crowdsec/data ]]; then
|
|
|
|
mkdir -p /var/lib/crowdsec/data
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d /var/lib/crowdsec/backup ]]; then
|
|
|
|
cscli config restore /var/lib/crowdsec/backup/backup.config
|
|
|
|
rm -rf /var/lib/crowdsec/backup
|
|
|
|
/usr/bin/cscli hub update
|
|
|
|
/usr/bin/cscli hub upgrade
|
|
|
|
systemctl start crowdsec
|
|
|
|
fi
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
. /usr/share/crowdsec/wizard.sh -n
|
2021-09-09 14:24:59 +00:00
|
|
|
if ! [[ -f /etc/crowdsec/acquis.yaml ]]; then
|
2021-08-18 11:57:06 +00:00
|
|
|
echo Creating /etc/crowdsec/acquis.yaml
|
|
|
|
set +e
|
|
|
|
SILENT=true detect_services
|
2022-08-16 12:59:59 +00:00
|
|
|
SILENT=true TMP_ACQUIS_FILE_SKIP=skip genacquisition
|
2021-08-18 11:57:06 +00:00
|
|
|
set -e
|
|
|
|
COLLECTIONS=true
|
|
|
|
fi
|
2021-10-22 08:14:15 +00:00
|
|
|
|
|
|
|
if [[ -f /etc/crowdsec/local_api_credentials.yaml ]] ; then
|
|
|
|
chmod 600 /etc/crowdsec/local_api_credentials.yaml
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f /etc/crowdsec/online_api_credentials.yaml ]]; then
|
|
|
|
chmod 600 /etc/crowdsec/online_api_credentials.yaml
|
|
|
|
fi
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
if [[ ! -f /etc/crowdsec/local_api_credentials.yaml ]] || [[ ! -f /etc/crowdsec/online_api_credentials.yaml ]]; then
|
2021-10-22 08:14:15 +00:00
|
|
|
if [[ ! -f /etc/crowdsec/local_api_credentials.yaml ]] ; then
|
|
|
|
install -m 600 /dev/null /etc/crowdsec/local_api_credentials.yaml
|
|
|
|
fi
|
|
|
|
if [[ ! -f /etc/crowdsec/online_api_credentials.yaml ]] ; then
|
|
|
|
install -m 600 /dev/null /etc/crowdsec/online_api_credentials.yaml
|
|
|
|
fi
|
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
db_input medium crowdsec/lapi || true
|
|
|
|
db_go || true
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
db_get crowdsec/lapi
|
|
|
|
LAPI=$RET
|
|
|
|
|
|
|
|
if [ "$LAPI" = true ]; then
|
|
|
|
db_input medium crowdsec/capi || true
|
|
|
|
db_go || true
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
db_get crowdsec/capi
|
|
|
|
CAPI=$RET
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2023-12-13 14:43:46 +00:00
|
|
|
[ -s /etc/crowdsec/local_api_credentials.yaml ] || cscli machines add -a --force --error
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
if [ "$CAPI" = true ]; then
|
2024-01-18 08:20:52 +00:00
|
|
|
cscli capi register --error
|
2021-08-18 11:57:06 +00:00
|
|
|
fi
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
else
|
|
|
|
db_input medium crowdsec/lapi_host || true
|
|
|
|
db_go || true
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
db_get crowdsec/lapi_host
|
|
|
|
LAPI_HOST=$RET
|
|
|
|
sed -i "s/127.0.0.1:8080/$LAPI_HOST/g" /etc/crowdsec/config.yaml
|
|
|
|
fi
|
|
|
|
fi
|
2022-02-01 08:55:28 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
echo Updating hub
|
|
|
|
/usr/bin/cscli hub update
|
2022-02-01 08:55:28 +00:00
|
|
|
if [ "$COLLECTIONS" = true ]; then
|
2021-08-18 11:57:06 +00:00
|
|
|
set +e
|
|
|
|
CSCLI_BIN_INSTALLED="/usr/bin/cscli" SILENT=true install_collection
|
|
|
|
set -e
|
2022-02-01 08:55:28 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-17 15:04:01 +00:00
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
if [[ -f /var/lib/crowdsec/data/crowdsec.db.backup ]]; then
|
|
|
|
cp /var/lib/crowdsec/data/crowdsec.db.backup /var/lib/crowdsec/data/crowdsec.db
|
|
|
|
rm -f /var/lib/crowdsec/data/crowdsec.db.backup
|
|
|
|
fi
|
|
|
|
|
|
|
|
systemctl --quiet is-enabled crowdsec || systemctl unmask crowdsec && systemctl enable crowdsec
|
|
|
|
|
2022-03-10 12:57:04 +00:00
|
|
|
API=$(cscli config show --key "Config.API.Server")
|
2023-12-19 20:46:34 +00:00
|
|
|
if [ "$API" = "nil" ] ; then
|
2022-03-10 12:57:04 +00:00
|
|
|
LAPI=false
|
|
|
|
else
|
|
|
|
PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2)
|
|
|
|
fi
|
|
|
|
if [ "$LAPI" = false ] || [ -z "$(ss -nlt "sport = ${PORT}" | grep -v ^State)" ] ; then
|
2021-08-18 11:57:06 +00:00
|
|
|
systemctl start crowdsec
|
|
|
|
else
|
2022-02-15 10:20:52 +00:00
|
|
|
echo "Not attempting to start crowdsec, port ${PORT} is already used or lapi was disabled"
|
2021-08-18 11:57:06 +00:00
|
|
|
echo "This port is configured through /etc/crowdsec/config.yaml and /etc/crowdsec/local_api_credentials.yaml"
|
|
|
|
fi
|
2023-12-20 08:44:10 +00:00
|
|
|
|
|
|
|
echo "Get started with CrowdSec:"
|
|
|
|
echo " * Detailed guides are available in our documentation: https://docs.crowdsec.net"
|
|
|
|
echo " * Configuration items created by the community can be found at the Hub: https://hub.crowdsec.net"
|
|
|
|
echo " * Gain insights into your use of CrowdSec with the help of the console https://app.crowdsec.net"
|
|
|
|
|
|
|
|
|
2021-08-18 11:57:06 +00:00
|
|
|
fi
|
|
|
|
|
2023-12-13 14:43:46 +00:00
|
|
|
echo "You can always run the configuration again interactively by using '/usr/share/crowdsec/wizard.sh -c'"
|