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

View File

@ -14,17 +14,11 @@ SRC=main.go \
service/*.go \ service/*.go \
util/*.go \ util/*.go \
all: bloat bloat.def.conf all: bloat
bloat: $(SRC) $(TMPL) bloat: $(SRC) $(TMPL)
$(GO) build $(GOFLAGS) -o bloat main.go $(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 install: bloat
mkdir -p $(DESTDIR)$(BINPATH) \ mkdir -p $(DESTDIR)$(BINPATH) \
$(DESTDIR)$(SHAREPATH)/templates \ $(DESTDIR)$(SHAREPATH)/templates \
@ -35,6 +29,10 @@ install: bloat
chmod 0644 $(DESTDIR)$(SHAREPATH)/templates/* chmod 0644 $(DESTDIR)$(SHAREPATH)/templates/*
cp -r static/* $(DESTDIR)$(SHAREPATH)/static cp -r static/* $(DESTDIR)$(SHAREPATH)/static
chmod 0644 $(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: uninstall:
rm -f $(DESTDIR)$(BINPATH)/bloat rm -f $(DESTDIR)$(BINPATH)/bloat
@ -42,4 +40,3 @@ uninstall:
clean: clean:
rm -f bloat 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 Typing make will build the binary
$ make $ 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 $ ed bloat.conf
Run the binary 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 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. 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 return
} }
func ParseFile(file string) (c *config, err error) { func ParseFiles(files []string) (c *config, err error) {
f, err := os.Open(file) var lastErr error
if err != nil { for _, file := range files {
return 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() if lastErr == nil {
lastErr = errors.New("invalid config file")
info, err := f.Stat()
if err != nil {
return
} }
return nil, lastErr
if info.IsDir() {
return nil, errors.New("invalid config file")
}
return Parse(f)
} }

View File

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