windows: install into Program Files, seed components, log as a service
install copies the release into %ProgramFiles%\ProxySuite (upgrading in place when the service exists), registers it there, and puts it on the system PATH: a copy in Downloads could be replaced by any user, and the service runs it as SYSTEM. uninstall removes the service, the PATH entry and the program files, and leaves the state. At every start the service copies the release's components into bin\ when they are newer, staged and verified file by file, and only from a service running in Program Files. Under the Service Control Manager it logs to logs\service.log, reports StartPending until the API listens, and a failed start as a service-specific error. zapret refuses to start while Flowseal's, the win bundle's or GoodbyeDPI's service holds WinDivert, and says which to remove. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1bce9db94
commit
28cc7b2cbe
5 files changed
+338
-36
No files matched your search
@@ -183,3 +183,80 @@ pub async fn stage(to: &Path, cache: &Path, only: &[String]) -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Where the release's components are, next to the running program, if it runs from a
|
||||
/// place only administrators can change (on Windows: Program Files, where `install` puts it).
|
||||
pub fn bundled_components_dir() -> Option<PathBuf> {
|
||||
let exe = std::env::current_exe().ok()?;
|
||||
let dir = exe.parent()?.join("components");
|
||||
if !dir.is_dir() {
|
||||
return None;
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let program_files = std::env::var_os("ProgramFiles").map(PathBuf::from)?;
|
||||
if !exe.starts_with(&program_files) {
|
||||
tracing::warn!("not taking components from {}: the service runs outside Program Files", dir.display());
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(dir)
|
||||
}
|
||||
|
||||
fn copy_tree(from: &Path, to: &Path) -> Result<()> {
|
||||
std::fs::create_dir_all(to)?;
|
||||
for entry in std::fs::read_dir(from)? {
|
||||
let entry = entry?;
|
||||
let ty = entry.file_type()?;
|
||||
let dest = to.join(entry.file_name());
|
||||
if ty.is_dir() {
|
||||
copy_tree(&entry.path(), &dest)?;
|
||||
} else if ty.is_file() {
|
||||
std::fs::copy(entry.path(), &dest)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Every file `.files.json` names, with its hash.
|
||||
fn verify_all(dir: &Path) -> Result<()> {
|
||||
let files: std::collections::BTreeMap<String, String> =
|
||||
serde_json::from_slice(&std::fs::read(dir.join(".files.json")).context("no .files.json")?)?;
|
||||
for (rel, want) in files {
|
||||
if !ps_core::components::safe_relative(&rel) {
|
||||
bail!("{rel} is not a plain path");
|
||||
}
|
||||
let got = hex(&std::fs::read(dir.join(&rel)).with_context(|| format!("{rel} is missing"))?);
|
||||
if got != want {
|
||||
bail!("{rel} does not match its recorded hash");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Copies each component of `from` (the release's) into `bin` when `bin` lacks it or holds
|
||||
/// another version: staged, verified file by file, swapped in. What it did, as lines.
|
||||
pub fn seed(from: &Path, bin: &Path) -> Vec<String> {
|
||||
let manifest = ps_core::components::manifest();
|
||||
let mut notes = Vec::new();
|
||||
for (name, comp) in &manifest.components {
|
||||
let src = from.join(name);
|
||||
if installed_version(from, name).as_deref() != Some(comp.version.as_str()) {
|
||||
continue;
|
||||
}
|
||||
if installed_version(bin, name).as_deref() == Some(comp.version.as_str()) {
|
||||
continue;
|
||||
}
|
||||
let staging = bin.join(format!("{name}.staging"));
|
||||
let _ = std::fs::remove_dir_all(&staging);
|
||||
let result = copy_tree(&src, &staging).and_then(|()| verify_all(&staging)).and_then(|()| swap(bin, name, &staging));
|
||||
match result {
|
||||
Ok(()) => notes.push(format!("installed {name} {} from the release", comp.version)),
|
||||
Err(e) => {
|
||||
let _ = std::fs::remove_dir_all(&staging);
|
||||
notes.push(format!("could not install {name} from the release: {e:#}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
notes
|
||||
}
|
||||
Reference in new issue
Block a user