post-install: reduce verbosity (#2751)

* post install: avoid message "no such file or directory" when looking for logs
* post install: avoid info and warning messages when registering to capi
* lint (backtick)
This commit is contained in:
mmetc 2024-01-18 09:20:52 +01:00 committed by GitHub
parent 5d0d5ac9c9
commit fa8d5b6992
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 8 deletions

2
debian/postinst vendored
View file

@ -61,7 +61,7 @@ if [ "$1" = configure ]; then
[ -s /etc/crowdsec/local_api_credentials.yaml ] || cscli machines add -a --force --error [ -s /etc/crowdsec/local_api_credentials.yaml ] || cscli machines add -a --force --error
if [ "$CAPI" = true ]; then if [ "$CAPI" = true ]; then
cscli capi register cscli capi register --error
fi fi
else else

View file

@ -169,7 +169,7 @@ if [ $1 == 1 ]; then
fi fi
if [ ! -f "%{_sysconfdir}/crowdsec/online_api_credentials.yaml" ] ; then if [ ! -f "%{_sysconfdir}/crowdsec/online_api_credentials.yaml" ] ; then
install -m 600 /dev/null /etc/crowdsec/online_api_credentials.yaml install -m 600 /dev/null /etc/crowdsec/online_api_credentials.yaml
cscli capi register cscli capi register --error
fi fi
if [ ! -f "%{_sysconfdir}/crowdsec/local_api_credentials.yaml" ] ; then if [ ! -f "%{_sysconfdir}/crowdsec/local_api_credentials.yaml" ] ; then
install -m 600 /dev/null /etc/crowdsec/local_api_credentials.yaml install -m 600 /dev/null /etc/crowdsec/local_api_credentials.yaml

View file

@ -130,9 +130,9 @@ detect_services () {
DETECTED_SERVICES=() DETECTED_SERVICES=()
HMENU=() HMENU=()
# list systemd services # list systemd services
SYSTEMD_SERVICES=`systemctl --state=enabled list-unit-files '*.service' | cut -d ' ' -f1` SYSTEMD_SERVICES=$(systemctl --state=enabled list-unit-files '*.service' | cut -d ' ' -f1)
# raw ps # raw ps
PSAX=`ps ax -o comm=` PSAX=$(ps ax -o comm=)
for SVC in ${SUPPORTED_SERVICES} ; do for SVC in ${SUPPORTED_SERVICES} ; do
log_dbg "Checking if service '${SVC}' is running (ps+systemd)" log_dbg "Checking if service '${SVC}' is running (ps+systemd)"
for SRC in "${SYSTEMD_SERVICES}" "${PSAX}" ; do for SRC in "${SYSTEMD_SERVICES}" "${PSAX}" ; do
@ -191,7 +191,6 @@ log_locations[linux]='/var/log/syslog,/var/log/kern.log,/var/log/messages'
# $1 is service name, such those in SUPPORTED_SERVICES # $1 is service name, such those in SUPPORTED_SERVICES
find_logs_for() { find_logs_for() {
ret=""
x=${1} x=${1}
# we have trailing and starting quotes because of whiptail # we have trailing and starting quotes because of whiptail
SVC="${x%\"}" SVC="${x%\"}"
@ -209,7 +208,7 @@ find_logs_for() {
# Split /var/log/nginx/*.log into '/var/log/nginx' and '*.log' so we can use find # Split /var/log/nginx/*.log into '/var/log/nginx' and '*.log' so we can use find
path=${poss_path%/*} path=${poss_path%/*}
fname=${poss_path##*/} fname=${poss_path##*/}
candidates=`find "${path}" -type f -mtime -5 -ctime -5 -name "$fname"` candidates=$(find "${path}" -type f -mtime -5 -ctime -5 -name "$fname" 2>/dev/null)
# We have some candidates, add them # We have some candidates, add them
for final_file in ${candidates} ; do for final_file in ${candidates} ; do
log_dbg "Found logs file for '${SVC}': ${final_file}" log_dbg "Found logs file for '${SVC}': ${final_file}"
@ -713,8 +712,7 @@ main() {
${CSCLI_BIN_INSTALLED} machines add --force "$(cat /etc/machine-id)" -a -f "${CROWDSEC_CONFIG_PATH}/${CLIENT_SECRETS}" || log_fatal "unable to add machine to the local API" ${CSCLI_BIN_INSTALLED} machines add --force "$(cat /etc/machine-id)" -a -f "${CROWDSEC_CONFIG_PATH}/${CLIENT_SECRETS}" || log_fatal "unable to add machine to the local API"
log_dbg "Crowdsec LAPI registered" log_dbg "Crowdsec LAPI registered"
${CSCLI_BIN_INSTALLED} capi register || log_fatal "unable to register to the Central API" ${CSCLI_BIN_INSTALLED} capi register --error || log_fatal "unable to register to the Central API"
log_dbg "Crowdsec CAPI registered"
systemctl enable -q crowdsec >/dev/null || log_fatal "unable to enable crowdsec" systemctl enable -q crowdsec >/dev/null || log_fatal "unable to enable crowdsec"
systemctl start crowdsec >/dev/null || log_fatal "unable to start crowdsec" systemctl start crowdsec >/dev/null || log_fatal "unable to start crowdsec"