Remove entries on install (#213)

This commit is contained in:
Itxaka
2024-01-26 17:41:23 +01:00
committed by GitHub
parent 8696eb16d2
commit f6f113128d
5 changed files with 93 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package utils
import (
"bufio"
"crypto/sha256"
"errors"
"fmt"
@@ -527,3 +528,31 @@ func UkiBootMode() state.Boot {
}
return state.Unknown
}
// SystemdBootConfReader reads a systemd-boot conf file and returns a map with the key/value pairs
func SystemdBootConfReader(filePath string) (map[string]string, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
result := make(map[string]string)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
parts := strings.SplitN(line, " ", 2)
if len(parts) == 2 {
result[parts[0]] = parts[1]
}
if len(parts) == 1 {
result[parts[0]] = ""
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return result, nil
}