-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1875 from odilitime/fix-postinstall-script
chore: support more debians distros
- Loading branch information
Showing
1 changed file
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,64 @@ | ||
import os from "os"; | ||
import fs from "fs"; | ||
import { execSync } from "child_process"; | ||
|
||
const platform = os.platform(); | ||
const rel = os.release(); | ||
|
||
if (platform !== "linux") { | ||
console.log("Skipping playwright installation: non-Linux platform detected:", platform); | ||
process.exit(0); | ||
} | ||
|
||
function getDistroName() { | ||
try { | ||
const osReleaseContent = fs.readFileSync("/etc/os-release", "utf8"); | ||
const lines = osReleaseContent.split("\n"); | ||
const info = {}; | ||
for (const line of lines) { | ||
const [key, value] = line.split("="); | ||
if (key && value) { | ||
info[key.toLowerCase()] = value.replace(/"/g, "").toLowerCase().trim(); | ||
} | ||
} | ||
return info["id"] || info["id_like"] || null; | ||
} catch (err) { | ||
console.error("Error reading /etc/os-release:", err.message); | ||
} | ||
return null; | ||
} | ||
|
||
if ( | ||
platform === "linux" && | ||
!(os.release().includes("ubuntu") || os.release().includes("debian")) | ||
) { | ||
// DO NOT CHANGE THIS TO ELIZALOGGER, this file cannot depends on any workspace otherwise we can't build the workspace | ||
const distro = getDistroName(); | ||
console.log("Detected Linux distribution:", distro || "unknown"); | ||
|
||
const supportedDistros = [ | ||
"ubuntu", | ||
"debian", | ||
"pve", | ||
"raspbian", | ||
"pop", | ||
"zorin", | ||
"linuxmint", | ||
"elementary", | ||
"pureos", | ||
"kali" | ||
]; | ||
|
||
if (!distro || !supportedDistros.some((name) => distro.includes(name))) { | ||
console.log( | ||
"Skipping playwright installation on unsupported platform:", | ||
platform | ||
platform, | ||
rel, | ||
distro || "unknown distro" | ||
); | ||
} else { | ||
const { execSync } = await import("child_process"); | ||
process.exit(0); | ||
} | ||
|
||
try { | ||
execSync("npx playwright install-deps && npx playwright install", { | ||
stdio: "inherit", | ||
stdio: "inherit" | ||
}); | ||
} catch (err) { | ||
console.error("Failed to install Playwright dependencies:", err.message); | ||
process.exit(1); | ||
} |