github.com/iDigitalFlame/xmt@v0.5.4/device/local/linux_no_crypt.go (about)

     1  //go:build (android || linux) && !crypt
     2  // +build android linux
     3  // +build !crypt
     4  
     5  // Copyright (C) 2020 - 2023 iDigitalFlame
     6  //
     7  // This program is free software: you can redistribute it and/or modify
     8  // it under the terms of the GNU General Public License as published by
     9  // the Free Software Foundation, either version 3 of the License, or
    10  // any later version.
    11  //
    12  // This program is distributed in the hope that it will be useful,
    13  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  // GNU General Public License for more details.
    16  //
    17  // You should have received a copy of the GNU General Public License
    18  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    19  //
    20  
    21  package local
    22  
    23  import (
    24  	"github.com/iDigitalFlame/xmt/data"
    25  	"github.com/iDigitalFlame/xmt/device/unix"
    26  )
    27  
    28  func sysID() []byte {
    29  	b, err := data.ReadFile("/var/lib/dbus/machine-id")
    30  	if err == nil {
    31  		return b
    32  	}
    33  	b, _ = data.ReadFile("/etc/machine-id")
    34  	return b
    35  }
    36  func version() string {
    37  	var (
    38  		ok      bool
    39  		b, n, v string
    40  	)
    41  	if m := release(); len(m) > 0 {
    42  		b = m["ID"]
    43  		if n, ok = m["PRETTY_NAME"]; !ok {
    44  			n = m["NAME"]
    45  		}
    46  		if v, ok = m["VERSION_ID"]; !ok {
    47  			v = m["VERSION"]
    48  		}
    49  	}
    50  	if len(v) == 0 {
    51  		v = unix.Release()
    52  	}
    53  	switch {
    54  	case len(n) == 0 && len(b) == 0 && len(v) == 0:
    55  		return "Linux"
    56  	case len(n) == 0 && len(b) > 0 && len(v) > 0:
    57  		return "Linux (" + v + ", " + b + ")"
    58  	case len(n) == 0 && len(b) == 0 && len(v) > 0:
    59  		return "Linux (" + v + ")"
    60  	case len(n) == 0 && len(b) > 0 && len(v) == 0:
    61  		return "Linux (" + b + ")"
    62  	case len(n) > 0 && len(b) > 0 && len(v) > 0:
    63  		return n + " (" + v + ", " + b + ")"
    64  	case len(n) > 0 && len(b) == 0 && len(v) > 0:
    65  		return n + " (" + v + ")"
    66  	case len(n) > 0 && len(b) > 0 && len(v) == 0:
    67  		return n + " (" + b + ")"
    68  	}
    69  	return "Linux"
    70  }