From a67e12f98dcd5138ebb0a5a917d72091ce2c0ab9 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Fri, 27 Apr 2018 10:43:19 +0200 Subject: [PATCH] Create wirey folder if not exists - fixes #5 Signed-off-by: Lorenzo Fontana --- cmd/wirey/root.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/wirey/root.go b/cmd/wirey/root.go index 721fbb4..26d8b3a 100644 --- a/cmd/wirey/root.go +++ b/cmd/wirey/root.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "path/filepath" "strings" "github.com/influxdata/wirey/backend" @@ -32,6 +33,13 @@ var rootCmd = &cobra.Command{ log.Fatal(err) } + privKeyBaseDir := filepath.Dir(privateKeyPath) + if _, err := os.Stat(privKeyBaseDir); os.IsNotExist(err) { + if err := os.Mkdir(privKeyBaseDir, 0600); err != nil { + log.Fatal("Unable to create the base directory for the wirey private key: %s - %s", privKeyBaseDir, err.Error()) + } + } + i, err := backend.NewInterface(b, ifname, fmt.Sprintf("%s:%s", endpoint, endpointPort), ipAddr, privateKeyPath) if err != nil {