(contents: string)
| 142 | |
| 143 | /** Parse the shell-style key=value contents of /etc/os-release. */ |
| 144 | export function parseOsRelease(contents: string): Record<string, string> { |
| 145 | const out: Record<string, string> = {}; |
| 146 | for (const rawLine of contents.split("\n")) { |
| 147 | const line = rawLine.trim(); |
| 148 | if (!line || line.startsWith("#")) continue; |
| 149 | const eq = line.indexOf("="); |
| 150 | if (eq < 0) continue; |
| 151 | const key = line.slice(0, eq).trim(); |
| 152 | let value = line.slice(eq + 1).trim(); |
| 153 | // Strip surrounding single/double quotes. |
| 154 | if (value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.at(-1) === value[0]) { |
| 155 | value = value.slice(1, -1); |
| 156 | } |
| 157 | if (key) out[key] = value; |
| 158 | } |
| 159 | return out; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Detect the running Linux distribution family and WSL status. Reads |
no outgoing calls
no test coverage detected