Line data Source code
1 : /*
2 : * Copyright (C) 2022 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 142 : import cockpit from "cockpit";
7 :
8 125 : function parse_simple_vars(text: string): Record<string, string> {
9 125 : const res: Record<string, string> = { };
10 125 : for (const l of text.split('\n')) {
11 125 : const pos = l.indexOf('=');
12 125 : if (pos > 0) {
13 125 : const name = l.substring(0, pos);
14 125 : let val = l.substring(pos + 1);
15 125 : if (val[0] == '"' && val[val.length - 1] == '"')
16 125 : val = val.substring(1, val.length - 1);
17 125 : res[name] = val;
18 125 : }
19 125 : }
20 125 : return res;
21 125 : }
22 :
23 : /* Return /etc/os-release as object */
24 126 : export const read_os_release = () => cockpit.file("/etc/os-release", { syntax: { parse: parse_simple_vars } }).read();
|