Files
gluetun/internal/shadowsocks/command.go

42 lines
1.1 KiB
Go
Raw Normal View History

package shadowsocks
import (
2020-04-19 18:13:48 +00:00
"context"
"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, server string, port uint16, password string, log bool) (stdout, stderr io.ReadCloser, waitFn func() error, err error) {
2020-04-12 19:07:19 +00:00
c.logger.Info("starting shadowsocks server")
args := []string{
"-c", string(constants.ShadowsocksConf),
"-p", fmt.Sprintf("%d", port),
"-k", password,
}
if log {
args = append(args, "-v")
}
2020-04-19 18:13:48 +00:00
stdout, stderr, waitFn, err = c.commander.Start(ctx, "ss-server", args...)
2020-04-14 12:22:14 +00:00
return stdout, stderr, waitFn, err
}
// Version obtains the version of the installed shadowsocks server
2020-04-19 18:13:48 +00:00
func (c *configurator) Version(ctx context.Context) (string, error) {
output, err := c.commander.Run(ctx, "ss-server", "-h")
if err != nil {
return "", err
}
lines := strings.Split(output, "\n")
if len(lines) < 2 {
return "", fmt.Errorf("ss-server -h: not enough lines in %q", output)
}
words := strings.Fields(lines[1])
if len(words) < 2 {
return "", fmt.Errorf("ss-server -h: line 2 is too short: %q", lines[1])
}
return words[1], nil
}