Change config file lookup

- Look for both local and global config file
- Directly generate the global config file with make install
This commit is contained in:
r 2022-01-02 10:52:15 +00:00
parent 21ef7a6610
commit 003233d60d
6 changed files with 40 additions and 35 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
bloat
database
bloat.def.conf

12
INSTALL
View file

@ -15,12 +15,12 @@ This will perform a system wide installation of bloat. By default, it will
install the binary in /usr/local/bin and data files in /usr/local/share/bloat.
You can change these paths by editing the Makefile.
3. Edit and copy the config file
Edit the generated config file to you liking and then copy it to the default
config location. Comments in the config file describe what each config value
does. For most cases, you only need to change the value of "client_website".
$ $EDITOR bloat.def.conf
# cp bloat.def.conf /etc/bloat.conf
3. Edit the config file
bloat looks for a file named bloat.conf in the working directory and
/etc/bloat in that order. You can also specify another file by using the -f
flag. Comments in the config file describe what each config value does. For
most cases, you only need to change the value of "client_website".
# $EDITOR /etc/bloat.conf
4. Create database directory
Create a directory to store session information. Optionally, create a user

View file

@ -14,17 +14,11 @@ SRC=main.go \
service/*.go \
util/*.go \
all: bloat bloat.def.conf
all: bloat
bloat: $(SRC) $(TMPL)
$(GO) build $(GOFLAGS) -o bloat main.go
bloat.def.conf:
sed -e "s%=database%=/var/bloat%g" \
-e "s%=templates%=$(SHAREPATH)/templates%g" \
-e "s%=static%=$(SHAREPATH)/static%g" \
< bloat.conf > bloat.def.conf
install: bloat
mkdir -p $(DESTDIR)$(BINPATH) \
$(DESTDIR)$(SHAREPATH)/templates \
@ -35,6 +29,10 @@ install: bloat
chmod 0644 $(DESTDIR)$(SHAREPATH)/templates/*
cp -r static/* $(DESTDIR)$(SHAREPATH)/static
chmod 0644 $(DESTDIR)$(SHAREPATH)/static/*
sed -e "s%=database%=/var/bloat%g" \
-e "s%=templates%=$(SHAREPATH)/templates%g" \
-e "s%=static%=$(SHAREPATH)/static%g" \
< bloat.conf > /etc/bloat.conf
uninstall:
rm -f $(DESTDIR)$(BINPATH)/bloat
@ -42,4 +40,3 @@ uninstall:
clean:
rm -f bloat
rm -f bloat.def.conf

4
README
View file

@ -15,11 +15,11 @@ Building and Installation:
Typing make will build the binary
$ make
Edit the provided config file. See the bloat.conf file for more details.
Edit the default config file. See the bloat.conf file for more details.
$ ed bloat.conf
Run the binary
$ ./bloat -f bloat.conf
$ ./bloat
You can now access the frontend at http://127.0.0.1:8080, which is the default
listen address. See the INSTALL file for more details.

View file

@ -108,21 +108,30 @@ func Parse(r io.Reader) (c *config, err error) {
return
}
func ParseFile(file string) (c *config, err error) {
f, err := os.Open(file)
if err != nil {
return
func ParseFiles(files []string) (c *config, err error) {
var lastErr error
for _, file := range files {
f, err := os.Open(file)
if err != nil {
lastErr = err
if os.IsNotExist(err) {
continue
}
return nil, err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
lastErr = err
return nil, err
}
if info.IsDir() {
continue
}
return Parse(f)
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return
if lastErr == nil {
lastErr = errors.New("invalid config file")
}
if info.IsDir() {
return nil, errors.New("invalid config file")
}
return Parse(f)
return nil, lastErr
}

View file

@ -17,7 +17,7 @@ import (
)
var (
configFile = "/etc/bloat.conf"
configFiles = []string{"bloat.conf", "/etc/bloat.conf"}
)
func errExit(err error) {
@ -34,11 +34,11 @@ func main() {
for _, opt := range opts {
switch opt.Option {
case 'f':
configFile = opt.Value
configFiles = []string{opt.Value}
}
}
config, err := config.ParseFile(configFile)
config, err := config.ParseFiles(configFiles)
if err != nil {
errExit(err)
}