Skip to content

Commit a528b2a

Browse files
committed
fix: Fix /etc/os-release not present
1 parent 7b00ac2 commit a528b2a

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/utils/os-utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,18 @@ export const OsUtils = {
170170
},
171171

172172
async getLinuxDistro(): Promise<LinuxDistro | undefined> {
173-
const osRelease = await fs.readFile('/etc/os-release', 'utf8');
174-
const lines = osRelease.split('\n');
175-
for (const line of lines) {
176-
if (line.startsWith('ID=')) {
177-
const distroId = line.slice(3).trim().replaceAll('"', '');
178-
return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
173+
for (const candidate of ['/etc/os-release', '/usr/lib/os-release']) {
174+
let osRelease: string;
175+
try {
176+
osRelease = await fs.readFile(candidate, 'utf8');
177+
} catch {
178+
continue;
179+
}
180+
for (const line of osRelease.split('\n')) {
181+
if (line.startsWith('ID=')) {
182+
const distroId = line.slice(3).trim().replaceAll('"', '');
183+
return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
184+
}
179185
}
180186
}
181187

src/utils/shell.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ export const ShellUtils = {
5151
},
5252

5353
async getLinuxDistro(): Promise<LinuxDistro | undefined> {
54-
const osRelease = await fs.readFile('/etc/os-release', 'utf8');
55-
const lines = osRelease.split('\n');
56-
for (const line of lines) {
57-
if (line.startsWith('ID=')) {
58-
const distroId = line.slice(3).trim().replaceAll('"', '');
59-
return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
54+
for (const candidate of ['/etc/os-release', '/usr/lib/os-release']) {
55+
let osRelease: string;
56+
try {
57+
osRelease = await fs.readFile(candidate, 'utf8');
58+
} catch {
59+
continue;
60+
}
61+
for (const line of osRelease.split('\n')) {
62+
if (line.startsWith('ID=')) {
63+
const distroId = line.slice(3).trim().replaceAll('"', '');
64+
return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
65+
}
6066
}
6167
}
6268

0 commit comments

Comments
 (0)