A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1use anyhow::Error;
2use std::path::Path;
3use std::process::Command;
4
5const SERVICE_TEMPLATE: &str = include_str!("../../systemd/rockbox.service");
6
7pub fn install() -> Result<(), Error> {
8 let home = std::env::var("HOME")?;
9 let service_path: &str = &format!("{}/.config/systemd/user/rockbox.service", home);
10 std::fs::create_dir_all(format!("{}/.config/systemd/user", home))
11 .expect("Failed to create systemd user directory");
12
13 if Path::new(service_path).exists() {
14 println!("Service file already exists. Nothing to install.");
15 return Ok(());
16 }
17
18 let rockbox_path = std::env::current_exe()?;
19 let service_template: &str = &SERVICE_TEMPLATE.replace(
20 "ExecStart=/usr/local/bin/rockboxd",
21 &format!("ExecStart={}d", rockbox_path.display()),
22 );
23
24 std::fs::write(service_path, service_template).expect("Failed to write service file");
25
26 Command::new("systemctl")
27 .arg("--user")
28 .arg("daemon-reload")
29 .status()?;
30
31 Command::new("systemctl")
32 .arg("--user")
33 .arg("enable")
34 .arg("rockbox")
35 .status()?;
36
37 Command::new("systemctl")
38 .arg("--user")
39 .arg("start")
40 .arg("rockbox")
41 .status()?;
42
43 println!("✅ Rockbox service installed successfully!");
44
45 Ok(())
46}
47
48pub fn uninstall() -> Result<(), Error> {
49 let home = std::env::var("HOME")?;
50 let service_path: &str = &format!("{}/.config/systemd/user/rockbox.service", home);
51
52 if Path::new(service_path).exists() {
53 Command::new("systemctl")
54 .arg("--user")
55 .arg("stop")
56 .arg("rockbox")
57 .status()?;
58
59 Command::new("systemctl")
60 .arg("--user")
61 .arg("disable")
62 .arg("rockbox")
63 .status()?;
64
65 std::fs::remove_file(service_path).expect("Failed to remove service file");
66
67 Command::new("systemctl")
68 .arg("--user")
69 .arg("daemon-reload")
70 .status()?;
71
72 println!("✅ Rockbox service uninstalled successfully!");
73 } else {
74 println!("Service file does not exist. Nothing to uninstall.");
75 }
76
77 Ok(())
78}
79
80pub fn status() -> Result<(), Error> {
81 let home = std::env::var("HOME")?;
82 let service_path: &str = &format!("{}/.config/systemd/user/rockbox.service", home);
83
84 if Path::new(service_path).exists() {
85 Command::new("systemctl")
86 .arg("--user")
87 .arg("status")
88 .arg("rockbox")
89 .status()?;
90 } else {
91 println!("Service file does not exist. Rockbox service is not installed.");
92 }
93
94 Ok(())
95}