From 6c752cbb2489fb9645f5abdb0542f13f37e13d7b Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Wed, 17 Aug 2016 23:40:15 -0700 Subject: [PATCH 1/2] Linux: dynamically detect dependencies and list package names This uses LookPath to check for dependency existence and outputs a list of whichever dependencies are not yet installed. Also outputs example apt/yum commands. --- linux.go | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/linux.go b/linux.go index 62a56c0..d49fdb2 100644 --- a/linux.go +++ b/linux.go @@ -23,12 +23,39 @@ func NewLinuxTracker() Tracker { } func (t *LinuxTracker) Deps() string { - return `Install the following command-line utilities via your package manager (e.g., apt) of choice: -* xdpyinfo -* xwininfo -* xdotool -* wmctrl -` + var output = "\r\nInstall these following command-line utilities via your package manager (e.g., apt) of choice:\r\n" + var depsRequired = false + if !verifyCommand("xdpyinfo") { + output += "\r\n* xdpyinfo" + depsRequired = true + } + if !verifyCommand("xwininfo") { + output += "\r\n* xwininfo" + depsRequired = true + } + if !verifyCommand("xdotool") { + output += "\r\n* xdotool" + depsRequired = true + } + if !verifyCommand("wmctrl") { + output += "\r\n* wmctrl" + depsRequired = true + } + + if depsRequired { + return output+"\r\n\r\nExample deb/apt install command: apt-get install x11-utils xdotool wmctrl\r\nExample rpm/yum install command: yum install xorg-x11-utils xdotool wmctrl" + } else { + return `All dependencies already installed.` + } +} + +func verifyCommand(file string) bool { + var _, err = exec.LookPath(file) + if err != nil { + return false + } else { + return true + } } func (t *LinuxTracker) Snap() (*Snapshot, error) { From be7551a56a14e183ce476645b25ea27b96bd50e0 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Thu, 18 Aug 2016 11:17:58 -0700 Subject: [PATCH 2/2] Break long string up into shorter strings --- linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linux.go b/linux.go index d49fdb2..b3a993a 100644 --- a/linux.go +++ b/linux.go @@ -43,7 +43,9 @@ func (t *LinuxTracker) Deps() string { } if depsRequired { - return output+"\r\n\r\nExample deb/apt install command: apt-get install x11-utils xdotool wmctrl\r\nExample rpm/yum install command: yum install xorg-x11-utils xdotool wmctrl" + output += "\r\n\r\nExample deb/apt install command: apt-get install x11-utils xdotool wmctrl" + output += "\r\nExample rpm/yum install command: yum install xorg-x11-utils xdotool wmctrl" + return output } else { return `All dependencies already installed.` }