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

     1  //go:build !windows && !js && !ios && !darwin && !crypt
     2  // +build !windows,!js,!ios,!darwin,!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  	"os"
    24  	"strings"
    25  
    26  	"github.com/iDigitalFlame/xmt/data"
    27  )
    28  
    29  func release() map[string]string {
    30  	f, err := os.OpenFile("/etc", 0, 0)
    31  	if err != nil {
    32  		return nil
    33  	}
    34  	e, err := f.Readdirnames(0)
    35  	if f.Close(); err != nil || len(e) == 0 {
    36  		return nil
    37  	}
    38  	m := make(map[string]string)
    39  	for i := range e {
    40  		if e[i] != "release" && !strings.Contains(e[i], "release") {
    41  			continue
    42  		}
    43  		for _, v := range data.ReadSplit("/etc/"+e[i], "\n") {
    44  			x := strings.IndexByte(v, '=')
    45  			if x < 1 || len(v)-x < 2 {
    46  				continue
    47  			}
    48  			c, s := len(v)-1, x+1
    49  			for ; c > x && v[c] == '"'; c-- {
    50  			}
    51  			for ; s < c && v[s] == '"'; s++ {
    52  			}
    53  			m[strings.ToUpper(v[:x])] = v[s : c+1]
    54  		}
    55  	}
    56  	return m
    57  }