From f267c259163e121ff376bd764b10767a7939ef79 Mon Sep 17 00:00:00 2001 From: qvkap Date: Thu, 1 Oct 2026 08:07:36 +0300 Subject: fix(install): create symlinks for single-line service targets like /bin/sh -> bash --- src/install.rs | 109 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 84 insertions(+), 25 deletions(-) (limited to 'src/install.rs') diff --git a/src/install.rs b/src/install.rs index 160121c..e58735e 100644 --- a/src/install.rs +++ b/src/install.rs @@ -671,20 +671,51 @@ pub fn install_services(pkg: &Package) { continue; } } - match std::fs::write(path, &service.file) { - Ok(_) => { - println!( - "{} Created service for '{}': {}", - "[ror]".green().bold(), pkg.name, service.filepath - ); - if let Some(cmd) = &service.install_cmd { - run_service_install_cmd(cmd, init, &pkg.name); + let trimmed = service.file.trim(); + let is_symlink = !trimmed.is_empty() + && !trimmed.contains('\n') + && !trimmed.contains(' ') + && !trimmed.contains('=') + && (trimmed.starts_with("../") || trimmed.starts_with("./") || trimmed.starts_with('/') || !trimmed.contains(';')); + + if is_symlink { + if path.exists() || path.is_symlink() { + let _ = std::fs::remove_file(path); + } + match std::os::unix::fs::symlink(trimmed, path) { + Ok(_) => { + println!( + "{} Created service symlink for '{}': {} -> {}", + "[ror]".green().bold(), pkg.name, service.filepath, trimmed + ); + if let Some(cmd) = &service.install_cmd { + run_service_install_cmd(cmd, init, &pkg.name); + } + } + Err(e) => eprintln!( + "{} Failed to create service symlink '{}': {}", + "[ror]".red().bold(), service.filepath, e + ), + } + } else { + if path.exists() || path.is_symlink() { + let _ = std::fs::remove_file(path); + } + match std::fs::write(path, &service.file) { + Ok(_) => { + println!( + "{} Created service for '{}': {}", + "[ror]".green().bold(), pkg.name, service.filepath + ); + if let Some(cmd) = &service.install_cmd { + run_service_install_cmd(cmd, init, &pkg.name); + } } + Err(e) => eprintln!( + "{} Failed to write service file '{}': {}", + "[ror]".red().bold(), service.filepath, e + ), } - Err(e) => eprintln!( - "{} Failed to write service file '{}': {}", - "[ror]".red().bold(), service.filepath, e - ), } } } @@ -718,21 +749,49 @@ pub fn install_services_to_root(pkg: &Package, root_dir: &Path) { continue; } } - match std::fs::write(&full_path, &service.file) { - Ok(_) => { - println!( - "{} Created service for '{}': {}", - "[ror]".green().bold(), pkg.name, service.filepath - ); - if service.file.starts_with("#!") { - use std::os::unix::fs::PermissionsExt; - let _ = std::fs::set_permissions(&full_path, std::fs::Permissions::from_mode(0o755)); + let trimmed = service.file.trim(); + let is_symlink = !trimmed.is_empty() + && !trimmed.contains('\n') + && !trimmed.contains(' ') + && !trimmed.contains('=') + && (trimmed.starts_with("../") || trimmed.starts_with("./") || trimmed.starts_with('/') || !trimmed.contains(';')); + + if is_symlink { + if full_path.exists() || full_path.is_symlink() { + let _ = std::fs::remove_file(&full_path); + } + match std::os::unix::fs::symlink(trimmed, &full_path) { + Ok(_) => { + println!( + "{} Created service symlink for '{}': {} -> {}", + "[ror]".green().bold(), pkg.name, service.filepath, trimmed + ); + } + Err(e) => eprintln!( + "{} Failed to create service symlink '{}': {}", + "[ror]".red().bold(), service.filepath, e + ), + } + } else { + if full_path.exists() || full_path.is_symlink() { + let _ = std::fs::remove_file(&full_path); + } + match std::fs::write(&full_path, &service.file) { + Ok(_) => { + println!( + "{} Created service for '{}': {}", + "[ror]".green().bold(), pkg.name, service.filepath + ); + if service.file.starts_with("#!") { + use std::os::unix::fs::PermissionsExt; + let _ = std::fs::set_permissions(&full_path, std::fs::Permissions::from_mode(0o755)); + } } + Err(e) => eprintln!( + "{} Failed to write service file '{}': {}", + "[ror]".red().bold(), service.filepath, e + ), } - Err(e) => eprintln!( - "{} Failed to write service file '{}': {}", - "[ror]".red().bold(), service.filepath, e - ), } } } -- cgit v1.2.3