Skip tray re-register on deep-link enroll

Browser enrollment succeeds once the device is ACTIVE, but the
macOS URL handler failed whenever install re-bootstrapped a tray
LaunchAgent the PKG had already installed. Skip registration when
the plist is current, treat live bootstrap as best-effort, and
exit successfully if the device is already enrolled so retries
do not show "Enrollment failed".

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
Ludovic Vielle
2026-07-19 12:55:57 +02:00
parent 238c19d509
commit 754d12d583
3 changed files with 75 additions and 77 deletions

View File

@@ -25,11 +25,9 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"
"time"
@@ -102,8 +100,6 @@ func newRootCmd() *cobra.Command {
}
func newEnrollURLCmd() *cobra.Command {
var preflight bool
cmd := &cobra.Command{
Use: "enroll-url [url]",
Hidden: true,
@@ -116,32 +112,14 @@ func newEnrollURLCmd() *cobra.Command {
dir := resolveDir(cmd)
if preflight {
enrolled, err := deviceagent.IsEnrolled(deviceagent.EnrollmentRunDir(dir))
if err != nil {
return fmt.Errorf("cannot check enrollment state: %w", err)
}
return writeEnrollPreflight(cmd.OutOrStdout(), serverURL, enrollmentToken, dir, enrolled)
}
already, err := reportIfAlreadyEnrolled(dir)
if err != nil {
return err
}
if already {
return nil
}
if runtime.GOOS == "darwin" {
return fmt.Errorf(
"macOS browser enrollment must use the signed Probo Agent.app " +
"(probo:// deeplink); for CLI use: sudo probo-agent install " +
"--server … --enrollment-token …",
)
}
exePath, err := os.Executable()
if err != nil {
return fmt.Errorf("cannot resolve current executable path: %w", err)
@@ -157,42 +135,9 @@ func newEnrollURLCmd() *cobra.Command {
},
}
cmd.Flags().BoolVar(&preflight, "preflight", false, "validate enrollment URL and print JSON for the macOS URL handler")
return cmd
}
type enrollPreflightResponse struct {
Server string `json:"server"`
Token string `json:"token"`
AlreadyEnrolled bool `json:"alreadyEnrolled"`
ConfigDir string `json:"configDir"`
}
func writeEnrollPreflight(
w io.Writer,
serverURL, enrollmentToken, dir string,
alreadyEnrolled bool,
) error {
payload := enrollPreflightResponse{
Server: serverURL,
Token: enrollmentToken,
AlreadyEnrolled: alreadyEnrolled,
ConfigDir: dir,
}
out, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("cannot encode enrollment preflight response: %w", err)
}
if _, err := fmt.Fprintln(w, string(out)); err != nil {
return fmt.Errorf("cannot write enrollment preflight response: %w", err)
}
return nil
}
// reportIfAlreadyEnrolled prints a success message and returns true when
// the local enrollment marker is already present. Deep-link retries must
// exit 0 so the macOS URL handler does not show "Enrollment failed".
@@ -286,7 +231,6 @@ func newInstallCmd() *cobra.Command {
if err != nil {
return err
}
if already {
return nil
}