Skip to content

Commit

Permalink
Bad workaround for local appimage daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
davnotdev committed Aug 14, 2024
1 parent f7236bd commit 555650b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions burrow-gtk/src/components/settings/daemon_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl AsyncComponent for DaemonGroup {
#[name(group)]
adw::PreferencesGroup {
#[watch]
set_sensitive:
(model.system_setup == SystemSetup::AppImage || model.system_setup == SystemSetup::Other) &&
set_sensitive:
(model.system_setup == SystemSetup::AppImage || model.system_setup == SystemSetup::Other) &&
!model.already_running,
set_title: "Local Daemon",
set_description: Some("Run Local Daemon"),
Expand Down Expand Up @@ -68,27 +68,32 @@ impl AsyncComponent for DaemonGroup {
) {
match msg {
DaemonGroupMsg::LaunchLocal => {
// TODO: Handle error condition

const BURROW_LOCAL_DAEMON_PATH: &str = "/tmp/burrow-detached-daemon";

let burrow_original_bin = std::env::vars()
.find(|(k, _)| k == "APPDIR")
.map(|(_, v)| v + "/usr/bin/burrow")
.unwrap_or("/usr/bin/burrow".to_owned());

Command::new("cp")
.arg(&burrow_original_bin)
.arg(BURROW_LOCAL_DAEMON_PATH)
.output()
.unwrap();

let mut burrow_bin =
String::from_utf8(Command::new("mktemp").output().unwrap().stdout).unwrap();
burrow_bin.pop();

let privileged_spawn_script = format!(
r#"TEMP=$(mktemp -p /root)
cp {} $TEMP
chmod +x $TEMP
setcap CAP_NET_BIND_SERVICE,CAP_NET_ADMIN+eip $TEMP
mv $TEMP /tmp/burrow-detached-daemon"#,
burrow_original_bin
r#"chmod +x {}
setcap CAP_NET_BIND_SERVICE,CAP_NET_ADMIN+eip {}"#,
BURROW_LOCAL_DAEMON_PATH, BURROW_LOCAL_DAEMON_PATH
)
.replace('\n', "&&");

// TODO: Handle error condition

Command::new("pkexec")
.arg("sh")
.arg("-c")
Expand All @@ -97,7 +102,7 @@ mv $TEMP /tmp/burrow-detached-daemon"#,
.output()
.unwrap();

Command::new("/tmp/burrow-detached-daemon")
Command::new(BURROW_LOCAL_DAEMON_PATH)
.env("RUST_LOG", "debug")
.arg("daemon")
.spawn()
Expand Down

0 comments on commit 555650b

Please sign in to comment.