Automatically enable the online hub
authorCyril Brulebois <cyril@debamax.com>
Mon, 1 Mar 2021 20:40:04 +0000 (20:40 +0000)
committerCyril Brulebois <cyril@debamax.com>
Wed, 31 May 2023 16:54:17 +0000 (17:54 +0100)
By default, crowdsec comes with an offline copy of the hub (see
README.Debian). When running `cscli hub update`, ensure switching from
this offline copy to the online hub.

To ensure cscli doesn't disable anything that was configured (due to
symlinks from /etc/crowdsec becoming dangling all of a sudden), copy the
offline hub in the live directory (/var/lib/crowdsec/hub), and let
further operations (`cscli hub upgrade`, or `cscli <type> install`)
update the live directory as required.

Signed-off-by: Cyril Brulebois <cyril@debamax.com>
Gbp-Pq: Name 0007-automatically-enable-online-hub.patch

cmd/crowdsec-cli/hub.go

index 6b35eb6aab8c6b1f97aebf9283e9b38591d55a8d..39c51ba9f40767e70a9259bcd8e9dbb08db6fb65 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "fmt"
+       "os/exec"
 
        "github.com/fatih/color"
        log "github.com/sirupsen/logrus"
@@ -84,6 +85,12 @@ Fetches the [.index.json](https://github.com/crowdsecurity/hub/blob/master/.inde
                        return nil
                },
                Run: func(cmd *cobra.Command, args []string) {
+                       /* Make sure to move away from the offline hub (see README.Debian) */
+                       command := exec.Command("/var/lib/dpkg/info/crowdsec.postinst", "enable-online-hub")
+                       if err := command.Run(); err != nil {
+                               log.Printf("Enabling Online Hub failed with error: %v", err)
+                       }
+
                        if err := csConfig.LoadHub(); err != nil {
                                log.Fatal(err)
                        }