()
| 155 | } |
| 156 | |
| 157 | func main() { |
| 158 | s := make(chan os.Signal, 1) |
| 159 | signal.Notify(s, syscall.SIGINT, syscall.SIGQUIT) |
| 160 | ctx, cancel := context.WithCancel(context.Background()) |
| 161 | |
| 162 | go func() { |
| 163 | <-s |
| 164 | cancel() |
| 165 | }() |
| 166 | |
| 167 | exePath := executablePath() |
| 168 | lock("boot") |
| 169 | |
| 170 | isDaemonProcess := len(os.Args) > 1 && os.Args[1] == daemonProcess |
| 171 | args := os.Args |
| 172 | if isDaemonProcess { |
| 173 | lock("boot-daemon") |
| 174 | args = []string{args[0]} |
| 175 | args = append(args, os.Args[2:]...) |
| 176 | } |
| 177 | parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying") |
| 178 | |
| 179 | config := parser.String("c", "config", &argparse.Options{Help: "Path of configuration file"}) |
| 180 | silent := parser.Flag("s", "silent", &argparse.Options{Help: "Silent mode"}) |
| 181 | daemon := parser.Flag("d", "daemon", &argparse.Options{Help: "Make wireproxy run in background"}) |
| 182 | info := parser.String("i", "info", &argparse.Options{Help: "Specify the address and port for exposing health status"}) |
| 183 | printVerison := parser.Flag("v", "version", &argparse.Options{Help: "Print version"}) |
| 184 | configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."}) |
| 185 | |
| 186 | err := parser.Parse(args) |
| 187 | if err != nil { |
| 188 | fmt.Print(parser.Usage(err)) |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | if *printVerison { |
| 193 | fmt.Printf("wireproxy, version %s\n", version) |
| 194 | return |
| 195 | } |
| 196 | |
| 197 | if *config == "" { |
| 198 | if path, config_exist := configFilePath(); config_exist { |
| 199 | *config = path |
| 200 | } else { |
| 201 | fmt.Println("configuration path is required") |
| 202 | return |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | if !*daemon { |
| 207 | lock("read-config") |
| 208 | } |
| 209 | |
| 210 | conf, err := wireproxy.ParseConfig(*config) |
| 211 | if err != nil { |
| 212 | log.Fatal(err) |
| 213 | } |
| 214 |
nothing calls this directly
no test coverage detected