check.go 683 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. )
  6. // commandExists checks if a given command exists on the system
  7. func commandExists(cmd string) bool {
  8. _, err := exec.LookPath(cmd)
  9. return err == nil
  10. }
  11. // checkRuntimeEnvironment checks if the required commands are available in the runtime environment
  12. func checkRuntimeEnvironment() bool {
  13. packageMissing := false
  14. commands := []string{"ffmpeg", "smartctl", "mdadm", "lsblk", "blkid", "df"}
  15. for _, cmd := range commands {
  16. if commandExists(cmd) {
  17. fmt.Printf("\033[32m✔\033[0m '%s' exists\n", cmd)
  18. } else {
  19. packageMissing = true
  20. fmt.Printf("\033[31m✘\033[0m '%s' does not exist\n", cmd)
  21. }
  22. }
  23. return !packageMissing
  24. }