fix install
This commit is contained in:
Binary file not shown.
+116
@@ -269,6 +269,10 @@ Commands:
|
||||
eval <js> Evaluate JavaScript
|
||||
close Close browser
|
||||
|
||||
Setup:
|
||||
install Install browser binaries
|
||||
install --with-deps Also install system dependencies (Linux)
|
||||
|
||||
Snapshot Options:
|
||||
-i, --interactive Only interactive elements
|
||||
-c, --compact Remove empty structural elements
|
||||
@@ -285,6 +289,111 @@ Examples:
|
||||
"#);
|
||||
}
|
||||
|
||||
fn run_install(with_deps: bool) {
|
||||
let is_linux = cfg!(target_os = "linux");
|
||||
|
||||
if is_linux {
|
||||
if with_deps {
|
||||
println!("\x1b[36mInstalling system dependencies...\x1b[0m");
|
||||
|
||||
// Detect package manager and install deps
|
||||
let (pkg_mgr, deps) = if which_exists("apt-get") {
|
||||
("apt-get", vec![
|
||||
"libxcb-shm0", "libx11-xcb1", "libx11-6", "libxcb1", "libxext6",
|
||||
"libxrandr2", "libxcomposite1", "libxcursor1", "libxdamage1", "libxfixes3",
|
||||
"libxi6", "libgtk-3-0", "libpangocairo-1.0-0", "libpango-1.0-0", "libatk1.0-0",
|
||||
"libcairo-gobject2", "libcairo2", "libgdk-pixbuf-2.0-0", "libxrender1",
|
||||
"libasound2", "libfreetype6", "libfontconfig1", "libdbus-1-3", "libnss3",
|
||||
"libnspr4", "libatk-bridge2.0-0", "libdrm2", "libxkbcommon0", "libatspi2.0-0",
|
||||
"libcups2", "libxshmfence1", "libgbm1",
|
||||
])
|
||||
} else if which_exists("dnf") {
|
||||
("dnf", vec![
|
||||
"nss", "nspr", "atk", "at-spi2-atk", "cups-libs", "libdrm",
|
||||
"libXcomposite", "libXdamage", "libXrandr", "mesa-libgbm", "pango",
|
||||
"alsa-lib", "libxkbcommon", "libxcb", "libX11-xcb", "libX11", "libXext",
|
||||
"libXcursor", "libXfixes", "libXi", "gtk3", "cairo-gobject",
|
||||
])
|
||||
} else if which_exists("yum") {
|
||||
("yum", vec![
|
||||
"nss", "nspr", "atk", "at-spi2-atk", "cups-libs", "libdrm",
|
||||
"libXcomposite", "libXdamage", "libXrandr", "mesa-libgbm", "pango",
|
||||
"alsa-lib", "libxkbcommon",
|
||||
])
|
||||
} else {
|
||||
eprintln!("\x1b[31m✗\x1b[0m No supported package manager found (apt-get, dnf, or yum)");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
let install_cmd = match pkg_mgr {
|
||||
"apt-get" => format!("sudo apt-get update && sudo apt-get install -y {}", deps.join(" ")),
|
||||
_ => format!("sudo {} install -y {}", pkg_mgr, deps.join(" ")),
|
||||
};
|
||||
|
||||
println!("Running: {}", install_cmd);
|
||||
let status = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(&install_cmd)
|
||||
.status();
|
||||
|
||||
match status {
|
||||
Ok(s) if s.success() => println!("\x1b[32m✓\x1b[0m System dependencies installed"),
|
||||
Ok(_) => {
|
||||
eprintln!("\x1b[33m⚠\x1b[0m Failed to install some dependencies. You may need to run manually with sudo.");
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("\x1b[33m⚠\x1b[0m Could not run install command: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("\x1b[33m⚠\x1b[0m Linux detected. If browser fails to launch, run:");
|
||||
println!(" agent-browser install --with-deps");
|
||||
println!(" or: npx playwright install-deps chromium");
|
||||
println!();
|
||||
}
|
||||
}
|
||||
|
||||
// Install browser binaries
|
||||
println!("\x1b[36mInstalling Chromium browser...\x1b[0m");
|
||||
let status = Command::new("npx")
|
||||
.args(["playwright", "install", "chromium"])
|
||||
.status();
|
||||
|
||||
match status {
|
||||
Ok(s) if s.success() => {
|
||||
println!("\x1b[32m✓\x1b[0m Chromium installed successfully");
|
||||
if is_linux && !with_deps {
|
||||
println!();
|
||||
println!("\x1b[33mNote:\x1b[0m If you see \"shared library\" errors when running, use:");
|
||||
println!(" agent-browser install --with-deps");
|
||||
}
|
||||
}
|
||||
Ok(_) => {
|
||||
eprintln!("\x1b[31m✗\x1b[0m Failed to install browser");
|
||||
if is_linux {
|
||||
println!("\x1b[33mTip:\x1b[0m Try installing system dependencies first:");
|
||||
println!(" agent-browser install --with-deps");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("\x1b[31m✗\x1b[0m Failed to run npx: {}", e);
|
||||
eprintln!("Make sure Node.js is installed and npx is in your PATH");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn which_exists(cmd: &str) -> bool {
|
||||
Command::new("which")
|
||||
.arg(cmd)
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.map(|s| s.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().skip(1).collect();
|
||||
let json_mode = args.iter().any(|a| a == "--json");
|
||||
@@ -295,6 +404,13 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle install command separately (doesn't need daemon)
|
||||
if clean_args.get(0).map(|s| s.as_str()) == Some("install") {
|
||||
let with_deps = args.iter().any(|a| a == "--with-deps" || a == "-d");
|
||||
run_install(with_deps);
|
||||
return;
|
||||
}
|
||||
|
||||
let cmd = match parse_command(&clean_args) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user