Help us shape the future of Go! Take the 2026 Go Developer Survey

system

package
v1.49.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BrewCmd = &cobra.Command{
	Use:   "brew",
	Short: "Update Homebrew packages only",
	Long:  `This command updates only Homebrew packages, skipping system updates.`,
	Run: func(cmd *cobra.Command, _args []string) {
		isVerbose := cmdutil.IsVerbose(cmd)
		updateBrew(isVerbose)
	},
}

BrewCmd represents the Homebrew update subcommand.

View Source
var CleanCmd = &cobra.Command{
	Use:     "clean",
	Aliases: []string{"cleanup", "prune", "c"},
	Short:   "Clean and reclaim host system storage across OS and developer tools",
	Long: `Orchestrates cross-platform system maintenance across macOS, Ubuntu, Fedora, and Debian/Raspberry Pi.

Cleans package manager caches (APT/DNF/Brew), vacuums systemd journal logs, prunes Docker container and image layers, and cleans outdated asdf tool versions.

Use the --dry-run (-n) flag to preview operations without modifying system data.
Use the --yes (-y) flag to run all available cleanup operations without prompting.`,
	RunE: func(cmd *cobra.Command, _args []string) error {
		headerStyle := lipgloss.NewStyle().
			Bold(true).
			Foreground(theme.Primary).
			MarginBottom(1)
		if !ui.DisableProgress {
			fmt.Fprintln(log.Out, headerStyle.Render("🧹 Host & System Storage Maintenance"))
		}

		isVerbose := cmdutil.IsVerbose(cmd)

		opts := cleanup.SystemCleanOptions{
			Docker: dockerFlagCleanSys,
			DockerOpts: cleanup.DockerCleanOptions{
				All:        allImagesFlagCleanSys,
				OlderThan:  olderThanFlagCleanSys,
				BuildCache: true,
				Volumes:    false,
				DryRun:     dryRunFlagCleanSys,
				Verbose:    isVerbose,
			},
			Journal:        journalFlagCleanSys,
			JournalSize:    journalSizeCleanSys,
			Packages:       packagesFlagCleanSys,
			Asdf:           asdfFlagCleanSys,
			Brew:           brewFlagCleanSys,
			DryRun:         dryRunFlagCleanSys,
			Verbose:        isVerbose,
			AutoApprove:    yesFlagCleanSys,
			CleanupTimeout: timeoutFlagCleanSys,
		}

		report, err := cleanup.RunSystemCleanup(opts)
		if err != nil {
			return err
		}

		if report != nil {
			summary := report.RenderSummaryTable()
			if summary != "" {
				fmt.Println(summary)
			}
		}

		return nil
	},
}

CleanCmd represents the system clean command.

View Source
var CompauditFixCmd = &cobra.Command{
	Use:   "compauditFix",
	Short: "Fix insecure directories reported by compaudit",
	Long:  `Runs 'compaudit' and applies 'chmod g-w,o-w' to any directories reported as insecure. This uses an interactive zsh so zsh functions like compaudit (from oh-my-zsh) are available.`,
	Run: func(cmd *cobra.Command, _args []string) {
		log.Start("Running compaudit and fixing insecure directories...")
		isVerbose := cmdutil.IsVerbose(cmd)

		execCmd := exec.Command("zsh", "-ic", "compaudit | xargs --no-run-if-empty chmod g-w,o-w")
		log.Verbose(isVerbose, "Executing: %s", execCmd.String())

		outputBytes, err := execCmd.CombinedOutput()
		output := strings.TrimSpace(string(outputBytes))

		if err != nil {
			log.Error("Failed to run compaudit fix: %v", err)
			if output != "" {
				log.Error("Output: %s", output)
			}
			return
		}

		if output != "" {

			log.Message("%s", output)
		}

		log.Success("Finished applying compaudit fixes.")
	},
}

CompauditFixCmd runs 'compaudit' and removes group/world write permissions from any reported insecure directories.

View Source
var GPGCmd = &cobra.Command{
	Use:   "gpg",
	Short: "Manage GPG keys for commit signing and encryption",
	Long:  `Manage GPG keys for commit signing, encryption, initial setup, and expiration renewal.`,
	RunE: func(cmd *cobra.Command, _args []string) error {
		return cmd.Help()
	},
}
View Source
var ImmichCmd = &cobra.Command{
	Use:     "immich",
	Aliases: []string{"photos"},
	Short:   "Manage Immich photo stack, database, backups, and lifecycle",
	Long: `Inspect Immich service health, monitor container states, query database metrics,
execute verified backups, perform disaster recovery, and manage systemd services.`,
	RunE: func(cmd *cobra.Command, _args []string) error {
		return cmd.Help()
	},
}

ImmichCmd represents the Immich stack management command.

View Source
var KillPortCmd = &cobra.Command{
	Use:   "killPort [port]",
	Short: "Find and kill the process listening on a specific port",
	Long: `This command finds the process ID (PID) listening on the specified network port
using available tools (lsof, ss, netstat) and then terminates that process.

A comma-separated list of ports may be provided to kill processes on multiple ports, e.g.
"eng system killPort 3000,8080".

If no port is provided or --interactive is used, it lists listening ports for selection.
Requires appropriate tools to be available on the system.
Primarily intended for Unix-like systems (Linux, macOS).`,
	Args: cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		isVerbose := cmdutil.IsVerbose(cmd)

		var portList []string

		if len(args) == 0 || interactive {
			log.Message("Listing listening ports...")
			ports, err := listPorts(filter)
			if err != nil {
				log.Error("Failed to list ports: %v", err)
				return
			}
			if len(ports) == 0 {
				log.Warn("No listening ports found.")
				return
			}
			selectedPort, err := selectPort(ports)
			if err != nil {
				log.Error("Failed to select port: %v", err)
				return
			}
			portList = []string{selectedPort.Port}
		} else {
			log.Message("Parsing ports: %s", args[0])
			var errs []error
			portList, errs = parsePortList(args[0])
			if len(errs) > 0 {
				log.Error("Found %d problem(s) in port list %q:", len(errs), args[0])
				for _, err := range errs {
					log.Error("  - %v", err)
				}
				return
			}
		}

		for _, portStr := range portList {
			killPort(portStr, signal, isVerbose)
		}
	},
}
View Source
var KillProcessCmd = &cobra.Command{
	Use:   "killProcess [pid]",
	Short: "Find and kill a process by PID or interactively",
	Long: `This command finds and kills a process by its PID, or lists processes for interactive selection.

A comma-separated list of PIDs may be provided to kill multiple processes, e.g.
"eng system killProcess 1234,5678".

If no PID is provided or --interactive is used, it lists running processes for selection.
Requires 'ps' and 'kill' commands to be available on the system.
Primarily intended for Unix-like systems (Linux, macOS).`,
	Args: cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		isVerbose := cmdutil.IsVerbose(cmd)

		var pidList []string

		if len(args) == 0 || processInteractive {
			log.Message("Listing running processes...")
			processes, err := listProcesses(processFilter)
			if err != nil {
				log.Error("Failed to list processes: %v", err)
				return
			}
			if len(processes) == 0 {
				log.Warn("No processes found.")
				return
			}
			selectedProcess, err := selectProcess(processes)
			if err != nil {
				log.Error("Failed to select process: %v", err)
				return
			}
			pidList = []string{selectedProcess.PID}
		} else {
			log.Message("Parsing process PIDs: %s", args[0])
			var errs []error
			pidList, errs = parseProcessList(args[0])
			if len(errs) > 0 {
				log.Error("Found %d problem(s) in process PID list %q:", len(errs), args[0])
				for _, err := range errs {
					log.Error("  - %v", err)
				}
				return
			}
		}

		for _, pidStr := range pidList {
			killProcess(pidStr, processSignal, isVerbose)
		}
	},
}
View Source
var ProxyCmd = &cobra.Command{
	Use:   "proxy",
	Short: "Show or configure system proxies",
	Long:  `Display, switch, test, and manage multiple proxy configurations with rich visual feedback.`,
	Run: func(cmd *cobra.Command, args []string) {
		listProxyConfigurations(cmd)
	},
}
View Source
var RenewGPGCmd = &cobra.Command{
	Use:     "renew",
	Aliases: []string{"update", "extend"},
	Short:   "Renew or extend GPG key and subkey expiration",
	Long: `Interactively inspect and extend expiration dates for your GPG key and subkeys.
Imports the master key from a local/cloud backup directory, updates expiration dates,
archives old key files to archive/<date-expired>/, re-exports updated secret and public
key files back to your backup folder with standard names (for cloud sync), publishes
public keys, and strips the master key locally (keeping subkeys only for security).`,
	RunE: func(cmd *cobra.Command, _args []string) error {
		return renewGPG(cmdutil.IsVerbose(cmd))
	},
}
View Source
var SetupASDFCmd = &cobra.Command{
	Use:   "asdf",
	Short: "Setup asdf plugins from $HOME/.tool-versions",
	Long:  `Reads $HOME/.tool-versions and installs asdf plugins listed there.`,
	Run: func(cmd *cobra.Command, args []string) {
		setupASDF(cmdutil.IsVerbose(cmd))
	},
}
View Source
var SetupCmd = &cobra.Command{
	Use:   "setup",
	Short: "Setup development tools",
	Long: `Setup various development tools.
Running this command without subcommands will run all setup steps:
- Oh My Zsh
- ASDF plugins
- Dotfiles installation
- Dotfiles secrets restore (when configured)
- Software installation
- GPG keys setup (interactive)
- GPG permissions fix`,
	RunE: func(cmd *cobra.Command, _args []string) error {
		if err := runSetup(cmd, cmdutil.IsVerbose(cmd)); err != nil {
			return fmt.Errorf("setup failed: %w", err)
		}
		return nil
	},
}
View Source
var SetupDotfilesCmd = &cobra.Command{
	Use:   "dotfiles",
	Short: "Setup dotfiles from your git repository",
	Long: `Setup dotfiles from your git repository. This command will:
	- Check and install prerequisites (Homebrew, Git, Bash)
	- Setup SSH keys for GitHub when required by the repository URL
  - Clone your dotfiles repository as a bare repository
  - Backup any conflicting files
  - Checkout dotfiles to your home directory
  - Initialize git submodules
	- Configure git to hide untracked files
	- Restore dotfiles secrets when manifest and BWS token are available`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := setupDotfiles(cmdutil.IsVerbose(cmd)); err != nil {
			return fmt.Errorf("dotfiles setup failed: %w", err)
		}
		return nil
	},
}
View Source
var SetupGPGCmd = &cobra.Command{
	Use:   "gpg",
	Short: "Setup GPG keys for signing and encryption",
	Long: `Setup GPG keys for signing commits and encryption. This command will:
  - Prompt you for GPG key files to import
  - Import master key and subkeys
  - Set ultimate trust on the key
  - Configure Git to use your GPG key for signing
  - Optionally remove the master key (keeping only subkeys for security)
  - Configure ~/.gnupg and wrapper permissions and restart gpg-agent`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := setupGPG(cmdutil.IsVerbose(cmd)); err != nil {
			return fmt.Errorf("gpg setup failed: %w", err)
		}
		return nil
	},
}
View Source
var SetupOhMyZshCmd = &cobra.Command{
	Use:   "oh-my-zsh",
	Short: "Install Oh My Zsh",
	Long:  `Downloads and installs Oh My Zsh. Skips if already installed.`,
	Run: func(cmd *cobra.Command, args []string) {
		setupOhMyZsh(cmdutil.IsVerbose(cmd))
	},
}
View Source
var SetupSSHCmd = &cobra.Command{
	Use:   "ssh",
	Short: "Setup SSH keys for GitHub access",
	Long: `Setup SSH keys for GitHub access. This command will:
  - Check for existing SSH keys
  - Attempt to retrieve SSH keys from Bitwarden vault
  - Generate new SSH keys if none found
  - Configure SSH config for GitHub`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := SetupSSH(cmdutil.IsVerbose(cmd)); err != nil {
			return fmt.Errorf("ssh setup failed: %w", err)
		}
		return nil
	},
}
View Source
var SyncGPGCmd = &cobra.Command{
	Use:     "sync",
	Aliases: []string{"pull", "fetch", "refresh"},
	Short:   "Sync updated GPG public key and expiration dates from keyservers",
	Long: `Pull and sync updated GPG public keys and signatures from OpenPGP keyservers
and GitHub on secondary devices without needing access to your master key.`,
	RunE: func(cmd *cobra.Command, _args []string) error {
		return syncGPG(cmdutil.IsVerbose(cmd))
	},
}
View Source
var SystemCmd = &cobra.Command{
	Use:   "system",
	Short: "A command for managing the system",
	Long:  `This command will help manage various aspects of MacOS and Linux systems.`,
	Run: func(cmd *cobra.Command, _args []string) {
		err := cmd.Help()
		cobra.CheckErr(err)
	},
}
View Source
var UpdateCmd = &cobra.Command{
	Use:     "update",
	Aliases: []string{"upgrade", "u"},
	Short:   "Update the system and perform maintenance",
	Long:    `This command updates the system, Homebrew packages, asdf plugins, flatpak packages, and performs cleanup operations.`,
	Run: func(cmd *cobra.Command, _args []string) {
		headerStyle := lipgloss.NewStyle().
			Bold(true).
			Foreground(theme.Primary).
			MarginBottom(1)
		if !ui.DisableProgress {
			fmt.Println(headerStyle.Render("🚀 System Maintenance & Update"))
		}

		isVerbose := cmdutil.IsVerbose(cmd)
		autoApprove, _ := cmd.Flags().GetBool("yes")
		cleanupTimeout, _ := cmd.Flags().GetInt("cleanup-timeout")
		log.Verbose(isVerbose, "Checking system type...")

		distro := detectDistro()
		log.Verbose(isVerbose, "System detected: %s (OS: %s, ID: %s)", distro.PrettyName, distro.RawOS, distro.ID)

		if distro.IsFedora() {
			log.Verbose(isVerbose, "Detected Fedora/RHEL system, running DNF system update...")
			updateFedora(isVerbose, autoApprove, cleanupTimeout)
		} else if distro.IsDebianUbuntu() {
			log.Verbose(isVerbose, "Detected Debian/Ubuntu system, running APT system update...")
			updateDebianUbuntu(isVerbose, autoApprove, cleanupTimeout)
		} else if distro.IsMacOS() {
			log.Verbose(isVerbose, "Detected macOS system, running macOS update...")
			updateMacOS(isVerbose)
		} else if distro.IsRaspberryPi() {
			log.Verbose(isVerbose, "Detected Raspberry Pi system, running Raspberry Pi update...")
			updateRaspberryPi(isVerbose, autoApprove, cleanupTimeout)
		} else if distro.IsLinux() {
			log.Verbose(isVerbose, "Detected generic Linux system, running general maintenance...")
			updateGenericLinux(isVerbose, autoApprove, cleanupTimeout)
		} else {
			log.Warn("This system is not yet configured for automated OS updates.")
			log.Verbose(isVerbose, "System type: %s", distro.PrettyName)
			updateBrew(isVerbose)
			updateAsdf(isVerbose)
		}
	},
}

UpdateCmd represents the system update command.

View Source
var UpdateIdeCmd = &cobra.Command{
	Use:     "ide [archive-path-or-url]",
	Aliases: []string{"agy-ide", "antigravity-ide", "antigravity"},
	Short:   "Update or install Antigravity IDE",
	Long: `Download, validate, and install the latest Antigravity IDE release package.
Supports automated download, detecting downloaded archives in ~/Downloads, or specifying an archive directly.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		filePath, _ := cmd.Flags().GetString("file")
		urlPath, _ := cmd.Flags().GetString("url")
		autoApprove, _ := cmd.Flags().GetBool("yes")

		target := ""
		if len(args) > 0 {
			target = args[0]
		} else if filePath != "" {
			target = filePath
		} else if urlPath != "" {
			target = urlPath
		}

		return RunIdeUpdate(cmd.Context(), target, cmdutil.IsVerbose(cmd), autoApprove)
	},
}

UpdateIdeCmd represents the command to update Antigravity IDE.

Functions

func DetectSSHBackupCandidates added in v1.46.0

func DetectSSHBackupCandidates() []string

DetectSSHBackupCandidates scans common local locations for SSH backup folders containing key files.

func EnsurePrerequisites added in v0.28.0

func EnsurePrerequisites(verbose bool) error

EnsurePrerequisites checks and installs core prerequisites needed for setup flows. SSH is handled contextually by callers that need GitHub access.

func EnsureSSHConfig added in v1.46.0

func EnsureSSHConfig(sshKeyPath string) error

EnsureSSHConfig ensures ~/.ssh/config contains the Host github.com configuration block.

func FindGitHubSSHKey added in v1.46.0

func FindGitHubSSHKey(sshDir string) string

FindGitHubSSHKey locates the primary GitHub SSH private key within sshDir.

func GenerateSSHKey added in v1.46.0

func GenerateSSHKey(sshKeyPath string, verbose bool) (bool, error)

GenerateSSHKey generates a new ed25519 SSH key pair and attempts to register it in GitHub.

func MigrateSSHFromBackup added in v1.46.0

func MigrateSSHFromBackup(sourceDir, destDir string, verbose bool) error

MigrateSSHFromBackup copies all SSH keys, public keys, and config from sourceDir into destDir, enforcing secure permissions.

func RunIdeUpdate added in v1.40.0

func RunIdeUpdate(ctx context.Context, target string, verbose, autoApprove bool) error

RunIdeUpdate orchestrates finding, downloading, extracting, validating, and installing the IDE.

func SetupSSH added in v1.46.0

func SetupSSH(verbose bool) error

SetupSSH handles SSH key setup for GitHub and general access with multiple sources.

func SetupSSHForGitHub added in v1.9.0

func SetupSSHForGitHub(verbose bool) error

SetupSSHForGitHub exposes the SSH setup flow for other commands that need GitHub access.

func SetupSSHFromBitwarden added in v1.46.0

func SetupSSHFromBitwarden(sshKeyPath string, verbose bool) error

SetupSSHFromBitwarden retrieves SSH keys from Bitwarden vault and configures them locally.

func ValidateGitHubSSHAuth added in v1.46.0

func ValidateGitHubSSHAuth(sshKeyPath string, verbose bool) error

ValidateGitHubSSHAuth verifies GitHub SSH connectivity using the specified key.

Types

type GPGKeyInfo added in v1.46.0

type GPGKeyInfo struct {
	KeyID       string   // 16-character Long Key ID (e.g. BE363376C8A71C92)
	Fingerprint string   // 40-character Primary Fingerprint
	UID         string   // e.g. "Eric N. Garcia <eng618@garciaericn.com>"
	HasMaster   bool     // true if master secret key is present (sec vs sec#)
	Subkeys     []string // Subkey IDs / fingerprints
}

GPGKeyInfo represents a GPG secret key found in the local keyring.

type PortInfo added in v0.31.0

type PortInfo struct {
	Command string
	PID     string
	Port    string
	User    string
}

type ProcessInfo added in v0.31.0

type ProcessInfo struct {
	Command string
	PID     string
	User    string
}

type Software added in v0.29.0

type Software struct {
	Name        string
	Description string
	Optional    bool
	URL         string      // For manual downloads
	Check       func() bool // Returns true if already installed
	// Install returns an error if installation fails.
	// For manual installs, this typically involves opening a URL.
	Install func() error
	// OS restriction (empty means both, otherwise "linux" or "darwin")
	OS string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL