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:
parent
21ef7a6610
commit
003233d60d
|
@ -1,3 +1,2 @@
|
||||||
bloat
|
bloat
|
||||||
database
|
database
|
||||||
bloat.def.conf
|
|
||||||
|
|
12
INSTALL
12
INSTALL
|
@ -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
|
||||||
|
|
13
Makefile
13
Makefile
|
@ -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
4
README
|
@ -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.
|
||||||
|
|
|
@ -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) {
|
||||||
|
var lastErr error
|
||||||
|
for _, file := range files {
|
||||||
f, err := os.Open(file)
|
f, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
lastErr = err
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
info, err := f.Stat()
|
info, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
lastErr = err
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
return nil, errors.New("invalid config file")
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return Parse(f)
|
return Parse(f)
|
||||||
|
}
|
||||||
|
if lastErr == nil {
|
||||||
|
lastErr = errors.New("invalid config file")
|
||||||
|
}
|
||||||
|
return nil, lastErr
|
||||||
}
|
}
|
||||||
|
|
6
main.go
6
main.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue