Files
probo/cmd/probo-agent/GNUmakefile
Ludovic Vielle 85864a580c Install macOS helper from PKG for XPC enroll
Browser enrollment used osascript on every elevate. Ship a signed
privileged helper installed at PKG time so probo:// can enroll over
XPC with no second admin prompt. Add make install/uninstall/clean for
local PKG test loops, and show alerts only on failure.

Mirror the Go lint path for the macOS SPM package: Make
targets, root configs, and a Linux CI job. Keep checks
syntax-only so they do not need a macOS SDK. Format the
existing sources so the new gates start clean.

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
2026-07-24 15:08:37 +02:00

182 lines
5.6 KiB
Makefile

# Local build / install helpers for probo-agent.
#
# macOS (primary for browser-enroll testing):
# make install build signed PKG, uninstall leftovers, install PKG
# make uninstall remove all system artifacts (idempotent)
# make clean uninstall + wipe local build caches
#
# Requires on Darwin: CODESIGN_IDENTITY, APPLE_TEAM_ID
# Optional: INSTALLER_IDENTITY; notarize via APPLE_ID+APPLE_ID_PASSWORD
# (stored into a keychain profile; submit uses --keychain-profile)
#
# CLI-only (no app / helper), any Unix:
# make install-cli
# make run
CP ?= cp
MKDIR ?= mkdir -p
RMRF ?= rm -rf
SUDO ?= sudo
REPO_ROOT= $(abspath ../..)
PROBO_AGENT_BIN= $(REPO_ROOT)/bin/probo-agent
VERSION= $(shell cat VERSION)
STATE_DIR= $(HOME)/.local/share/probo-agent-dev
CACHE_ROOT= $(HOME)/.cache/probo-agent-dev
DEV_TAG= probo-agent/dev
BINARY= /usr/local/bin/probo-agent
RELEASE_DIR= $(CACHE_ROOT)/release/$(DEV_TAG)
INSTALL_SCRIPT= installer/install.sh
MACOS_BUILD_SCRIPT= installer/macos/build.sh
MACOS_UNINSTALL_SCRIPT= installer/macos/uninstall.sh
MACOS_REINSTALL_SCRIPT= installer/macos/reinstall.sh
ENROLL_UI_BUILD= installer/macos/enroll-ui/.build
UNAME_S:= $(shell uname -s)
UNAME_M:= $(shell uname -m)
ifeq ($(UNAME_S),Darwin)
OS_LABEL= Darwin
else ifeq ($(UNAME_S),Linux)
OS_LABEL= Linux
else ifeq ($(UNAME_S),FreeBSD)
OS_LABEL= Freebsd
else
OS_LABEL=
endif
ifeq ($(UNAME_M),x86_64)
ARCH_LABEL= x86_64
BUILD_ARCH= amd64
else ifeq ($(UNAME_M),amd64)
ARCH_LABEL= x86_64
BUILD_ARCH= amd64
else ifeq ($(UNAME_M),arm64)
ARCH_LABEL= arm64
BUILD_ARCH= arm64
else ifeq ($(UNAME_M),aarch64)
ARCH_LABEL= arm64
BUILD_ARCH= arm64
else
ARCH_LABEL=
BUILD_ARCH=
endif
AGENT_DIR= probo-agent_$(OS_LABEL)_$(ARCH_LABEL)
ARCHIVE_NAME= $(AGENT_DIR).tar.gz
ARCHIVE_PATH= $(RELEASE_DIR)/$(ARCHIVE_NAME)
STAGING_DIR= $(CACHE_ROOT)/staging/$(AGENT_DIR)
BUILD_BINARY= $(STAGING_DIR)/probo-agent
PKG= $(REPO_ROOT)/dist/probo-agent_$(VERSION)_darwin_$(ARCH_LABEL).pkg
INSTALL_ARGS?= --skip-service --dir "$(STATE_DIR)"
INSTALL_ENV= PROBO_AGENT_RELEASE_TAG="$(DEV_TAG)" \
PROBO_AGENT_RELEASE_BASE="file://$(abspath $(RELEASE_DIR))" \
PROBO_AGENT_SKIP_CHECKSUM_VERIFY=true \
PROBO_AGENT_STATE_DIR="$(STATE_DIR)" \
PROBO_SERVER_URL="$(PROBO_SERVER_URL)" \
PROBO_ENROLLMENT_TOKEN="$(PROBO_ENROLLMENT_TOKEN)"
.PHONY: help all pkg install uninstall clean clean-build install-cli run
.PHONY: $(PROBO_AGENT_BIN)
all: help
help: ## Show targets
@printf '%s\n' \
'Targets:' \
' install macOS: build signed PKG, wipe previous install, install PKG' \
' other: same as install-cli' \
' uninstall Remove system install (macOS: full PKG/helper/app teardown)' \
' clean uninstall + remove local build caches' \
' clean-build Remove local caches only (no sudo)' \
' pkg Build signed macOS PKG to dist/ (Darwin only)' \
' install-cli Install binary via installer/install.sh (dev state dir)' \
' run Foreground run against install-cli state dir' \
'' \
'Darwin install requires CODESIGN_IDENTITY and APPLE_TEAM_ID.'
# --- primary local test loop -------------------------------------------------
install: ## Install for local testing (PKG on macOS)
ifeq ($(UNAME_S),Darwin)
$(MAKE) pkg
$(SUDO) "$(MACOS_REINSTALL_SCRIPT)" "$(PKG)"
else
$(MAKE) install-cli
endif
uninstall: ## Remove all system artifacts
ifeq ($(UNAME_S),Darwin)
$(SUDO) "$(MACOS_UNINSTALL_SCRIPT)"
else
@if [ -x "$(BINARY)" ]; then \
$(SUDO) "$(BINARY)" uninstall || true; \
fi
$(SUDO) $(RMRF) "$(BINARY)"
endif
clean: uninstall clean-build ## uninstall + wipe build caches
clean-build: ## Wipe local build caches (no sudo)
$(RMRF) "$(STATE_DIR)" "$(CACHE_ROOT)" "$(ENROLL_UI_BUILD)"
@# Unquoted globs so the shell can expand dist artifacts.
-$(RMRF) $(REPO_ROOT)/dist/probo-agent_*.pkg
@# Native binary under /usr/local is owned by root after install; leave it
@# to `uninstall`. Never remove it here without sudo.
# --- macOS PKG ---------------------------------------------------------------
pkg: $(PKG) ## Build signed .pkg into dist/
$(PKG): $(PROBO_AGENT_BIN)
ifeq ($(UNAME_S),Darwin)
@if [ -z "$(CODESIGN_IDENTITY)" ]; then \
echo 'error: CODESIGN_IDENTITY is required' >&2; exit 2; \
fi
@if [ -z "$(APPLE_TEAM_ID)" ]; then \
echo 'error: APPLE_TEAM_ID is required' >&2; exit 2; \
fi
@if [ -z "$(BUILD_ARCH)" ]; then \
echo 'error: unsupported arch $(UNAME_M)' >&2; exit 2; \
fi
@$(MKDIR) "$(dir $(PKG))"
@CODESIGN_IDENTITY="$(CODESIGN_IDENTITY)" \
APPLE_TEAM_ID="$(APPLE_TEAM_ID)" \
INSTALLER_IDENTITY="$(INSTALLER_IDENTITY)" \
APPLE_ID="$(APPLE_ID)" \
APPLE_ID_PASSWORD="$(APPLE_ID_PASSWORD)" \
NOTARYTOOL_KEYCHAIN_PROFILE="$(NOTARYTOOL_KEYCHAIN_PROFILE)" \
sh "$(MACOS_BUILD_SCRIPT)" \
--binary "$(PROBO_AGENT_BIN)" \
--arch "$(BUILD_ARCH)" \
--version "$(VERSION)" \
--output "$(PKG)"
else
@echo 'error: pkg target is macOS-only' >&2
@exit 1
endif
# --- CLI-only (no Probo Agent.app / helper) ----------------------------------
install-cli: $(ARCHIVE_PATH) ## Install binary only via install.sh
@$(SUDO) $(INSTALL_ENV) sh "$(INSTALL_SCRIPT)" $(INSTALL_ARGS)
run: ## Run agent in foreground (install-cli state dir)
$(SUDO) "$(BINARY)" run --dir "$(STATE_DIR)"
$(ARCHIVE_PATH): $(BUILD_BINARY)
$(MKDIR) "$(RELEASE_DIR)"
tar -czf "$(ARCHIVE_PATH)" -C "$(CACHE_ROOT)/staging" "$(AGENT_DIR)"
$(PROBO_AGENT_BIN):
$(MAKE) -C "$(REPO_ROOT)" bin/probo-agent
$(BUILD_BINARY): $(PROBO_AGENT_BIN)
$(MKDIR) "$(STAGING_DIR)"
$(CP) "$(PROBO_AGENT_BIN)" "$(BUILD_BINARY)"
$(CP) "$(REPO_ROOT)/README.md" "$(REPO_ROOT)/LICENSE" "$(STAGING_DIR)/"
@if [ -f CHANGELOG.md ]; then $(CP) CHANGELOG.md "$(STAGING_DIR)/"; fi