FreeBSD changes () ()

* FreeBSD changes ()

* Update build Makefile to be able to build on other platforms

Split Makefiles to isolate every specifics per platform if specific file
is not found, the include will default to linux.

* Isolate linux specific messages emitted by crowdsec command line

On other platforms, we shouldn't write messages with `systemctl`
occurrences. This commit isolate the specific messages and ensure the
messages are relevant for the given platform according result of `GOOS`.

* remove the test

Co-authored-by: Sofian Brabez <sbz@6dev.net>
Co-authored-by: AlteredCoder <AlteredCoder>
This commit is contained in:
AlteredCoder 2021-03-26 17:42:56 +01:00 committed by GitHub
parent 5ad7e9e729
commit 20ccb32124
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 54 additions and 9 deletions

View file

@ -1,3 +1,12 @@
ROOT= $(shell git rev-parse --show-toplevel)
SYSTEM = $(shell uname -s | tr '[A-Z]' '[a-z]')
ifneq ("$(wildcard $(ROOT)/platform/$(SYSTEM).mk)", "")
include $(ROOT)/platform/$(SYSTEM).mk
else
include $(ROOT)/platform/linux.mk
endif
PREFIX?="/tmp/crowdsec/"
CFG_PREFIX = $(PREFIX)"/etc/crowdsec/"
BIN_PREFIX = $(PREFIX)"/usr/local/bin/"
@ -9,10 +18,8 @@ CSCLI_FOLDER = "./cmd/crowdsec-cli/"
CROWDSEC_BIN = "crowdsec"
CSCLI_BIN = "cscli"
BUILD_CMD = "build"
MAKE = "make"
GOARCH=amd64
GOOS=linux
#Golang version info
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)

View file

@ -99,7 +99,7 @@ func NewCapiCmd() *cobra.Command {
fmt.Printf("%s\n", string(apiConfigDump))
}
log.Warningf("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective")
log.Warningf(ReloadMessage())
},
}
cmdCapiRegister.Flags().StringVarP(&outputFile, "file", "f", "", "output file destination")

View file

@ -40,7 +40,7 @@ func NewCollectionsCmd() *cobra.Command {
if cmd.Name() == "inspect" || cmd.Name() == "list" {
return
}
log.Infof("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective.")
log.Infof(ReloadMessage())
},
}

View file

@ -115,7 +115,7 @@ Keep in mind the machine needs to be validated by an administrator on LAPI side
} else {
fmt.Printf("%s\n", string(apiConfigDump))
}
log.Warningf("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective")
log.Warningf(ReloadMessage())
},
}
cmdLapiRegister.Flags().StringVarP(&apiURL, "url", "u", "", "URL of the API (ie. http://127.0.0.1)")

View file

@ -0,0 +1,25 @@
package main
import (
"fmt"
"runtime"
)
const (
ReloadMessageFormat = `Run '%s' for the new configuration to be effective.`
ReloadCmdLinux = `sudo systemctl reload crowdsec`
ReloadCmdFreebsd = `sudo service crowdsec reload`
)
func ReloadMessage() string {
var reloadCmd string
if runtime.GOOS == "freebsd" {
reloadCmd = ReloadCmdFreebsd
} else {
reloadCmd = ReloadCmdLinux
}
return fmt.Sprintf(ReloadMessageFormat, reloadCmd)
}

View file

@ -43,7 +43,7 @@ cscli parsers remove crowdsecurity/sshd-logs
if cmd.Name() == "inspect" || cmd.Name() == "list" {
return
}
log.Infof("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective.")
log.Infof(ReloadMessage())
},
}

View file

@ -42,7 +42,7 @@ func NewPostOverflowsCmd() *cobra.Command {
if cmd.Name() == "inspect" || cmd.Name() == "list" {
return
}
log.Infof("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective.")
log.Infof(ReloadMessage())
},
}

View file

@ -43,7 +43,7 @@ cscli scenarios remove crowdsecurity/ssh-bf
if cmd.Name() == "inspect" || cmd.Name() == "list" {
return
}
log.Infof("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective.")
log.Infof(ReloadMessage())
},
}

View file

@ -118,7 +118,7 @@ cscli simulation disable crowdsecurity/ssh-bf`,
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if cmd.Name() != "status" {
log.Infof("Run 'sudo systemctl reload crowdsec' for the new configuration to be effective.")
log.Infof(ReloadMessage())
}
},
}

7
platform/freebsd.mk Normal file
View file

@ -0,0 +1,7 @@
# FreeBSD specific
#
Make=gmake
GOOS=freebsd
$(warning Building for freebsd)

6
platform/linux.mk Normal file
View file

@ -0,0 +1,6 @@
# Linux specific
MAKE=make
GOOS=linux
$(warning Building for linux)