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

system

package
v0.17.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FindNonMovieFoldersCmd = &cobra.Command{
	Use:   "findNonMovieFolders",
	Short: "Find and optionally delete non-movie folders",
	Long:  `This command searches recursively through the supplied directory for directories that do not contain video files. It can also delete these directories if the dry-run flag is not set.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Warn("You need to supply the directory to search for non-movie folders.")
			return
		}

		directory := args[0]
		dryRun, _ := cmd.Flags().GetBool("dry-run")
		verbose := utils.IsVerbose(cmd)

		log.Verbose(verbose, "Searching for directories in: %s", directory)

		findCmd := exec.Command("find", directory, "-type", "d")
		folders, err := findCmd.Output()
		if err != nil {
			log.Error("Error finding directories: %s", err)
			return
		}

		log.Verbose(verbose, "Found directories: %s", strings.TrimSpace(string(folders)))

		for _, folder := range strings.Split(string(folders), "\n") {
			if folder == "" {
				continue
			}

			log.Verbose(verbose, "Checking folder: %s", folder)

			checkCmd := exec.Command("find", folder, "-type", "f", "-iregex", ".*\\.(mp4|mkv|avi|mov|wmv|flv|webm|mpeg|mpg)")
			files, err := checkCmd.Output()
			if err != nil {
				log.Error("Error checking folder %s: %s", folder, err)
				continue
			}

			if strings.TrimSpace(string(files)) == "" {

				listFilesCmd := exec.Command("find", folder, "-type", "f")
				filesToDelete, err := listFilesCmd.Output()
				if err != nil {
					log.Error("Error listing files in folder %s: %s", folder, err)
					continue
				}
				if verbose {
					for _, file := range strings.Split(string(filesToDelete), "\n") {
						if file != "" {
							log.Warn("Would delete file: %s", file)
						}
					}
					log.Warn("Would delete folder: %s", folder)
				}
				if dryRun {
					log.Message("Dry-run: Found non-movie folder: %s", folder)
				} else {
					log.Message("Deleting non-movie folder: %s", folder)
					deleteCmd := exec.Command("rm", "-rf", folder)
					if err := deleteCmd.Run(); err != nil {
						log.Error("Error deleting folder %s: %s", folder, err)
					}
				}
			} else {
				log.Verbose(verbose, "Skipping folder (contains movie file): %s", folder)
			}
		}
	},
}
View Source
var KillPortCmd = &cobra.Command{
	Use:   "killPort",
	Short: "Kill a supplied port",
	Long:  `This will find what process is running on a supplied port, then kill that process.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			KillString := fmt.Sprintf("kill -9 $(lsof -ti:%s)", strings.Join(args, ","))
			log.Message("This should run: %s", KillString)

			killPortCmd := exec.Command(KillString)
			utils.StartChildProcess(killPortCmd)
		} else {
			log.Warn("You need to supply the port to kill, which will run the following:")
		}
	},
}
View Source
var ProxyCmd = &cobra.Command{
	Use:   "proxy",
	Short: "Show or configure system proxies",
	Long:  `This command displays and manages multiple proxy configurations and allows enabling, disabling, or setting them via subcommands.`,
	Run: func(cmd *cobra.Command, args []string) {
		listProxyConfigurations()
	},
}
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",
	Long:    `This command updates the system. It supports Ubuntu and WSL Linux systems and logs a message for unsupported systems.`,
	Run: func(cmd *cobra.Command, args []string) {
		isVerbose := utils.IsVerbose(cmd)
		log.Verbose(isVerbose, "Checking system type...")

		checkCmd := exec.Command("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)
		} 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)))
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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