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