Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Created May 20, 2020 19:15
Show Gist options
  • Save ahmetozer/1749a14bf7bf35a39448884067fc6529 to your computer and use it in GitHub Desktop.
Save ahmetozer/1749a14bf7bf35a39448884067fc6529 to your computer and use it in GitHub Desktop.
Golang check required apps
requiredPrograms := []string{"nc", "ls", "bash", "mkdir"}
var requiredapps [4]bool
for i, s := range requiredPrograms {
// Get path of required programs
path, err := exec.LookPath(s)
if err == nil {
fmt.Printf("Required program %v %v found at %v\n", i+1, s, path)
requiredapps[i] = true //save to array
} else {
fmt.Printf("Required program %v %v cannot found.\n", i+1, s)
requiredapps[i] = false
if i < 4 { //sh and df is must required. If is not found in software than exit.
fmt.Printf("Please install %v and run this program again\n", s)
os.Exit(3)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment