2020-11-30 09:37:17 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-09-10 12:59:22 +00:00
|
|
|
# Check if the container has already been started (ignore if agent is disabled)
|
|
|
|
if [ "$DISABLE_AGENT" == "" ] ; then
|
|
|
|
echo "Check if the container has already been started (ignore if agent is disabled)"
|
|
|
|
cscli machines list | grep localhost
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
cscli lapi register --machine localhost
|
|
|
|
fi
|
|
|
|
if [ "$AGENT_USERNAME" != "" ] && [ "$AGENT_PASSWORD" != "" ] && [ "$LOCAL_API_URL" != "" ] ; then
|
|
|
|
echo "set up lapi credentials for agent"
|
|
|
|
CONFIG_PATH=$(yq eval '.api.client.credentials_path' /etc/crowdsec/config.yaml)
|
|
|
|
echo "url: $LOCAL_API_URL" > $CONFIG_PATH
|
|
|
|
echo "login: $AGENT_USERNAME" >> $CONFIG_PATH
|
|
|
|
echo "password: $AGENT_PASSWORD" >> $CONFIG_PATH
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if lapi need to register automatically an agent
|
|
|
|
echo Check if lapi need to register automatically an agent
|
|
|
|
if [ "$DISABLE_LOCAL_API" == "" ] && [ "$AGENT_USERNAME" != "" ] && [ "$AGENT_PASSWORD" != "" ] ; then
|
|
|
|
echo registering agent $AGENT_USERNAME to lapi
|
|
|
|
echo AGENT PASSWORD : $AGENT_PASSWORD
|
|
|
|
cscli machines add $AGENT_USERNAME --password $AGENT_PASSWORD
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
|
|
|
|
2021-02-10 08:29:29 +00:00
|
|
|
# registration to online API for signal push
|
|
|
|
if [ "$DISABLE_ONLINE_API" == "" ] && [ "$CONFIG_FILE" == "" ] ; then
|
|
|
|
CONFIG_EXIST=$(yq eval '.api.server.online_client | has("credentials_path")' /etc/crowdsec/config.yaml)
|
|
|
|
if [ "$CONFIG_EXIST" != "true" ]; then
|
|
|
|
yq eval '.api.server.online_client = {"credentials_path": "/etc/crowdsec/online_api_credentials.yaml"}' /etc/crowdsec/config.yaml > /etc/crowdsec/config2.yaml
|
|
|
|
mv /etc/crowdsec/config2.yaml /etc/crowdsec/config.yaml
|
2020-11-30 09:37:17 +00:00
|
|
|
cscli capi register > /etc/crowdsec/online_api_credentials.yaml
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-02-25 10:29:39 +00:00
|
|
|
# crowdsec sqlite database permissions
|
|
|
|
if [ "$GID" != "" ]; then
|
|
|
|
IS_SQLITE=$(yq eval '.db_config.type == "sqlite"' /etc/crowdsec/config.yaml)
|
|
|
|
DB_PATH=$(yq eval '.db_config.db_path' /etc/crowdsec/config.yaml)
|
|
|
|
if [ "$IS_SQLITE" == "true" ]; then
|
|
|
|
chown :$GID $DB_PATH
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
## Install collections, parsers & scenarios
|
|
|
|
cscli hub update
|
2021-09-10 12:59:22 +00:00
|
|
|
cscli collections upgrade crowdsecurity/linux || true
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$COLLECTIONS" != "" ]; then
|
|
|
|
cscli collections install $COLLECTIONS
|
|
|
|
fi
|
|
|
|
if [ "$PARSERS" != "" ]; then
|
|
|
|
cscli parsers install $PARSERS
|
|
|
|
fi
|
|
|
|
if [ "$SCENARIOS" != "" ]; then
|
|
|
|
cscli scenarios install $SCENARIOS
|
|
|
|
fi
|
|
|
|
if [ "$POSTOVERFLOWS" != "" ]; then
|
|
|
|
cscli postoverflows install $POSTOVERFLOWS
|
|
|
|
fi
|
|
|
|
|
|
|
|
ARGS=""
|
|
|
|
if [ "$CONFIG_FILE" != "" ]; then
|
|
|
|
ARGS="-c $CONFIG_FILE"
|
|
|
|
fi
|
2021-06-29 16:03:45 +00:00
|
|
|
if [ "$DSN" != "" ]; then
|
|
|
|
ARGS="$ARGS -dsn ${DSN}"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
2021-06-29 16:03:45 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$TYPE" != "" ]; then
|
|
|
|
ARGS="$ARGS -type $TYPE"
|
|
|
|
fi
|
|
|
|
if [ "$TEST_MODE" == "true" ] || [ "$TEST_MODE" == "TRUE" ]; then
|
|
|
|
ARGS="$ARGS -t"
|
|
|
|
fi
|
|
|
|
if [ "$DISABLE_AGENT" == "true" ] || [ "$DISABLE_AGENT" == "TRUE" ]; then
|
|
|
|
ARGS="$ARGS -no-cs"
|
|
|
|
fi
|
2021-09-10 12:59:22 +00:00
|
|
|
if [ "$DISABLE_LOCAL_API" == "true" ] || [ "$DISABLE_LOCAL_API" == "TRUE" ]; then
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS="$ARGS -no-api"
|
|
|
|
fi
|
|
|
|
if [ "$LEVEL_TRACE" == "true" ] || [ "$LEVEL_TRACE" == "TRUE" ]; then
|
|
|
|
ARGS="$ARGS -trace"
|
|
|
|
fi
|
|
|
|
if [ "$LEVEL_DEBUG" == "true" ] || [ "$LEVEL_DEBUG" == "TRUE" ]; then
|
|
|
|
ARGS="$ARGS -debug"
|
|
|
|
fi
|
|
|
|
if [ "$LEVEL_INFO" == "true" ] || [ "$LEVEL_INFO" == "TRUE" ]; then
|
|
|
|
ARGS="$ARGS -info"
|
|
|
|
fi
|
|
|
|
|
2021-09-10 12:59:22 +00:00
|
|
|
exec crowdsec $ARGS
|