From 12e11649409564968a9c87e483e84346d99a856b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Tue, 2 Mar 2021 20:24:09 +0100 Subject: [PATCH] Create the LaunchAgents directory if it does not exist (#237) * Create the LaunchAgents directory if it does not exist Fixes: https://github.com/ooni/probe/issues/1368 * Update cmd/ooniprobe/internal/autorun/autorun_darwin.go Co-authored-by: Simone Basso Co-authored-by: Simone Basso --- cmd/ooniprobe/internal/autorun/autorun_darwin.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/ooniprobe/internal/autorun/autorun_darwin.go b/cmd/ooniprobe/internal/autorun/autorun_darwin.go index c6d6caf..80225f3 100644 --- a/cmd/ooniprobe/internal/autorun/autorun_darwin.go +++ b/cmd/ooniprobe/internal/autorun/autorun_darwin.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "strconv" "strings" "text/template" @@ -20,7 +21,8 @@ import ( type managerDarwin struct{} var ( - plistPath = os.ExpandEnv("$HOME/Library/LaunchAgents/org.ooni.cli.plist") + plistDir = os.ExpandEnv("$HOME/Library/LaunchAgents/") + plistPath = filepath.Join(plistDir, "org.ooni.cli.plist") domainTarget = fmt.Sprintf("gui/%d", os.Getuid()) serviceTarget = fmt.Sprintf("%s/org.ooni.cli", domainTarget) ) @@ -107,6 +109,10 @@ func (managerDarwin) writePlist() error { if err := t.Execute(&out, in); err != nil { return err } + log.Infof("exec: mkdir -p %s", plistDir) + if err := os.MkdirAll(plistDir, 0755); err != nil { + return err + } log.Infof("exec: writePlist(%s)", plistPath) return ioutil.WriteFile(plistPath, out.Bytes(), 0644) }