change - add default configuration paths

This commit is contained in:
shaerpour 2024-05-28 17:25:52 +03:30
parent e749217090
commit 4c94823e17
No known key found for this signature in database
2 changed files with 24 additions and 3 deletions

View file

@ -33,7 +33,7 @@ of wireproxy by [@juev](https://github.com/juev).
# Usage # Usage
``` ```
./wireproxy -c [path to config] ./wireproxy [-c path to config]
``` ```
``` ```
@ -47,6 +47,7 @@ Arguments:
-h --help Print help information -h --help Print help information
-c --config Path of configuration file -c --config Path of configuration file
Default paths: /etc/wireproxy/wireproxy.conf, $HOME/.config/wireproxy.conf
-s --silent Silent mode -s --silent Silent mode
-d --daemon Make wireproxy run in background -d --daemon Make wireproxy run in background
-i --info Specify the address and port for exposing health status -i --info Specify the address and port for exposing health status

View file

@ -22,6 +22,12 @@ import (
// an argument to denote that this process was spawned by -d // an argument to denote that this process was spawned by -d
const daemonProcess = "daemon-process" const daemonProcess = "daemon-process"
// default paths for wireproxy config file
var default_config_paths = []string {
"/etc/wireproxy/wireproxy.conf",
os.Getenv("HOME")+"/.config/wireproxy.conf",
}
var version = "1.0.8-dev" var version = "1.0.8-dev"
func panicIfError(err error) { func panicIfError(err error) {
@ -51,6 +57,16 @@ func executablePath() string {
return programPath return programPath
} }
// check if default config file paths exist
func configFilePath() (string, bool) {
for _, path := range default_config_paths {
if _, err := os.Stat(path); err == nil {
return path, true
}
}
return "", false
}
func lock(stage string) { func lock(stage string) {
switch stage { switch stage {
case "boot": case "boot":
@ -177,9 +193,13 @@ func main() {
} }
if *config == "" { if *config == "" {
if path, config_exist := configFilePath(); config_exist {
*config = path
} else {
fmt.Println("configuration path is required") fmt.Println("configuration path is required")
return return
} }
}
if !*daemon { if !*daemon {
lock("read-config") lock("read-config")