2020-02-06 20:42:46 -05:00
|
|
|
package dns
|
|
|
|
|
|
|
|
|
|
import (
|
2020-04-19 18:13:48 +00:00
|
|
|
"context"
|
2020-02-06 20:42:46 -05:00
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/private-internet-access-docker/internal/constants"
|
|
|
|
|
)
|
|
|
|
|
|
2020-04-19 18:13:48 +00:00
|
|
|
func (c *configurator) Start(ctx context.Context, verbosityDetailsLevel uint8) (stdout io.ReadCloser, waitFn func() error, err error) {
|
2020-04-12 19:07:19 +00:00
|
|
|
c.logger.Info("starting unbound")
|
2020-02-06 20:42:46 -05:00
|
|
|
args := []string{"-d", "-c", string(constants.UnboundConf)}
|
|
|
|
|
if verbosityDetailsLevel > 0 {
|
|
|
|
|
args = append(args, "-"+strings.Repeat("v", int(verbosityDetailsLevel)))
|
|
|
|
|
}
|
|
|
|
|
// Only logs to stderr
|
2020-04-19 18:13:48 +00:00
|
|
|
_, stdout, waitFn, err = c.commander.Start(ctx, "unbound", args...)
|
2020-02-13 13:23:22 +00:00
|
|
|
return stdout, waitFn, err
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
2020-04-19 18:13:48 +00:00
|
|
|
func (c *configurator) Version(ctx context.Context) (version string, err error) {
|
|
|
|
|
output, err := c.commander.Run(ctx, "unbound", "-V")
|
2020-02-06 20:42:46 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("unbound version: %w", err)
|
|
|
|
|
}
|
|
|
|
|
for _, line := range strings.Split(output, "\n") {
|
|
|
|
|
if strings.Contains(line, "Version ") {
|
|
|
|
|
words := strings.Fields(line)
|
|
|
|
|
if len(words) < 2 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
version = words[1]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if version == "" {
|
|
|
|
|
return "", fmt.Errorf("unbound version was not found in %q", output)
|
|
|
|
|
}
|
|
|
|
|
return version, nil
|
|
|
|
|
}
|