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 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 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. 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 portStr string var selectedPort PortInfo 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 } portStr = selectedPort.Port } else { portStr = args[0] if _, err := strconv.Atoi(portStr); err != nil { log.Error("Invalid port number provided: %s. Port must be an integer.", portStr) return } } log.Message("Attempting to find process on port %s...", portStr) tool := findPortTool() if tool == "" { log.Error("No suitable tool found for finding processes on ports.") return } var lsofCmd *exec.Cmd switch tool { case "lsof": lsofCmd = exec.Command("lsof", "-ti:"+portStr) case "ss": lsofCmd = exec.Command( "sh", "-c", fmt.Sprintf("ss -tulpn | grep ':%s ' | grep -o 'pid=[0-9]*' | cut -d'=' -f2 | head -1", portStr), ) case "netstat": lsofCmd = exec.Command( "sh", "-c", fmt.Sprintf("netstat -tulpn | grep ':%s ' | awk '{print $7}' | cut -d'/' -f1 | head -1", portStr), ) } log.Verbose(isVerbose, "Executing: %s", lsofCmd.String()) outputBytes, err := lsofCmd.CombinedOutput() output := strings.TrimSpace(string(outputBytes)) if err != nil { log.Verbose(isVerbose, "Command finished with error: %v", err) log.Verbose(isVerbose, "lsof output: %s", output) // Check if the error is ExitError and output is empty - common case for "port not found" var exitErr *exec.ExitError if errors.As(err, &exitErr) && output == "" { log.Warn("No process found listening on port %s.", portStr) } else { log.Error("Failed to execute command: %v", err) log.Error("Command output (if any): %s", output) } return } if output == "" { log.Warn("lsof ran successfully but found no process ID on port %s.", portStr) return } pids := strings.Fields(output) if len(pids) == 0 { log.Warn("Command ran successfully but found no process ID on port %s.", portStr) return } killedCount := 0 errorCount := 0 for _, pid := range pids { log.Info("Found process with PID %s on port %s. Attempting to kill...", pid, portStr) killCmd := exec.Command("kill", "-"+signal, pid) log.Verbose(isVerbose, "Executing: %s", killCmd.String()) if err := killCmd.Run(); err != nil { log.Error("Failed to kill process with PID %s: %v", pid, err) if strings.Contains(err.Error(), "permission denied") { log.Warn("Try running with sudo: sudo kill -%s %s", signal, pid) } errorCount++ } else { log.Success("Successfully sent kill signal %s to process with PID %s.", signal, pid) killedCount++ } } if killedCount > 0 && errorCount == 0 { log.Success("Finished killing process(es) on port %s.", portStr) } else if killedCount > 0 && errorCount > 0 { log.Warn( "Finished attempting to kill process(es) on port %s, but encountered %d error(s).", portStr, errorCount, ) } else if killedCount == 0 && errorCount > 0 { log.Error("Failed to kill any process found on port %s.", portStr) } }, }
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. 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 pidStr string var selectedProcess ProcessInfo 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 } pidStr = selectedProcess.PID } else { pidStr = args[0] if _, err := strconv.Atoi(pidStr); err != nil { log.Error("Invalid PID provided: %s. PID must be an integer.", pidStr) return } } log.Message("Attempting to kill process with PID %s...", pidStr) killCmd := exec.Command("kill", "-"+processSignal, pidStr) log.Verbose(isVerbose, "Executing: %s", killCmd.String()) if err := killCmd.Run(); err != nil { log.Error("Failed to kill process with PID %s: %v", pidStr, err) if strings.Contains(err.Error(), "permission denied") { log.Warn("Try running with sudo: sudo kill -%s %s", processSignal, pidStr) } } else { log.Success("Successfully sent kill signal %s to process with PID %s.", processSignal, pidStr) } }, }
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 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)`, 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 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{"update", "u"}, Short: "Update the system and perform maintenance", Long: `This command updates the system, Homebrew packages, asdf plugins, 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...") checkCmd := execCommand("uname", "-a") output, err := checkCmd.Output() if err != nil { log.Error("Error checking system type: %s", err) return } uname := strings.ToLower(string(output)) log.Verbose(isVerbose, "System type detected: %s", strings.TrimSpace(string(output))) if strings.Contains(uname, "ubuntu") || strings.Contains(uname, "linux") { log.Verbose(isVerbose, "Detected Ubuntu/Linux system, running system update...") updateUbuntu(isVerbose, autoApprove, cleanupTimeout) } else if strings.Contains(uname, "darwin") { log.Verbose(isVerbose, "Detected macOS system, running macOS update...") updateMacOS(isVerbose) } else if strings.Contains(uname, "raspberrypi") || strings.Contains(uname, "raspbian") { log.Verbose(isVerbose, "Detected Raspberry Pi system, running Raspberry Pi update...") updateRaspberryPi(isVerbose) } else { log.Warn("This system is not yet supported for updates.") log.Verbose(isVerbose, "Unsupported system type: %s", strings.TrimSpace(string(output))) } }, }
UpdateCmd represents the system update command.
Functions ¶
func EnsurePrerequisites ¶ added in v0.28.0
EnsurePrerequisites checks and installs core prerequisites needed for setup flows. SSH is handled contextually by callers that need GitHub access.
func SetupSSHForGitHub ¶ added in v1.9.0
SetupSSHForGitHub exposes the SSH setup flow for other commands that need GitHub access.
Types ¶
type ProcessInfo ¶ added in v0.31.0
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
}
Click to show internal directories.
Click to hide internal directories.