Hub auto update cronjob (#1817)

Add hub cron installation to install scripts

Plus remove on uninstall
This commit is contained in:
Laurence Jones 2022-10-17 16:04:01 +01:00 committed by GitHub
parent ec0d2a5ed2
commit 0ecb6dcd4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 1 deletions

2
debian/postinst vendored
View file

@ -82,6 +82,8 @@ if [ "$1" = configure ]; then
set -e
fi
install_cronjob
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

3
debian/postrm vendored
View file

@ -1,4 +1,7 @@
if [ "$1" = "purge" ]; then
find /etc/crowdsec -maxdepth 1 -mindepth 1 | grep -v "bouncer" | xargs rm -rf || echo ""
rm -rf /var/lib/crowdsec
if [[ -d /etc/cron.daily/ ]] && [[ -f /etc/cron.daily/crowdsec-hub ]]; then
rm /etc/cron.daily/crowdsec-hub
fi
fi

View file

@ -175,6 +175,7 @@ if [ $1 == 1 ]; then
fi
cscli hub update
install_cronjob
CSCLI_BIN_INSTALLED="/usr/bin/cscli" SILENT=true install_collection
#upgrade
@ -227,6 +228,10 @@ if [ $1 == 0 ]; then
rm -rf /etc/crowdsec/hub
fi
if [[ -d /etc/cron.daily/ ]] && [[ -f /etc/cron.daily/crowdsec-hub ]]; then
rm /etc/cron.daily/crowdsec-hub
fi
#systemctl stop crowdsec || echo "crowdsec was not started"
%changelog

View file

@ -68,6 +68,7 @@ telnet
smb
'
CRON_NAME=/etc/cron.daily/crowdsec-hub
HTTP_PLUGIN_BINARY="./plugins/notifications/http/notification-http"
SLACK_PLUGIN_BINARY="./plugins/notifications/slack/notification-slack"
@ -552,6 +553,22 @@ uninstall_crowdsec() {
log_info "crowdsec successfully uninstalled"
}
install_cronjob() {
log_info "Installing Hub Cronjob"
if [[ -d /etc/cron.daily/ ]] && [[ ! -f $CRON_NAME ]]; then
echo "/usr/bin/cscli hub update" >> $CRON_NAME
echo "/usr/bin/cscli hub upgrade" >> $CRON_NAME
chmod 755 $CRON_NAME
fi
}
uninstall_cronjob() {
if [[ -d /etc/cron.daily/ ]] && [[ -f $CRON_NAME ]]; then
log_info "Uninstall Hub Cronjob"
rm $CRON_NAME
fi
}
function show_link {
echo ""
@ -618,6 +635,7 @@ main() {
${CSCLI_BIN_INSTALLED} hub update
install_collection
genacquisition
install_cronjob
if ! skip_tmp_acquis; then
mv "${TMP_ACQUIS_FILE}" "${ACQUIS_TARGET}"
fi
@ -638,6 +656,7 @@ main() {
fi
check_running_bouncers
uninstall_crowdsec
uninstall_cronjob
return
fi
@ -692,7 +711,8 @@ main() {
mkdir -p "${PATTERNS_PATH}"
cp "./${PATTERNS_FOLDER}/"* "${PATTERNS_PATH}/"
# install hub cronjob
install_cronjob
# api register
${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"