diff --git a/debian/postinst b/debian/postinst index 976179dca..fca546cae 100644 --- a/debian/postinst +++ b/debian/postinst @@ -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 diff --git a/debian/postrm b/debian/postrm index 61a95eed2..1e1a4d5c3 100644 --- a/debian/postrm +++ b/debian/postrm @@ -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 diff --git a/rpm/SPECS/crowdsec.spec b/rpm/SPECS/crowdsec.spec index 14c66e879..618c9124d 100644 --- a/rpm/SPECS/crowdsec.spec +++ b/rpm/SPECS/crowdsec.spec @@ -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 diff --git a/wizard.sh b/wizard.sh index 353e22a20..b4ae1e8f6 100755 --- a/wizard.sh +++ b/wizard.sh @@ -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"