2019-04-06 20:33:54 +00:00
|
|
|
package config
|
2019-03-24 22:59:37 +00:00
|
|
|
|
|
|
|
import (
|
2019-04-06 22:24:25 +00:00
|
|
|
"fmt"
|
2020-05-29 05:07:53 +00:00
|
|
|
"github.com/apex/log"
|
2020-04-13 17:12:49 +00:00
|
|
|
"github.com/cobaugh/osrelease"
|
2019-12-22 05:02:02 +00:00
|
|
|
"github.com/creasty/defaults"
|
2020-08-01 04:14:49 +00:00
|
|
|
"github.com/gammazero/workerpool"
|
2020-04-12 00:26:17 +00:00
|
|
|
"github.com/gbrlsnchs/jwt/v3"
|
2020-08-01 04:14:49 +00:00
|
|
|
"github.com/pkg/errors"
|
2019-03-25 01:00:21 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-04-06 22:24:25 +00:00
|
|
|
"os/exec"
|
|
|
|
"os/user"
|
2019-04-06 22:39:57 +00:00
|
|
|
"path"
|
|
|
|
"regexp"
|
2020-08-01 04:14:49 +00:00
|
|
|
"runtime"
|
2019-04-06 22:39:57 +00:00
|
|
|
"strconv"
|
2019-04-06 22:24:25 +00:00
|
|
|
"strings"
|
2019-04-06 22:39:57 +00:00
|
|
|
"sync"
|
2019-03-24 22:59:37 +00:00
|
|
|
)
|
|
|
|
|
2020-05-09 22:37:49 +00:00
|
|
|
const DefaultLocation = "/etc/pterodactyl/config.yml"
|
2020-04-17 21:27:06 +00:00
|
|
|
|
2019-03-24 22:59:37 +00:00
|
|
|
type Configuration struct {
|
2020-04-11 23:17:46 +00:00
|
|
|
sync.RWMutex `json:"-" yaml:"-"`
|
|
|
|
|
2020-04-17 21:27:06 +00:00
|
|
|
// The location from which this configuration instance was instantiated.
|
|
|
|
path string
|
|
|
|
|
2020-04-11 23:17:46 +00:00
|
|
|
// Locker specific to writing the configuration to the disk, this happens
|
|
|
|
// in areas that might already be locked so we don't want to crash the process.
|
|
|
|
writeLock sync.Mutex
|
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// Determines if wings should be running in debug mode. This value is ignored
|
|
|
|
// if the debug flag is passed through the command line arguments.
|
|
|
|
Debug bool
|
|
|
|
|
2020-04-10 22:22:15 +00:00
|
|
|
// A unique identifier for this node in the Panel.
|
|
|
|
Uuid string
|
|
|
|
|
|
|
|
// An identifier for the token which must be included in any requests to the panel
|
|
|
|
// so that the token can be looked up correctly.
|
2020-04-11 23:32:46 +00:00
|
|
|
AuthenticationTokenId string `json:"token_id" yaml:"token_id"`
|
2020-04-10 22:22:15 +00:00
|
|
|
|
|
|
|
// The token used when performing operations. Requests to this instance must
|
|
|
|
// validate against it.
|
2020-04-11 23:32:46 +00:00
|
|
|
AuthenticationToken string `json:"token" yaml:"token"`
|
2020-04-10 22:22:15 +00:00
|
|
|
|
2020-05-18 00:25:53 +00:00
|
|
|
Api ApiConfiguration `json:"api" yaml:"api"`
|
|
|
|
System SystemConfiguration `json:"system" yaml:"system"`
|
|
|
|
Docker DockerConfiguration `json:"docker" yaml:"docker"`
|
2019-03-25 01:00:21 +00:00
|
|
|
|
|
|
|
// The amount of time in seconds that should elapse between disk usage checks
|
|
|
|
// run by the daemon. Setting a higher number can result in better IO performance
|
|
|
|
// at an increased risk of a malicious user creating a process that goes over
|
|
|
|
// the assigned disk limits.
|
|
|
|
DiskCheckTimeout int `yaml:"disk_check_timeout"`
|
|
|
|
|
|
|
|
// Defines internal throttling configurations for server processes to prevent
|
|
|
|
// someone from running an endless loop that spams data to logs.
|
|
|
|
Throttles struct {
|
|
|
|
// The number of data overage warnings (inclusive) that can accumulate
|
|
|
|
// before a process is terminated.
|
2019-12-22 21:20:34 +00:00
|
|
|
KillAtCount int `default:"5" yaml:"kill_at_count"`
|
2019-03-25 01:00:21 +00:00
|
|
|
|
|
|
|
// The number of seconds that must elapse before the internal counter
|
|
|
|
// begins decrementing warnings assigned to a process that is outputting
|
|
|
|
// too much data.
|
2020-04-13 00:39:19 +00:00
|
|
|
DecaySeconds int `default:"10" json:"decay" yaml:"decay"`
|
2019-03-25 01:00:21 +00:00
|
|
|
|
|
|
|
// The total number of bytes allowed to be output by a server process
|
|
|
|
// per interval.
|
2020-04-13 00:39:19 +00:00
|
|
|
BytesPerInterval int `default:"4096" json:"bytes" yaml:"bytes"`
|
2019-03-25 01:00:21 +00:00
|
|
|
|
|
|
|
// The amount of time that should lapse between data output throttle
|
|
|
|
// checks. This should be defined in milliseconds.
|
2020-04-12 21:07:41 +00:00
|
|
|
CheckInterval int `default:"100" yaml:"check_interval"`
|
2019-03-25 01:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The location where the panel is running that this daemon should connect to
|
|
|
|
// to collect data and send events.
|
2020-04-13 00:39:19 +00:00
|
|
|
PanelLocation string `json:"remote" yaml:"remote"`
|
2020-07-04 21:32:53 +00:00
|
|
|
|
2020-07-31 22:21:27 +00:00
|
|
|
// AllowedMounts is a list of allowed host-system mount points.
|
|
|
|
// This is required to have the "Server Mounts" feature work properly.
|
2020-07-04 21:32:53 +00:00
|
|
|
AllowedMounts []string `json:"allowed_mounts" yaml:"allowed_mounts"`
|
2020-07-31 22:19:09 +00:00
|
|
|
|
2020-07-31 22:21:27 +00:00
|
|
|
// AllowedOrigins is a list of allowed request origins.
|
|
|
|
// The Panel URL is automatically allowed, this is only needed for adding
|
|
|
|
// additional origins.
|
2020-07-31 22:19:09 +00:00
|
|
|
AllowedOrigins []string `json:"allowed_origins" yaml:"allowed_origins"`
|
2019-03-24 22:59:37 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 22:01:40 +00:00
|
|
|
// Defines the configuration of the internal SFTP server.
|
|
|
|
type SftpConfiguration struct {
|
|
|
|
// If set to true disk checking will not be performed. This will prevent the SFTP
|
|
|
|
// server from checking the total size of a directory when uploading files.
|
|
|
|
DisableDiskChecking bool `default:"false" yaml:"disable_disk_checking"`
|
|
|
|
// The bind address of the SFTP server.
|
2020-04-13 00:39:19 +00:00
|
|
|
Address string `default:"0.0.0.0" json:"bind_address" yaml:"bind_address"`
|
2019-12-07 22:01:40 +00:00
|
|
|
// The bind port of the SFTP server.
|
2020-04-13 00:39:19 +00:00
|
|
|
Port int `default:"2022" json:"bind_port" yaml:"bind_port"`
|
2019-12-07 22:01:40 +00:00
|
|
|
// If set to true, no write actions will be allowed on the SFTP server.
|
|
|
|
ReadOnly bool `default:"false" yaml:"read_only"`
|
2019-04-06 20:33:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 22:59:37 +00:00
|
|
|
// Defines the configuration for the internal API that is exposed by the
|
|
|
|
// daemon webserver.
|
|
|
|
type ApiConfiguration struct {
|
2019-03-25 01:00:21 +00:00
|
|
|
// The interface that the internal webserver should bind to.
|
2019-12-22 21:20:34 +00:00
|
|
|
Host string `default:"0.0.0.0" yaml:"host"`
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// The port that the internal webserver should bind to.
|
2019-12-22 21:20:34 +00:00
|
|
|
Port int `default:"8080" yaml:"port"`
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// SSL configuration for the daemon.
|
|
|
|
Ssl struct {
|
2019-12-22 21:20:34 +00:00
|
|
|
Enabled bool `default:"false"`
|
2020-04-13 00:39:19 +00:00
|
|
|
CertificateFile string `json:"cert" yaml:"cert"`
|
|
|
|
KeyFile string `json:"key" yaml:"key"`
|
2019-03-25 01:00:21 +00:00
|
|
|
}
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// The maximum size for files uploaded through the Panel in bytes.
|
2020-04-13 00:39:19 +00:00
|
|
|
UploadLimit int `default:"100" json:"upload_limit" yaml:"upload_limit"`
|
2019-03-24 22:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reads the configuration from the provided file and returns the configuration
|
|
|
|
// object that can then be used.
|
|
|
|
func ReadConfiguration(path string) (*Configuration, error) {
|
2019-03-25 01:00:21 +00:00
|
|
|
b, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2019-12-07 22:01:40 +00:00
|
|
|
c := new(Configuration)
|
2019-12-22 21:20:34 +00:00
|
|
|
// Configures the default values for many of the configuration options present
|
2020-04-11 23:17:46 +00:00
|
|
|
// in the structs. Values set in the configuration file take priority over the
|
2019-12-22 21:20:34 +00:00
|
|
|
// default values.
|
|
|
|
if err := defaults.Set(c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2020-04-17 21:27:06 +00:00
|
|
|
// Track the location where we created this configuration.
|
2020-06-30 03:42:26 +00:00
|
|
|
c.unsafeSetPath(path)
|
2020-04-17 21:27:06 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// Replace environment variables within the configuration file with their
|
|
|
|
// values from the host system.
|
|
|
|
b = []byte(os.ExpandEnv(string(b)))
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
if err := yaml.Unmarshal(b, c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-03-24 22:59:37 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
return c, nil
|
2019-03-24 22:59:37 +00:00
|
|
|
}
|
2019-04-06 20:33:54 +00:00
|
|
|
|
2020-08-01 04:14:49 +00:00
|
|
|
var mu sync.RWMutex
|
2020-04-12 00:26:17 +00:00
|
|
|
|
2019-09-09 00:40:06 +00:00
|
|
|
var _config *Configuration
|
2020-04-12 00:26:17 +00:00
|
|
|
var _jwtAlgo *jwt.HMACSHA
|
2019-12-22 05:10:45 +00:00
|
|
|
var _debugViaFlag bool
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2020-04-11 23:17:46 +00:00
|
|
|
// Set the global configuration instance. This is a blocking operation such that
|
|
|
|
// anything trying to set a different configuration value, or read the configuration
|
|
|
|
// will be paused until it is complete.
|
2019-09-09 00:40:06 +00:00
|
|
|
func Set(c *Configuration) {
|
2020-08-01 04:14:49 +00:00
|
|
|
mu.Lock()
|
2020-04-12 00:26:17 +00:00
|
|
|
|
|
|
|
if _config == nil || _config.AuthenticationToken != c.AuthenticationToken {
|
|
|
|
_jwtAlgo = jwt.NewHS256([]byte(c.AuthenticationToken))
|
|
|
|
}
|
|
|
|
|
2019-09-09 00:40:06 +00:00
|
|
|
_config = c
|
2020-08-01 04:14:49 +00:00
|
|
|
mu.Unlock()
|
2019-09-09 00:40:06 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 05:10:45 +00:00
|
|
|
func SetDebugViaFlag(d bool) {
|
|
|
|
_debugViaFlag = d
|
|
|
|
}
|
|
|
|
|
2020-04-11 23:17:46 +00:00
|
|
|
// Get the global configuration instance. This is a read-safe operation that will block
|
|
|
|
// if the configuration is presently being modified.
|
2019-09-09 00:40:06 +00:00
|
|
|
func Get() *Configuration {
|
2020-08-01 04:14:49 +00:00
|
|
|
mu.RLock()
|
|
|
|
defer mu.RUnlock()
|
2020-04-11 23:17:46 +00:00
|
|
|
|
2019-09-09 00:40:06 +00:00
|
|
|
return _config
|
|
|
|
}
|
|
|
|
|
2020-04-12 00:26:17 +00:00
|
|
|
// Returns the in-memory JWT algorithm.
|
|
|
|
func GetJwtAlgorithm() *jwt.HMACSHA {
|
2020-08-01 04:14:49 +00:00
|
|
|
mu.RLock()
|
|
|
|
defer mu.RUnlock()
|
2020-04-12 00:26:17 +00:00
|
|
|
|
|
|
|
return _jwtAlgo
|
|
|
|
}
|
|
|
|
|
2020-06-30 03:33:54 +00:00
|
|
|
// Create a new struct and set the path where it should be stored.
|
|
|
|
func NewFromPath(path string) (*Configuration, error) {
|
|
|
|
c := new(Configuration)
|
|
|
|
if err := defaults.Set(c); err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return c, errors.WithStack(err)
|
2020-06-30 03:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.unsafeSetPath(path)
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the path where the configuration file is located on the server. This function should
|
|
|
|
// not be called except by processes that are generating the configuration such as the configration
|
|
|
|
// command shipped with this software.
|
|
|
|
func (c *Configuration) unsafeSetPath(path string) {
|
|
|
|
c.Lock()
|
|
|
|
c.path = path
|
|
|
|
c.Unlock()
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:32:09 +00:00
|
|
|
// Returns the path for this configuration file.
|
|
|
|
func (c *Configuration) GetPath() string {
|
2020-06-30 03:42:26 +00:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
|
|
|
|
2020-04-17 21:32:09 +00:00
|
|
|
return c.path
|
|
|
|
}
|
|
|
|
|
2019-04-06 20:33:54 +00:00
|
|
|
// Ensures that the Pterodactyl core user exists on the system. This user will be the
|
|
|
|
// owner of all data in the root data directory and is used as the user within containers.
|
|
|
|
//
|
|
|
|
// If files are not owned by this user there will be issues with permissions on Docker
|
|
|
|
// mount points.
|
2019-04-06 22:24:25 +00:00
|
|
|
func (c *Configuration) EnsurePterodactylUser() (*user.User, error) {
|
2019-04-06 23:03:02 +00:00
|
|
|
u, err := user.Lookup(c.System.Username)
|
2019-04-06 22:24:25 +00:00
|
|
|
|
|
|
|
// If an error is returned but it isn't the unknown user error just abort
|
|
|
|
// the process entirely. If we did find a user, return it immediately.
|
|
|
|
if err == nil {
|
2019-04-06 23:03:02 +00:00
|
|
|
return u, c.setSystemUser(u)
|
2019-04-06 22:24:25 +00:00
|
|
|
} else if _, ok := err.(user.UnknownUserError); !ok {
|
2020-08-01 04:14:49 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-04-06 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sysName, err := getSystemName()
|
|
|
|
if err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-04-06 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 23:03:02 +00:00
|
|
|
var command = fmt.Sprintf("useradd --system --no-create-home --shell /bin/false %s", c.System.Username)
|
2019-04-06 22:24:25 +00:00
|
|
|
|
|
|
|
// 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.
|
2020-04-13 17:12:49 +00:00
|
|
|
if strings.HasPrefix(sysName, "alpine") {
|
2019-04-06 23:03:02 +00:00
|
|
|
command = fmt.Sprintf("adduser -S -D -H -G %[1]s -s /bin/false %[1]s", c.System.Username)
|
2019-04-06 22:24:25 +00:00
|
|
|
|
|
|
|
// We have to create the group first on Alpine, so do that here before continuing on
|
|
|
|
// to the user creation process.
|
2020-04-12 21:07:41 +00:00
|
|
|
if _, err := exec.Command("addgroup", "-S", c.System.Username).Output(); err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-04-06 22:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
split := strings.Split(command, " ")
|
|
|
|
if _, err := exec.Command(split[0], split[1:]...).Output(); err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-04-06 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 23:03:02 +00:00
|
|
|
if u, err := user.Lookup(c.System.Username); err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-04-06 23:03:02 +00:00
|
|
|
} else {
|
|
|
|
return u, c.setSystemUser(u)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the system user into the configuration and then write it to the disk so that
|
|
|
|
// it is persisted on boot.
|
|
|
|
func (c *Configuration) setSystemUser(u *user.User) error {
|
|
|
|
uid, _ := strconv.Atoi(u.Uid)
|
|
|
|
gid, _ := strconv.Atoi(u.Gid)
|
|
|
|
|
2020-04-11 23:17:46 +00:00
|
|
|
c.Lock()
|
2019-04-06 23:03:02 +00:00
|
|
|
c.System.Username = u.Username
|
|
|
|
c.System.User.Uid = uid
|
|
|
|
c.System.User.Gid = gid
|
2020-06-30 03:42:26 +00:00
|
|
|
c.Unlock()
|
2019-04-06 23:03:02 +00:00
|
|
|
|
2020-04-10 23:55:36 +00:00
|
|
|
return c.WriteToDisk()
|
2019-04-06 20:33:54 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 04:14:49 +00:00
|
|
|
var uuid4Regex = regexp.MustCompile("^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$")
|
|
|
|
|
2019-04-06 20:33:54 +00:00
|
|
|
// Ensures that the configured data directory has the correct permissions assigned to
|
|
|
|
// all of the files and folders within.
|
|
|
|
func (c *Configuration) EnsureFilePermissions() error {
|
2019-04-06 22:39:57 +00:00
|
|
|
// Don't run this unless it is configured to be run. On large system this can often slow
|
|
|
|
// things down dramatically during the boot process.
|
|
|
|
if !c.System.SetPermissionsOnBoot {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := ioutil.ReadDir(c.System.Data)
|
|
|
|
if err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return errors.WithStack(err)
|
2019-04-06 22:39:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 04:31:53 +00:00
|
|
|
pool := workerpool.New(runtime.NumCPU())
|
2019-04-06 22:39:57 +00:00
|
|
|
|
|
|
|
for _, file := range files {
|
2020-08-01 04:14:49 +00:00
|
|
|
f := file
|
|
|
|
if !f.IsDir() || !uuid4Regex.MatchString(f.Name()) {
|
|
|
|
continue
|
|
|
|
}
|
2019-04-06 22:39:57 +00:00
|
|
|
|
2020-08-01 04:14:49 +00:00
|
|
|
pool.Submit(func() {
|
|
|
|
if err := os.Chown(path.Join(c.System.Data, f.Name()), c.System.User.Uid, c.System.User.Gid); err != nil {
|
2020-05-29 05:07:53 +00:00
|
|
|
log.WithField("error", err).WithField("directory", f.Name()).Warn("failed to chown server directory")
|
2019-04-06 22:39:57 +00:00
|
|
|
}
|
2020-08-01 04:14:49 +00:00
|
|
|
})
|
2019-04-06 22:39:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 04:14:49 +00:00
|
|
|
pool.StopWait()
|
2019-04-06 22:39:57 +00:00
|
|
|
|
2019-04-06 20:33:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-04-06 22:24:25 +00:00
|
|
|
|
2019-04-06 23:03:02 +00:00
|
|
|
// Writes the configuration to the disk as a blocking operation by obtaining an exclusive
|
|
|
|
// lock on the file. This prevents something else from writing at the exact same time and
|
|
|
|
// leading to bad data conditions.
|
|
|
|
func (c *Configuration) WriteToDisk() error {
|
2020-06-30 03:42:26 +00:00
|
|
|
// Obtain an exclusive write against the configuration file.
|
|
|
|
c.writeLock.Lock()
|
|
|
|
defer c.writeLock.Unlock()
|
|
|
|
|
2019-12-22 05:10:45 +00:00
|
|
|
ccopy := *c
|
|
|
|
// If debugging is set with the flag, don't save that to the configuration file, otherwise
|
|
|
|
// you'll always end up in debug mode.
|
|
|
|
if _debugViaFlag {
|
|
|
|
ccopy.Debug = false
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:27:06 +00:00
|
|
|
if c.path == "" {
|
|
|
|
return errors.New("cannot write configuration, no path defined in struct")
|
|
|
|
}
|
|
|
|
|
2019-12-22 05:10:45 +00:00
|
|
|
b, err := yaml.Marshal(&ccopy)
|
2019-04-06 23:03:02 +00:00
|
|
|
if err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return errors.WithStack(err)
|
2019-04-06 23:03:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:32:09 +00:00
|
|
|
if err := ioutil.WriteFile(c.GetPath(), b, 0644); err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return errors.WithStack(err)
|
2019-04-06 23:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-06 22:39:57 +00:00
|
|
|
// Gets the system release name.
|
2019-04-06 22:24:25 +00:00
|
|
|
func getSystemName() (string, error) {
|
2020-04-13 17:12:49 +00:00
|
|
|
// use osrelease to get release version and ID
|
2020-04-17 21:27:06 +00:00
|
|
|
if release, err := osrelease.Read(); err != nil {
|
2020-08-01 04:14:49 +00:00
|
|
|
return "", errors.WithStack(err)
|
2020-04-12 21:07:41 +00:00
|
|
|
} else {
|
2020-04-13 17:12:49 +00:00
|
|
|
return release["ID"], nil
|
2019-04-06 22:24:25 +00:00
|
|
|
}
|
2019-12-07 22:01:40 +00:00
|
|
|
}
|