From 12c97c41b0f0354cec29585dc09c3c701b2eac75 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Mon, 13 Apr 2020 13:12:49 -0400 Subject: [PATCH] fixes distro matching Adds osrelease to get distro name --- config/config.go | 21 ++++++--------------- go.mod | 1 + go.sum | 2 ++ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/config/config.go b/config/config.go index f99d4c4..b47ebdd 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "github.com/cobaugh/osrelease" "github.com/creasty/defaults" "github.com/gbrlsnchs/jwt/v3" "go.uber.org/zap" @@ -294,7 +295,7 @@ func (c *Configuration) EnsurePterodactylUser() (*user.User, error) { // Alpine Linux is the only OS we currently support that doesn't work with the useradd command, so // in those cases we just modify the command a bit to work as expected. - if strings.HasPrefix(sysName, "Alpine") { + if strings.HasPrefix(sysName, "alpine") { command = fmt.Sprintf("adduser -S -D -H -G %[1]s -s /bin/false %[1]s", c.System.Username) // We have to create the group first on Alpine, so do that here before continuing on @@ -413,20 +414,10 @@ func (c *Configuration) WriteToDisk() error { // Gets the system release name. func getSystemName() (string, error) { - // alpine doesn't have lsb_release - _, err := os.Stat("/etc/alpine-release") - if os.IsNotExist(err) { - // if the alpine release file doesn't exist. run lsb_release - cmd := exec.Command("lsb_release", "-is") - - b, err := cmd.Output() - if err != nil { - return "", err - } - - return string(b), nil + // use osrelease to get release version and ID + if release, err := osrelease.Read(); err != nil { + return "", err } else { - // if the alpine release file does exist return string - return "Alpine", err + return release["ID"], nil } } diff --git a/go.mod b/go.mod index a717a0a..8a32a07 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a github.com/beevik/etree v1.1.0 github.com/buger/jsonparser v0.0.0-20191204142016-1a29609e0929 + github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249 github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 // indirect github.com/creasty/defaults v1.3.0 github.com/docker/distribution v2.7.1+incompatible // indirect diff --git a/go.sum b/go.sum index 3aa5e0e..7055c64 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/buger/jsonparser v0.0.0-20191204142016-1a29609e0929 h1:MW/JDk68Rny52y github.com/buger/jsonparser v0.0.0-20191204142016-1a29609e0929/go.mod h1:tgcrVJ81GPSF0mz+0nu1Xaz0fazGPrmmJfJtxjbHhUQ= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249 h1:R0IDH8daQ3lODvu8YtxnIqqth5qMGCJyADoUQvmLx4o= +github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249/go.mod h1:EHKW9yNEYSBpTKzuu7Y9oOrft/UlzH57rMIB03oev6M= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 h1:PUD50EuOMkXVcpBIA/R95d56duJR9VxhwncsFbNnxW4= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=