Debian Codegraph @

pkg/lib/os-release.ts

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