summaryrefslogtreecommitdiff
path: root/src/install.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/install.rs')
-rw-r--r--src/install.rs109
1 files changed, 84 insertions, 25 deletions
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
- ),
}
}
}