github.com/iDigitalFlame/xmt@v0.5.4/device/local/linux_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 "github.com/iDigitalFlame/xmt/util/crypt" 27 ) 28 29 func sysID() []byte { 30 b, err := data.ReadFile(crypt.Get(80)) // /var/lib/dbus/machine-id 31 if err == nil { 32 return b 33 } 34 b, _ = data.ReadFile(crypt.Get(81)) // /etc/machine-id 35 return b 36 } 37 func version() string { 38 var ( 39 ok bool 40 b, n, v string 41 ) 42 if m := release(); len(m) > 0 { 43 b = m[crypt.Get(1)] // ID 44 if n, ok = m[crypt.Get(75)]; !ok { // PRETTY_NAME 45 n = m[crypt.Get(75)[7:]] // PRETTY_NAME 46 } 47 if v, ok = m[crypt.Get(76)]; !ok { // VERSION_ID 48 v = m[crypt.Get(76)[0:7]] // VERSION_ID 49 } 50 } 51 if len(v) == 0 { 52 v = unix.Release() 53 } 54 switch { 55 case len(n) == 0 && len(b) == 0 && len(v) == 0: 56 return crypt.Get(82) // Linux 57 case len(n) == 0 && len(b) > 0 && len(v) > 0: 58 return crypt.Get(82) + " (" + v + ", " + b + ")" // Linux 59 case len(n) == 0 && len(b) == 0 && len(v) > 0: 60 return crypt.Get(82) + " (" + v + ")" // Linux 61 case len(n) == 0 && len(b) > 0 && len(v) == 0: 62 return crypt.Get(82) + " (" + b + ")" // Linux 63 case len(n) > 0 && len(b) > 0 && len(v) > 0: 64 return n + " (" + v + ", " + b + ")" 65 case len(n) > 0 && len(b) == 0 && len(v) > 0: 66 return n + " (" + v + ")" 67 case len(n) > 0 && len(b) > 0 && len(v) == 0: 68 return n + " (" + b + ")" 69 } 70 return crypt.Get(82) // Linux 71 }