summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrorka <rorka@rorka.my.domain>2026-06-25 13:08:01 +0300
committerrorka <rorka@rorka.my.domain>2026-06-25 13:08:01 +0300
commit4222fbf750ebdbf2de216b38d177aa30a27310cb (patch)
tree442a86475f8702735477dba7654ec6565d5e2553 /src
parent3c2bec16cf37437759004bdf240fa6c85bc9e428 (diff)
downloadror-4222fbf750ebdbf2de216b38d177aa30a27310cb.tar.gz
ror-4222fbf750ebdbf2de216b38d177aa30a27310cb.zip
install: add install_cmd field to ServiceEntry run it after service file write if init matches1.0.1
Diffstat (limited to 'src')
-rw-r--r--src/install.rs49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/install.rs b/src/install.rs
index 9f7d80d..48c9c05 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -1,4 +1,3 @@
-// install.rs
use serde::{Deserialize, Serialize};
use std::fs;
use std::io::{BufReader, Read, Write};
@@ -130,6 +129,8 @@ pub struct ServiceEntry {
pub filepath: String,
#[serde(default)]
pub file: String,
+ #[serde(default)]
+ pub install_cmd: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
@@ -603,6 +604,37 @@ pub fn remove_services(pkg: &Package) {
}
}
+fn run_service_install_cmd(cmd_template: &str, init: &str, pkg_name: &str) {
+ let cmd = cmd_template.replace("{init}", init);
+ let parts: Vec<&str> = cmd.split_whitespace().collect();
+ if parts.is_empty() {
+ return;
+ }
+ match std::process::Command::new(parts[0])
+ .args(&parts[1..])
+ .status()
+ {
+ Ok(status) if status.success() => {
+ println!(
+ "{} Service install command OK for '{}': {}",
+ "[ror]".green().bold(), pkg_name, cmd
+ );
+ }
+ Ok(status) => {
+ eprintln!(
+ "{} Service install command exited with {} for '{}': {}",
+ "[ror]".yellow().bold(), status, pkg_name, cmd
+ );
+ }
+ Err(e) => {
+ eprintln!(
+ "{} Failed to run service install command for '{}': {} — {}",
+ "[ror]".red().bold(), pkg_name, cmd, e
+ );
+ }
+ }
+}
+
pub fn install_services(pkg: &Package) {
let current_init = get_current_init_in_root(Path::new("/"));
for service in &pkg.services {
@@ -619,7 +651,7 @@ pub fn install_services(pkg: &Package) {
"[ror]".yellow().bold(), pkg.name, service.init, init
);
}
- Some(_) => {
+ Some(init) => {
let path = std::path::Path::new(&service.filepath);
if let Some(parent) = path.parent() {
if let Err(e) = std::fs::create_dir_all(parent) {
@@ -631,10 +663,15 @@ pub fn install_services(pkg: &Package) {
}
}
match std::fs::write(path, &service.file) {
- Ok(_) => println!(
- "{} Created service for '{}': {}",
- "[ror]".green().bold(), pkg.name, service.filepath
- ),
+ 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