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

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