22systemctl daemon-reload
33
44
5- START=0
5+ API_KEY_REQUIRED=true
66BOUNCER_CONFIG_PATH=" /etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf"
77API_KEY=" <API_KEY>"
88CROWDSEC_LAPI_URL=" <LAPI_URL>"
@@ -14,9 +14,9 @@ check_lua_dependency() {
1414 )
1515 for dep in ${DEPENDENCY[@]} ;
1616 do
17- opm list | grep ${dep} > /dev/null
17+ opm list | grep " ${dep} " > /dev/null
1818 if [[ $? != 0 ]]; then
19- opm get ${dep} > /dev/null && echo " ${dep} successfully installed"
19+ opm get " ${dep} " > /dev/null && echo " ${dep} successfully installed"
2020 fi
2121 done
2222}
@@ -31,43 +31,44 @@ if [ "$1" = "configure" ]; then
3131 if [ " $2 " != " " ] ; then
3232 echo " Upgrading, check if there is bouncer configuration"
3333 if [ -f " ${BOUNCER_CONFIG_PATH} " ] ; then
34- START=2
34+ API_KEY_REQUIRED=false
3535 fi
3636 fi
37- if [ ${START} -eq 0 ] ; then
38- START=1
37+ API=$( cscli config show --key " Config.API.Server" )
38+ if [ " $API " = " nil" ] || [ " $API " = " <nil>" ] ; then
39+ API_KEY_REQUIRED=false
40+ fi
41+ if [ ${API_KEY_REQUIRED} = true ] ; then
3942 echo " cscli/crowdsec is present, generating API key"
40- unique=` date +%s`
41- API_KEY=` cscli -oraw bouncers add crowdsec-openresty-bouncer-${unique} `
43+ unique=$( date +%s)
44+ API_KEY=$( cscli -oraw bouncers add crowdsec-openresty-bouncer-" ${unique} " )
4245 PORT=$( cscli config show --key " Config.API.Server.ListenURI" | cut -d " :" -f2)
4346 if [ ! -z " $PORT " ]; then
4447 LAPI_DEFAULT_PORT=${PORT}
4548 fi
4649 CROWDSEC_LAPI_URL=" http://127.0.0.1:${LAPI_DEFAULT_PORT} "
4750 if [ $? -eq 1 ] ; then
48- echo " failed to create API token, service won't be started ."
49- START=0
51+ echo " failed to create API key ."
52+ API_KEY_REQUIRED=true
5053 API_KEY=" <API_KEY>"
5154 else
5255 echo " API Key : ${API_KEY} "
56+ TMP=$( mktemp -p /tmp/)
57+ cp ${BOUNCER_CONFIG_PATH} " ${TMP} "
58+ API_KEY=${API_KEY} CROWDSEC_LAPI_URL=${CROWDSEC_LAPI_URL} envsubst < " ${TMP} " > ${BOUNCER_CONFIG_PATH}
59+ rm " ${TMP} "
5360 fi
5461 fi
5562 fi
5663
57- TMP=` mktemp -p /tmp/`
58- cp ${BOUNCER_CONFIG_PATH} ${TMP}
59- API_KEY=${API_KEY} CROWDSEC_LAPI_URL=${CROWDSEC_LAPI_URL} envsubst < ${TMP} > ${BOUNCER_CONFIG_PATH}
60- rm ${TMP}
61-
6264 check_lua_dependency
63-
6465 echo " Add 'include /usr/local/openresty/nginx/conf/conf.d/crowdsec_openresty.conf;' in your nginx configuration file to enable the bouncer."
6566
6667else
67- START=1
68+ API_KEY_REQUIRED=false
6869fi
6970
70- if [ ${START} -eq 0 ] ; then
71+ if [ ${API_KEY_REQUIRED} = true ] ; then
7172 echo " Can't generate an API key for the bouncer. Please do it manually"
7273fi
7374
0 commit comments