diff options
-rw-r--r-- | Makefile | 22 | ||||
-rw-r--r-- | aerc.go | 7 | ||||
-rw-r--r-- | config/config.go | 38 |
3 files changed, 53 insertions, 14 deletions
diff --git a/Makefile b/Makefile index 64ba7d1..5708845 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,15 @@ +PREFIX?=/usr/local +_INSTDIR=$(DESTDIR)$(PREFIX) +BINDIR?=$(_INSTDIR)/bin +SHAREDIR?=$(_INSTDIR)/share/aerc +MANDIR?=$(_INSTDIR)/share/man GOFLAGS?= aerc: - go build $(GOFLAGS) -o aerc + go build $(GOFLAGS) \ + -ldflags "-X main.Prefix=$(PREFIX)" \ + -ldflags "-X main.ShareDir=$(SHAREDIR)" \ + -o aerc %.1: doc/%.1.scd scdoc < $< > $@ @@ -19,17 +27,13 @@ DOCS := \ aerc-smtp.5 \ aerc-tutorial.7 -all: aerc $(DOCS) +doc: $(DOCS) + +all: aerc doc clean: rm -f *.1 *.5 aerc -PREFIX?=/usr/local -_INSTDIR=$(DESTDIR)$(PREFIX) -BINDIR?=$(_INSTDIR)/bin -SHAREDIR?=$(_INSTDIR)/share/aerc -MANDIR?=$(_INSTDIR)/share/man - install: all mkdir -p $(BINDIR) $(MANDIR)/man1 $(MANDIR)/man5 \ $(SHAREDIR) $(SHAREDIR)/filters @@ -47,4 +51,4 @@ install: all .DEFAULT_GOAL := all -.PHONY: aerc clean install +.PHONY: aerc all doc clean install diff --git a/aerc.go b/aerc.go index 6f794c6..22df069 100644 --- a/aerc.go +++ b/aerc.go @@ -47,6 +47,11 @@ func getCommands(selected libui.Drawable) []*commands.Commands { } } +var ( + Prefix string + ShareDir string +) + func main() { var ( logOut io.Writer @@ -60,7 +65,7 @@ func main() { logger = log.New(logOut, "", log.LstdFlags) logger.Println("Starting up aerc") - conf, err := config.LoadConfig(nil) + conf, err := config.LoadConfig(nil, ShareDir) if err != nil { fmt.Printf("Failed to load config: %v\n", err) os.Exit(1) diff --git a/config/config.go b/config/config.go index 1019297..1fb764b 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,7 @@ package config import ( "errors" "fmt" + "io/ioutil" "net/url" "os" "os/exec" @@ -189,7 +190,25 @@ func parseCredential(cred, command string) (string, error) { return u.String(), nil } -func LoadConfig(root *string) (*AercConfig, error) { +func installTemplate(root, sharedir, name string) error { + if _, err := os.Stat(root); os.IsNotExist(err) { + err := os.MkdirAll(root, 0755) + if err != nil { + return err + } + } + data, err := ioutil.ReadFile(path.Join(sharedir, name)) + if err != nil { + return err + } + err = ioutil.WriteFile(path.Join(root, name), data, 0644) + if err != nil { + return err + } + return nil +} + +func LoadConfig(root *string, sharedir string) (*AercConfig, error) { if root == nil { _root := path.Join(xdg.ConfigHome(), "aerc") root = &_root @@ -201,7 +220,12 @@ func LoadConfig(root *string) (*AercConfig, error) { filename = path.Join(*root, "aerc.conf") file, err := ini.Load(filename) if err != nil { - return nil, err + if err := installTemplate(*root, sharedir, "aerc.conf"); err != nil { + return nil, err + } + if file, err = ini.Load(filename); err != nil { + return nil, err + } } file.NameMapper = mapName config := &AercConfig{ @@ -291,9 +315,15 @@ func LoadConfig(root *string) (*AercConfig, error) { } else { config.Accounts = accounts } - binds, err := ini.Load(path.Join(*root, "binds.conf")) + filename = path.Join(*root, "binds.conf") + binds, err := ini.Load(filename) if err != nil { - return nil, err + if err := installTemplate(*root, sharedir, "binds.conf"); err != nil { + return nil, err + } + if binds, err = ini.Load(filename); err != nil { + return nil, err + } } groups := map[string]**KeyBindings{ "default": &config.Bindings.Global, |