Feature: OPENVPN_VERSION which can be 2.4 or 2.5
This commit is contained in:
@@ -9,16 +9,42 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func (c *configurator) Start(ctx context.Context) (
|
||||
var ErrVersionUnknown = errors.New("OpenVPN version is unknown")
|
||||
|
||||
const (
|
||||
binOpenvpn24 = "openvpn2.4"
|
||||
binOpenvpn25 = "openvpn"
|
||||
)
|
||||
|
||||
func (c *configurator) Start(ctx context.Context, version string) (
|
||||
stdoutLines, stderrLines chan string, waitError chan error, err error) {
|
||||
c.logger.Info("starting openvpn")
|
||||
return c.commander.Start(ctx, "openvpn", "--config", constants.OpenVPNConf)
|
||||
var bin string
|
||||
switch version {
|
||||
case constants.Openvpn24:
|
||||
bin = binOpenvpn24
|
||||
case constants.Openvpn25:
|
||||
bin = binOpenvpn25
|
||||
default:
|
||||
return nil, nil, nil, fmt.Errorf("%w: %s", ErrVersionUnknown, version)
|
||||
}
|
||||
|
||||
c.logger.Info("starting OpenVPN " + version)
|
||||
|
||||
return c.commander.Start(ctx, bin, "--config", constants.OpenVPNConf)
|
||||
}
|
||||
|
||||
func (c *configurator) Version24(ctx context.Context) (version string, err error) {
|
||||
return c.version(ctx, binOpenvpn24)
|
||||
}
|
||||
|
||||
func (c *configurator) Version25(ctx context.Context) (version string, err error) {
|
||||
return c.version(ctx, binOpenvpn25)
|
||||
}
|
||||
|
||||
var ErrVersionTooShort = errors.New("version output is too short")
|
||||
|
||||
func (c *configurator) Version(ctx context.Context) (string, error) {
|
||||
output, err := c.commander.Run(ctx, "openvpn", "--version")
|
||||
func (c *configurator) version(ctx context.Context, binName string) (version string, err error) {
|
||||
output, err := c.commander.Run(ctx, binName, "--version")
|
||||
if err != nil && err.Error() != "exit status 1" {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) { //nolint:gocog
|
||||
|
||||
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
||||
|
||||
stdoutLines, stderrLines, waitError, err := l.conf.Start(openvpnCtx)
|
||||
stdoutLines, stderrLines, waitError, err := l.conf.Start(openvpnCtx, settings.Version)
|
||||
if err != nil {
|
||||
openvpnCancel()
|
||||
l.signalCrashedStatus()
|
||||
|
||||
@@ -12,12 +12,13 @@ import (
|
||||
)
|
||||
|
||||
type Configurator interface {
|
||||
Version(ctx context.Context) (string, error)
|
||||
Version24(ctx context.Context) (version string, err error)
|
||||
Version25(ctx context.Context) (version string, err error)
|
||||
WriteAuthFile(user, password string, puid, pgid int) error
|
||||
CheckTUN() error
|
||||
CreateTUN() error
|
||||
Start(ctx context.Context) (stdoutLines, stderrLines chan string,
|
||||
waitError chan error, err error)
|
||||
Start(ctx context.Context, version string) (
|
||||
stdoutLines, stderrLines chan string, waitError chan error, err error)
|
||||
}
|
||||
|
||||
type configurator struct {
|
||||
|
||||
Reference in New Issue
Block a user