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>
Mon, 3 May 2021 07:29:06 +0000 (08:29 +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 28172ae4ea29e56539e71a4272fa8a638dc5739e..584bb5cf1bbb06691bec022904dfe75c26835915 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "fmt"
+       "os/exec"
 
        "github.com/crowdsecurity/crowdsec/pkg/cwhub"
 
@@ -77,6 +78,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 := cwhub.UpdateHubIdx(csConfig.Cscli); err != nil {
                                log.Fatalf("Failed to get Hub index : %v", err)
                        }