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 <bassosimone@gmail.com> Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
parent
322394fe63
commit
12e1164940
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
@ -20,7 +21,8 @@ import (
|
||||||
type managerDarwin struct{}
|
type managerDarwin struct{}
|
||||||
|
|
||||||
var (
|
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())
|
domainTarget = fmt.Sprintf("gui/%d", os.Getuid())
|
||||||
serviceTarget = fmt.Sprintf("%s/org.ooni.cli", domainTarget)
|
serviceTarget = fmt.Sprintf("%s/org.ooni.cli", domainTarget)
|
||||||
)
|
)
|
||||||
|
@ -107,6 +109,10 @@ func (managerDarwin) writePlist() error {
|
||||||
if err := t.Execute(&out, in); err != nil {
|
if err := t.Execute(&out, in); err != nil {
|
||||||
return err
|
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)
|
log.Infof("exec: writePlist(%s)", plistPath)
|
||||||
return ioutil.WriteFile(plistPath, out.Bytes(), 0644)
|
return ioutil.WriteFile(plistPath, out.Bytes(), 0644)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user