config: specify sharedir during build
We should use the Makefile value of SHAREDIR when searching for config files and templates etc. This is important for systems which do not use the standard file hierarchy or which do not have a consistent location for installing program files, for example NixOS, which will have a different install location with every update. Signed-off-by: Daniel Patterson <me@danielpatterson.dev> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
7e6c0d2e6e
commit
0cfffaef54
5 changed files with 60 additions and 15 deletions
1
Makefile
1
Makefile
|
@ -11,6 +11,7 @@ MANDIR?=$(PREFIX)/share/man
|
||||||
GO?=go
|
GO?=go
|
||||||
GOFLAGS?=
|
GOFLAGS?=
|
||||||
LDFLAGS+=-X main.Version=$(VERSION)
|
LDFLAGS+=-X main.Version=$(VERSION)
|
||||||
|
LDFLAGS+=-X git.sr.ht/~rjarry/aerc/config.shareDir=$(SHAREDIR)
|
||||||
|
|
||||||
GOSRC!=find * -name '*.go'
|
GOSRC!=find * -name '*.go'
|
||||||
GOSRC+=go.mod go.sum
|
GOSRC+=go.mod go.sum
|
||||||
|
|
19
README.md
19
README.md
|
@ -64,6 +64,25 @@ To install aerc locally:
|
||||||
|
|
||||||
# make install
|
# make install
|
||||||
|
|
||||||
|
By default, aerc will install config files to directories under `/usr/local/aerc`,
|
||||||
|
and will search for templates and stylesets in these locations in order:
|
||||||
|
|
||||||
|
- `${XDG_CONFIG_HOME:-~/.config}/aerc`
|
||||||
|
- `${XDG_DATA_HOME:-~/.local/share}/aerc`
|
||||||
|
- `/usr/local/share/aerc`
|
||||||
|
- `/usr/share/aerc`
|
||||||
|
|
||||||
|
At build time it is possible to add an extra location to this list and to use
|
||||||
|
that location as the default install location for config files by setting the
|
||||||
|
`PREFIX` option like so:
|
||||||
|
|
||||||
|
# make PREFIX=/custom/location
|
||||||
|
# make install PREFIX=/custom/location
|
||||||
|
|
||||||
|
This will install templates and other config files to `/custom/location/share/aerc`,
|
||||||
|
and man pages to `/custom/location/share/man`. This extra location will have lower
|
||||||
|
priority than the XDG locations but higher than the fixed paths.
|
||||||
|
|
||||||
## Contribution Quick Start
|
## Contribution Quick Start
|
||||||
|
|
||||||
Anyone can contribute to aerc. First you need to clone the repository and build
|
Anyone can contribute to aerc. First you need to clone the repository and build
|
||||||
|
|
|
@ -105,8 +105,8 @@ next-message-on-delete=true
|
||||||
# list of directories. If this is unset or if a styleset cannot be found, the
|
# list of directories. If this is unset or if a styleset cannot be found, the
|
||||||
# following paths will be used as a fallback in that order:
|
# following paths will be used as a fallback in that order:
|
||||||
#
|
#
|
||||||
# ~/.config/aerc/stylesets
|
# ${XDG_CONFIG_HOME:-~/.config}/aerc/stylesets
|
||||||
# ~/.local/share/aerc/stylesets
|
# ${XDG_DATA_HOME:-~/.local/share}/aerc/stylesets
|
||||||
# /usr/local/share/aerc/stylesets
|
# /usr/local/share/aerc/stylesets
|
||||||
# /usr/share/aerc/stylesets
|
# /usr/share/aerc/stylesets
|
||||||
#
|
#
|
||||||
|
@ -251,8 +251,8 @@ new-email=
|
||||||
# list of directories. If this is unset or if a template cannot be found, the
|
# list of directories. If this is unset or if a template cannot be found, the
|
||||||
# following paths will be used as a fallback in that order:
|
# following paths will be used as a fallback in that order:
|
||||||
#
|
#
|
||||||
# ~/.config/aerc/templates
|
# ${XDG_CONFIG_HOME:-~/.config}/aerc/templates
|
||||||
# ~/.local/share/aerc/templates
|
# ${XDG_DATA_HOME:-~/.local/share}/aerc/templates
|
||||||
# /usr/local/share/aerc/templates
|
# /usr/local/share/aerc/templates
|
||||||
# /usr/share/aerc/templates
|
# /usr/share/aerc/templates
|
||||||
#
|
#
|
||||||
|
|
|
@ -297,13 +297,38 @@ func parseCredential(cred, command string) (string, error) {
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultDirs []string = []string{
|
// Set at build time
|
||||||
path.Join(xdg.ConfigHome(), "aerc"),
|
var shareDir string
|
||||||
path.Join(xdg.DataHome(), "aerc"),
|
|
||||||
"/usr/local/share/aerc",
|
func buildDefaultDirs() []string {
|
||||||
"/usr/share/aerc",
|
var defaultDirs []string
|
||||||
|
|
||||||
|
prefixes := []string{
|
||||||
|
xdg.ConfigHome(),
|
||||||
|
xdg.DataHome(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add XDG_CONFIG_HOME and XDG_DATA_HOME
|
||||||
|
for _, v := range prefixes {
|
||||||
|
if v != "" {
|
||||||
|
defaultDirs = append(defaultDirs, path.Join(v, "aerc"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add custom buildtime shareDir
|
||||||
|
if shareDir != "" && shareDir != "/usr/local/share/aerc" {
|
||||||
|
defaultDirs = append(defaultDirs, shareDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add fixed fallback locations
|
||||||
|
defaultDirs = append(defaultDirs, "/usr/local/share/aerc")
|
||||||
|
defaultDirs = append(defaultDirs, "/usr/share/aerc")
|
||||||
|
|
||||||
|
return defaultDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var searchDirs = buildDefaultDirs()
|
||||||
|
|
||||||
func installTemplate(root, name string) error {
|
func installTemplate(root, name string) error {
|
||||||
var err error
|
var err error
|
||||||
if _, err = os.Stat(root); os.IsNotExist(err) {
|
if _, err = os.Stat(root); os.IsNotExist(err) {
|
||||||
|
@ -313,7 +338,7 @@ func installTemplate(root, name string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var data []byte
|
var data []byte
|
||||||
for _, dir := range defaultDirs {
|
for _, dir := range searchDirs {
|
||||||
data, err = ioutil.ReadFile(path.Join(dir, name))
|
data, err = ioutil.ReadFile(path.Join(dir, name))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
|
@ -464,7 +489,7 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// append default paths to template-dirs and styleset-dirs
|
// append default paths to template-dirs and styleset-dirs
|
||||||
for _, dir := range defaultDirs {
|
for _, dir := range searchDirs {
|
||||||
config.Ui.StyleSetDirs = append(
|
config.Ui.StyleSetDirs = append(
|
||||||
config.Ui.StyleSetDirs, path.Join(dir, "stylesets"),
|
config.Ui.StyleSetDirs, path.Join(dir, "stylesets"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -219,8 +219,8 @@ These options are configured in the *[ui]* section of aerc.conf.
|
||||||
be found, the following paths will be used as a fallback in that order:
|
be found, the following paths will be used as a fallback in that order:
|
||||||
|
|
||||||
```
|
```
|
||||||
~/.config/aerc/stylesets
|
${XDG_CONFIG_HOME:-~/.config}/aerc/stylesets
|
||||||
~/.local/share/aerc/stylesets
|
${XDG_DATA_HOME:-~/.local/share}/aerc/stylesets
|
||||||
/usr/local/share/aerc/stylesets
|
/usr/local/share/aerc/stylesets
|
||||||
/usr/share/aerc/stylesets
|
/usr/share/aerc/stylesets
|
||||||
```
|
```
|
||||||
|
@ -417,8 +417,8 @@ These options are configured in the *[templates]* section of aerc.conf.
|
||||||
be found, the following paths will be used as a fallback in that order:
|
be found, the following paths will be used as a fallback in that order:
|
||||||
|
|
||||||
```
|
```
|
||||||
~/.config/aerc/templates
|
${XDG_CONFIG_HOME:-~/.config}/aerc/templates
|
||||||
~/.local/share/aerc/templates
|
${XDG_DATA_HOME:-~/.local/share}/aerc/templates
|
||||||
/usr/local/share/aerc/templates
|
/usr/local/share/aerc/templates
|
||||||
/usr/share/aerc/templates
|
/usr/share/aerc/templates
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue