From e14f6756c9991c4f4b2fc089bfb085bdb65b5d22 Mon Sep 17 00:00:00 2001 From: Timothy Date: Tue, 22 Jun 2021 17:44:36 +0800 Subject: [PATCH] fix: init SSH path if it doesn't exist --- cmd/skm/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/skm/main.go b/cmd/skm/main.go index d442fd0..563eec2 100644 --- a/cmd/skm/main.go +++ b/cmd/skm/main.go @@ -8,6 +8,7 @@ import ( "path/filepath" "github.com/TimothyYe/skm" + "github.com/fatih/color" cli "gopkg.in/urfave/cli.v1" ) @@ -59,6 +60,17 @@ func mustGetEnvironment(ctx *cli.Context) *skm.Environment { if storePath == "" || sshPath == "" { log.Fatalf("store-path (%v) and ssh-path (%v) have to be set!", storePath, sshPath) } + + // create SSH path if it doesn't exist + if _, err := os.Stat(sshPath); os.IsNotExist(err) { + err := os.Mkdir(sshPath, 0755) + + if err != nil { + color.Red("%sFailed to initialize SSH path!", skm.CrossSymbol) + return nil + } + } + if resticPath == "" { resticPath, _ = exec.LookPath("restic") }