forked from dylan-sutton-chavez/edge-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.rs
More file actions
41 lines (34 loc) · 1.71 KB
/
uninstall.rs
File metadata and controls
41 lines (34 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
`edge uninstall`: prompts here, then drops the bundled uninstall.sh to a temp file and runs it via bash.
*/
use anyhow::{anyhow, bail, Result};
use std::io::Write;
use std::process::Command;
// Bundled at compile time so the binary is self-contained; no network needed to clean up.
const UNINSTALL_SH: &str = include_str!("../setup/uninstall.sh");
pub fn run() -> Result<()> {
println!("This removes the edge binary and the PATH entry from your shell rc files.");
print!("Remove the system Chromium that install.sh added too? [y/N] ");
std::io::stdout().flush().ok();
let mut ans = String::new();
std::io::stdin().read_line(&mut ans).map_err(|e| anyhow!("reading answer: {e}"))?;
let remove_browser = matches!(ans.trim(), "y" | "Y" | "yes" | "Yes" | "YES");
// Spawning bash with the script as a file lets read prompts (none, in this path) work normally.
let temp = std::env::temp_dir().join("edge-uninstall.sh");
std::fs::write(&temp, UNINSTALL_SH).map_err(|e| anyhow!("staging uninstall script: {e}"))?;
let mut cmd = Command::new("bash");
cmd.arg(&temp);
// Tell the script which prompt path the user already answered.
cmd.env("EDGE_UNINSTALL_REMOVE_BROWSER", if remove_browser { "1" } else { "0" });
// Point at the install dir derived from where this binary lives, so non-default installs still clean up.
if let Ok(exe) = std::env::current_exe()
&& let Some(dir) = exe.parent() {
cmd.env("EDGE_INSTALL_DIR", dir);
}
let status = cmd.status().map_err(|e| anyhow!("running bash: {e}"))?;
let _ = std::fs::remove_file(&temp);
if !status.success() {
bail!("uninstall script exited with code {:?}", status.code());
}
Ok(())
}