Created
May 20, 2020 19:15
-
-
Save ahmetozer/1749a14bf7bf35a39448884067fc6529 to your computer and use it in GitHub Desktop.
Golang check required apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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