From c90e3012d2cfccd0b116e57bfa2247c3121634c6 Mon Sep 17 00:00:00 2001 From: Lucas Manuel Rodriguez Date: Tue, 21 Jun 2022 16:26:14 -0300 Subject: [PATCH] Fix Fleet Desktop opening of URL on Ubuntu 21/22 (#6314) * Fix Fleet Desktop opening URL on Ubuntu 21/22 * Fine tunning: fix for Ubuntu 18 --- orbit/pkg/execuser/execuser_linux.go | 9 ++++++++- orbit/pkg/packaging/linux_shared.go | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/orbit/pkg/execuser/execuser_linux.go b/orbit/pkg/execuser/execuser_linux.go index 5667c5b100..baadb03ca0 100644 --- a/orbit/pkg/execuser/execuser_linux.go +++ b/orbit/pkg/execuser/execuser_linux.go @@ -24,10 +24,13 @@ func run(path string, opts eopts) error { Int64("id", user.id). Msg("running sudo") - arg := []string{"-u", user.name, "-H"} + // Flag `-i` is needed to run the command with the user's context, from `man sudo`: + // "The command is run with an environment similar to the one a user would receive at log in" + arg := []string{"-i", "-u", user.name, "-H"} for _, nv := range opts.env { arg = append(arg, fmt.Sprintf("%s=%s", nv[0], nv[1])) } + arg = append(arg, // TODO(lucas): Default to display 0, revisit when working on // multi-user/multi-session support. This assumes there's only @@ -36,7 +39,11 @@ func run(path string, opts eopts) error { // DBUS_SESSION_BUS_ADDRESS sets the location of the user login session bus. // Required by the libayatana-appindicator3 library to display a tray icon // on the desktop session. + // + // This is required for Ubuntu 18, and not required for Ubuntu 21/22 + // (because it's already part of the user). fmt.Sprintf("DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%d/bus", user.id), + // Append the packaged libayatana-appindicator3 libraries path to LD_LIBRARY_PATH. fmt.Sprintf("LD_LIBRARY_PATH=%s:%s", filepath.Dir(path), os.ExpandEnv("$LD_LIBRARY_PATH")), path, ) diff --git a/orbit/pkg/packaging/linux_shared.go b/orbit/pkg/packaging/linux_shared.go index 97a9cbe1e2..442db18b1b 100644 --- a/orbit/pkg/packaging/linux_shared.go +++ b/orbit/pkg/packaging/linux_shared.go @@ -307,10 +307,15 @@ func writePreRemove(opt Options, path string) error { // We add `|| true` in case the service is not running // or has been manually disabled already. Otherwise, // uninstallation fails. + // + // "pkill fleet-desktop" is required because the application + // runs as user (separate from sudo command that launched it), + // so on some systems it's not killed properly. if err := ioutil.WriteFile(path, []byte(`#!/bin/sh systemctl stop orbit.service || true systemctl disable orbit.service || true +pkill fleet-desktop || true `), constant.DefaultFileMode); err != nil { return fmt.Errorf("write file: %w", err) }