Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions augment/hooks/mdm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,16 +1184,17 @@ def _is_unbound(cmd: str) -> bool:
return "failed"


def clear_setup():
def clear_setup() -> bool:
print("=" * 60)
print("Augment Code Hooks - Clearing MDM Setup")
print("=" * 60)

if not check_admin_privileges():
print("This script requires administrator/root privileges")
print(" Please re-run with sudo.")
return
return False

teardown_failed = False
print("\nClearing environment variables...")
# Windows `reg delete HKLM\...` is machine-wide; fall through with a
# placeholder so the removal runs even if C:\Users has no profiles.
Expand All @@ -1220,6 +1221,7 @@ def clear_setup():
elif not_found:
print(f"API_KEY not set, nothing to clear for {not_found} user(s)")
if failed:
teardown_failed = True
print(f"Failed to clear API_KEY for {failed} user(s)")

print("\nClearing managed hooks...")
Expand All @@ -1230,11 +1232,13 @@ def clear_setup():
elif status == "not_found":
print(f"Managed hooks not found in {managed_dir}")
else:
teardown_failed = True
print(f"Failed to clear managed hooks in {managed_dir}")

print("\n" + "=" * 60)
print("Clear Complete!")
print("=" * 60)
return not teardown_failed


def detect_install_state() -> Optional[str]:
Expand Down Expand Up @@ -1291,8 +1295,7 @@ def main():
print("[backfill] Augment backfill is not supported.")

if clear_mode:
clear_setup()
return
return clear_setup()

print("=" * 60)
print("Augment Code Hooks - MDM Setup")
Expand All @@ -1306,7 +1309,7 @@ def main():
)
print("This script requires administrator/root privileges")
print(" Please re-run with sudo.")
return
return False

base_url = "https://backend.getunbound.ai"
gateway_url = DEFAULT_GATEWAY_URL
Expand Down Expand Up @@ -1341,27 +1344,27 @@ def main():
print("\nMissing required argument: --api-key")
print("Usage: sudo python3 setup.py --api-key <api_key> [--backend-url <url>] [--app_name <app_name>] [--debug]")
print(" Or: sudo python3 setup.py --clear [--debug]")
return
return False

print("\nGetting device identifier...")
device_id = get_device_identifier()
if not device_id:
print("Failed to get device identifier")
return
return False
debug_print(f"Device identifier: {device_id}")
print("Device identifier retrieved")

print("\nFetching API key from MDM...")
api_key = fetch_api_key_from_mdm(base_url, app_name, auth_api_key, device_id)
if not api_key:
return
return False
print("API key received")

print("\nSetting environment variables system-wide...")
success, _ = set_env_var_system_wide("UNBOUND_AUGMENT_API_KEY", api_key)
if not success:
print("Failed to set UNBOUND_AUGMENT_API_KEY")
return
return False
debug_print("UNBOUND_AUGMENT_API_KEY set successfully")

# Write the per-user unbound config now (needed by the managed hook; harmless
Expand All @@ -1376,7 +1379,7 @@ def main():
print("\nConfiguring Augment managed hooks...")
if not setup_managed_hooks(gateway_url=gateway_url):
print("Failed to configure managed hooks")
return
return False
managed_dir = get_managed_settings_dir()
print(f"Created managed hooks in {managed_dir}")

Expand All @@ -1397,12 +1400,16 @@ def main():

notify_setup_complete(api_key, "augment_code", backend_url=base_url, install_state=state, serial_number=device_id)

return True


if __name__ == "__main__":
try:
main()
ok = main()
except KeyboardInterrupt:
print("\n\nSetup cancelled.")
sys.exit(1)
except Exception as e:
print(f"\nError: {e}")
exit(1)
sys.exit(1)
sys.exit(0 if ok else 1)
33 changes: 20 additions & 13 deletions claude-code/gateway/mdm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,16 +807,17 @@ def _clear_env_var_across_users(var_name: str, user_homes, label: str = None) ->
return cleared, not_found, failed


def clear_setup():
def clear_setup() -> bool:
print("=" * 60)
print("Claude Code - Clearing MDM Setup")
print("=" * 60)

if not check_admin_privileges():
print("This script requires administrator/root privileges")
print(" Please re-run with sudo.")
return
return False

teardown_failed = False
print("\nClearing environment variables...")
user_homes = get_all_user_homes() or ([(None, None)] if platform.system().lower() == "windows" else [])

Expand All @@ -830,6 +831,7 @@ def clear_setup():
elif not (f1 or f2):
print(f"API_KEY not set, nothing to clear for {n1} user(s)")
if f1 or f2:
teardown_failed = True
print(f"Failed to clear for {max(f1, f2)} user(s)")

print("\nClearing managed settings...")
Expand All @@ -840,11 +842,13 @@ def clear_setup():
elif status == "not_found":
print(f"Managed settings not found in {managed_dir}")
else:
teardown_failed = True
print(f"Failed to clear managed settings in {managed_dir}")

print("\n" + "=" * 60)
print("Clear Complete!")
print("=" * 60)
return not teardown_failed


def detect_install_state() -> Optional[str]:
Expand Down Expand Up @@ -904,8 +908,7 @@ def main():
debug_print("Debug mode enabled")

if clear_mode:
clear_setup()
return
return clear_setup()

print("=" * 60)
print("Claude Code - MDM Setup")
Expand All @@ -919,7 +922,7 @@ def main():
)
print("❌ This script requires administrator/root privileges")
print(" Please re-run with sudo.")
return
return False

base_url = "https://backend.getunbound.ai"
gateway_url = DEFAULT_GATEWAY_URL
Expand Down Expand Up @@ -950,13 +953,13 @@ def main():
print("\n❌ Missing required argument: --api-key")
print("Usage: sudo python3 setup.py --api-key <api_key> [--backend-url <url>] [--app_name <app_name>] [--debug]")
print(" Or: sudo python3 setup.py --clear [--debug]")
return
return False

print("\n🔍 Getting device identifier...")
device_id = get_device_identifier()
if not device_id:
print("❌ Failed to get device identifier")
return
return False
debug_print(f"Device identifier: {device_id}")
print("✅ Device identifier retrieved")

Expand All @@ -966,7 +969,7 @@ def main():
print("\n🔑 Fetching API key from MDM...")
claude_api_key = fetch_api_key_from_mdm(base_url, app_name, auth_api_key, device_id)
if not claude_api_key:
return
return False
print("✅ API key received")

print("\n📝 Setting environment variables system-wide...")
Expand All @@ -977,13 +980,13 @@ def main():
success, env_changed = set_env_var_system_wide("UNBOUND_API_KEY", claude_api_key)
if not success:
print(f"❌ Failed to set UNBOUND_API_KEY")
return
return False
debug_print("UNBOUND_API_KEY set successfully")

success, url_changed = set_env_var_system_wide("ANTHROPIC_BASE_URL", gateway_url)
if not success:
print(f"❌ Failed to set ANTHROPIC_BASE_URL")
return
return False
debug_print("ANTHROPIC_BASE_URL set successfully")

# Remove leftover hooks scripts, strip leftover user-level Unbound
Expand All @@ -1000,20 +1003,24 @@ def main():
print(f"✅ Created managed settings in {managed_dir}")
else:
print("❌ Failed to configure managed settings")
return
return False

print("\n" + "=" * 60)
print("Setup Complete!")
print("=" * 60)

notify_setup_complete(claude_api_key, "unbound-claude-code", backend_url=base_url, install_state=install_state, serial_number=device_id)

return True


if __name__ == "__main__":
try:
main()
ok = main()
except KeyboardInterrupt:
print("\n\n⚠️ Setup cancelled.")
sys.exit(1)
except Exception as e:
print(f"\n❌ Error: {e}")
exit(1)
sys.exit(1)
sys.exit(0 if ok else 1)
31 changes: 19 additions & 12 deletions claude-code/hooks/mdm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,16 +1117,17 @@ def clear_managed_hooks() -> str:
return "failed"


def clear_setup():
def clear_setup() -> bool:
print("=" * 60)
print("Claude Code Hooks - Clearing MDM Setup")
print("=" * 60)

if not check_admin_privileges():
print("This script requires administrator/root privileges")
print(" Please re-run with sudo.")
return
return False

teardown_failed = False
print("\nClearing environment variables...")
# Windows `reg delete HKLM\...` is machine-wide; fall through with a
# placeholder so the removal runs even if C:\Users has no profiles.
Expand All @@ -1153,6 +1154,7 @@ def clear_setup():
elif not_found:
print(f"API_KEY not set, nothing to clear for {not_found} user(s)")
if failed:
teardown_failed = True
print(f"Failed to clear API_KEY for {failed} user(s)")

print("\nClearing managed hooks...")
Expand All @@ -1163,11 +1165,13 @@ def clear_setup():
elif status == "not_found":
print(f"Managed hooks not found in {managed_dir}")
else:
teardown_failed = True
print(f"Failed to clear managed hooks in {managed_dir}")

print("\n" + "=" * 60)
print("Clear Complete!")
print("=" * 60)
return not teardown_failed


def _backfill_collect_session(transcript_path: Path) -> Optional[Dict]:
Expand Down Expand Up @@ -1611,8 +1615,7 @@ def main():
DEBUG = True

if clear_mode:
clear_setup()
return
return clear_setup()

print("=" * 60)
print("Claude Code Hooks - MDM Setup")
Expand All @@ -1626,7 +1629,7 @@ def main():
)
print("This script requires administrator/root privileges")
print(" Please re-run with sudo.")
return
return False

base_url = "https://backend.getunbound.ai"
gateway_url = DEFAULT_GATEWAY_URL
Expand Down Expand Up @@ -1665,20 +1668,20 @@ def main():
print("\nMissing required argument: --api-key")
print("Usage: sudo python3 setup.py --api-key <api_key> [--backend-url <url>] [--app_name <app_name>] [--debug] [--backfill]")
print(" Or: sudo python3 setup.py --clear [--debug]")
return
return False

print("\nGetting device identifier...")
device_id = get_device_identifier()
if not device_id:
print("Failed to get device identifier")
return
return False
debug_print(f"Device identifier: {device_id}")
print("Device identifier retrieved")

print("\nFetching API key from MDM...")
api_key = fetch_api_key_from_mdm(base_url, app_name, auth_api_key, device_id)
if not api_key:
return
return False
print("API key received")

print("\nSetting environment variables system-wide...")
Expand All @@ -1690,7 +1693,7 @@ def main():
success, _ = set_env_var_system_wide("UNBOUND_CLAUDE_API_KEY", api_key)
if not success:
print("Failed to set UNBOUND_CLAUDE_API_KEY")
return
return False
debug_print("UNBOUND_CLAUDE_API_KEY set successfully")

# Remove gateway artifacts, strip leftover user-level Unbound hooks
Expand All @@ -1708,7 +1711,7 @@ def main():
print(f"Created managed hooks in {managed_dir}")
else:
print("Failed to configure managed hooks")
return
return False

print("\n" + "=" * 60)
print("Setup Complete!")
Expand All @@ -1719,12 +1722,16 @@ def main():
if backfill_mode:
run_backfill(api_key, base_url, get_all_user_homes())

return True


if __name__ == "__main__":
try:
main()
ok = main()
except KeyboardInterrupt:
print("\n\nSetup cancelled.")
sys.exit(1)
except Exception as e:
print(f"\nError: {e}")
exit(1)
sys.exit(1)
sys.exit(0 if ok else 1)
Loading