Esempio n. 1
0
File: util.go Progetto: Kenshin/gnvm
func getGlobalNodePath() string {
	var path string

	if env, ok := IsSessionEnv("", false); ok {
		if reg, err := regexp.Compile(`\\([0]|[1-9]\d?)(\.([0]|[1-9]\d?)){2}(-x(86|64))?\\$`); err == nil {
			ver := reg.FindString(env)
			path = strings.Replace(env, ver, "", -1)
		}
		return path
	}

	file, err := exec.LookPath(NODE)
	if err != nil {
		if file, err := exec.LookPath(GNVM); err != nil {
			path = getCurrentPath()
		} else {
			path = strings.Replace(file, DIVIDE+GNVM, "", -1)
		}
	} else {
		path = strings.Replace(file, DIVIDE+NODE, "", -1)
	}

	// gnvm.exe and node.exe the same path
	if path == "." {
		path = getCurrentPath()
	}

	return path
}
Esempio n. 2
0
func ensureFuseVersionIsInstalled() error {
	// see if fuse-version is there
	if _, err := exec.LookPath("fuse-version"); err == nil {
		return nil // got it!
	}

	// try installing it...
	log.Debug("fuse-version: no fuse-version. attempting to install.")
	cmd := exec.Command("go", "get", "github.com/jbenet/go-fuse-version/fuse-version")
	cmdout := new(bytes.Buffer)
	cmd.Stdout = cmdout
	cmd.Stderr = cmdout
	if err := cmd.Run(); err != nil {
		// Ok, install fuse-version failed. is it they dont have fuse?
		cmdoutstr := cmdout.String()
		if strings.Contains(cmdoutstr, errStrNoFuseHeaders) {
			// yes! it is! they dont have fuse!
			return fmt.Errorf(errStrFuseRequired)
		}

		log.Debug("fuse-version: failed to install.")
		s := err.Error() + "\n" + cmdoutstr
		return fmt.Errorf(errStrNeedFuseVersion, fuseVersionPkg, dontCheckOSXFUSEConfigKey, s)
	}

	// ok, try again...
	if _, err := exec.LookPath("fuse-version"); err != nil {
		log.Debug("fuse-version: failed to install?")
		return fmt.Errorf(errStrNeedFuseVersion, fuseVersionPkg, dontCheckOSXFUSEConfigKey, err)
	}

	log.Debug("fuse-version: install success")
	return nil
}
Esempio n. 3
0
File: gif.go Progetto: kitak/magick
func init() {
	gifsicleCmd, _ = exec.LookPath("gifsicle")
	if Backend() == "GraphicsMagick" {
		maxGifTries = 3
		convertCmd, _ = exec.LookPath("convert")
	}
}
Esempio n. 4
0
func detectVBoxManageCmd() string {
	cmd := "VBoxManage"
	if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" {
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	if p := os.Getenv("VBOX_MSI_INSTALL_PATH"); p != "" {
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	// Look in default installation path for VirtualBox version > 5
	if path, err := exec.LookPath(filepath.Join("C:\\Program Files\\Oracle\\VirtualBox", cmd)); err == nil {
		return path
	}

	// Look in windows registry
	if p, err := findVBoxInstallDirInRegistry(); err == nil {
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	return detectVBoxManageCmdInPath() //fallback to path
}
func (ti *testInterface) setPointToPoint(suffix int, local, remote string) error {
	ti.name = fmt.Sprintf("gotest%d", suffix)
	ti.local = local
	ti.remote = remote
	xname, err := exec.LookPath("ip")
	if err != nil {
		return err
	}
	ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
		Path: xname,
		Args: []string{"ip", "tunnel", "add", ti.name, "mode", "gre", "local", local, "remote", remote},
	})
	ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
		Path: xname,
		Args: []string{"ip", "tunnel", "del", ti.name, "mode", "gre", "local", local, "remote", remote},
	})
	xname, err = exec.LookPath("ifconfig")
	if err != nil {
		return err
	}
	ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
		Path: xname,
		Args: []string{"ifconfig", ti.name, "inet", local, "dstaddr", remote},
	})
	return nil
}
Esempio n. 6
0
func main() {
	c := CgiServer()
	c.DefaultApp = "blosxom.cgi"
	c.LangMap[".cgi"], _ = exec.LookPath("perl")
	c.LangMap[".php"], _ = exec.LookPath("php-cgi")
	ListenAndServe(":8080", c)
}
Esempio n. 7
0
func main() {
	if len(os.Args) < 2 {
		log.Fatal("Usage")
	}

	path, err := exec.LookPath("./" + os.Args[1])
	if err != nil {
		path, err = exec.LookPath(os.Args[1])
		if err != nil {
			os.Exit(127)
		}
	}

	sigs := make(chan os.Signal, 1) // There is a go routine so I think capacity 1 is enough
	signal.Notify(sigs, syscall.SIGHUP)

	cmd := exec.Command(path)
	cmd.Args = os.Args[2:]
	// WTF is S_IRUSR | S_IWUSR, hoping its 0600
	logFile, err := os.OpenFile("nohup.out", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
	if err != nil {
		log.Fatal("TODO: create it in $HOME")
	}
	cmd.Stdout = logFile
	if err := cmd.Start(); err != nil {
		log.Fatal(err)
	}
	go handleSigs(sigs)
	fmt.Println("Pid of the started process: ", cmd.Process.Pid)
	cmd.Wait()
	sendEmail(cmd)
}
Esempio n. 8
0
func openCommand() (string, error) {
	if p, err := exec.LookPath("xdg-open"); err != nil {
		return exec.LookPath("open")
	} else {
		return p, nil
	}
}
Esempio n. 9
0
/* ============================================================================================ */
func New(environment string, parentId int) *Dialog {
	var err error
	var res = new(Dialog)
	if environment == AUTO || environment == "" {
		for _, pkg := range []string{KDE, GTK, X, CONSOLE} {
			_, err = exec.LookPath(pkg)
			if err == nil {
				res.environment = pkg
				break
			}
		}
		if res.environment == "" {
			fmt.Println("Package not found!\nPlease install " + KDE + " or " + GTK + " or " + X + " or " + CONSOLE)
		}
	} else {
		_, err = exec.LookPath(environment)
		if err == nil {
			res.environment = environment
		} else {
			fmt.Println("Package not found!\nPlease install " + environment)
		}
	}

	if res.environment == "" {
		os.Exit(1)
	}

	res.parentId = parentId
	res.reset()
	return res
}
Esempio n. 10
0
func ProcessExternal(page *gostatic.Page, args []string) error {
	if len(args) < 1 {
		return errors.New("'external' rule needs a command name")
	}
	cmdName := args[0]
	cmdArgs := args[1:]

	path, err := exec.LookPath(cmdName)
	if err != nil {
		path, err = exec.LookPath(filepath.Join(page.Site.Base, cmdName))
		if err != nil {
			return fmt.Errorf("command '%s' not found", cmdName)
		}
	}

	cmd := exec.Command(path, cmdArgs...)
	cmd.Stdin = strings.NewReader(page.Content())
	cmd.Dir = page.Site.Base
	var stderr bytes.Buffer
	cmd.Stderr = &stderr
	data, err := cmd.Output()
	if err != nil {
		return fmt.Errorf("'%s' failed: %s\n%s",
			strings.Join(args, " "), err, stderr.String())
	}

	page.SetContent(string(data))
	return nil
}
Esempio n. 11
0
func openURL(url string) error {
	var command string
	var args []string
	switch runtime.GOOS {
	case "darwin":
		command = "open"
		args = []string{command, url}
	case "windows":
		command = "cmd"
		args = []string{"/c", "start " + url}
	default:
		if _, err := exec.LookPath("xdg-open"); err != nil {
			log.Println("xdg-open is required to open web pages on " + runtime.GOOS)
			os.Exit(2)
		}
		command = "xdg-open"
		args = []string{command, url}
	}
	if runtime.GOOS != "windows" {
		p, err := exec.LookPath(command)
		if err != nil {
			log.Printf("Error finding path to %q: %s\n", command, err)
			os.Exit(2)
		}
		command = p
	}
	return sysExec(command, args, os.Environ())
}
Esempio n. 12
0
func validateEnvironment() {
	var err error
	workingDirectory, err = os.Getwd()
	if err != nil {
		fmt.Fprintln(os.Stderr, "Can't find the working directory")
		os.Exit(1)
	}

	path, err := exec.LookPath(pathToLessc)
	if err != nil {
		fmt.Fprintf(os.Stderr, "The lessc path provided (%s) is invalid\n", path)
		os.Exit(1)
	}

	if enableCSSMin {
		if pathToCSSMin == "" {
			fmt.Fprintf(os.Stderr, "CSS minification invoked but no path provided\n")
			os.Exit(1)
		}

		path, err := exec.LookPath(pathToCSSMin)
		if err != nil {
			fmt.Fprintf(os.Stderr, "CSS minification invoked but the path provided (%s) is invalid\n", path)
			os.Exit(1)
		}
	}
}
Esempio n. 13
0
func init() {
	var err error

	// The executable name will be the directory name.
	if program, err = os.Getwd(); err != nil {
		log.Fatal(err)
	}
	program = filepath.Base(program)

	if _, err = exec.LookPath(program); err != nil {
		if err.(*exec.Error).Err == exec.ErrNotFound {
			if err = exec.Command("go", "install").Run(); err != nil {
				log.Fatal(err)
			}

			log.Printf("Installed %s", program)
		} else {
			log.Fatal(err)
		}
	}

	path, err := exec.LookPath(program)
	if err == nil {
		log.Printf("Using %s at %s", program, path)
	} else {
		log.Fatal(err)
	}
}
// (Un)install symbolic runlevel links
func (s *sysv) manageSymlinks(confPath string, install bool) error {
	var cmd *exec.Cmd

	if _, err := exec.LookPath("chkconfig"); err == nil {
		if install {
			cmd = exec.Command("chkconfig", "--add", s.Name)
		} else {
			cmd = exec.Command("chkconfig", "--del", s.Name)
		}
	} else if _, err := exec.LookPath("update-rc.d"); err == nil {
		if install {
			cmd = exec.Command("update-rc.d", s.Name, "defaults")
		} else {
			cmd = exec.Command("update-rc.d", "-f", s.Name, "remove")
		}
	}

	if cmd != nil {
		if err := cmd.Run(); err != nil {
			return fmt.Errorf("Failed to run %q: %s", strings.Join(cmd.Args, " "), err)
		}
	} else {
		/* Manually install/remove symlinks */
		var base = "/etc"

		/* Debian/ubuntu use /etc/rc[0-6].d; RedHat uses /etc/rc.d/rc[0-6].d */
		if _, err := os.Stat("/etc/rc.d/"); err == nil {
			base = "/etc/rc.d"
		} else if _, err := os.Stat(base + "/rc0.d"); os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "FIXME: no suitable rc.d directory found in /etc")
			os.Exit(1)
		}

		for _, i := range strings.Split(defaultStartLevels, "") {
			path := fmt.Sprintf("%s/rc%s.d/S%s%s", base, i, defaultStartPriority, s.Name)
			if install {
				if err := os.Symlink(confPath, path); err != nil {
					return fmt.Errorf("Failed to create startup link %s: %s", path, err)
				}
			} else {
				if err := os.Remove(path); err != nil {
					return fmt.Errorf("Failed to remove startup link %s: %s", path, err)
				}
			}
		}
		for _, i := range strings.Split(defaultStopLevels, "") {
			path := fmt.Sprintf("%s/rc%s.d/K%s%s", base, i, defaultStopPriority, s.Name)
			if install {
				if err := os.Symlink(confPath, path); err != nil {
					return fmt.Errorf("Failed to create shutdown link %s: %s", path, err)
				}
			} else {
				if err := os.Remove(path); err != nil {
					return fmt.Errorf("Failed to remove shutdown link %s: %s", path, err)
				}
			}
		}
	}
	return nil
}
func (c *Config) initGcloud() error {
	//  check that gcloud is installed
	_, err := exec.LookPath("gcloud")
	if err != nil {
		return fmt.Errorf("gcloud cli is not installed.  Please install and try again\n")
	}

	//  check that java is installed
	_, err = exec.LookPath("java")
	if err != nil {
		return fmt.Errorf("java jre (at least) is not installed.  Please install and try again\n")
	}

	auth_cmd := exec.Command("gcloud", "--verbosity=debug", "auth", "activate-service-account", "--key-file", c.CredentialsFile)
	var stdout, stderr bytes.Buffer
	auth_cmd.Stdout = &stdout
	auth_cmd.Stderr = &stderr
	err = auth_cmd.Run()
	if err != nil {
		return fmt.Errorf("gcloud auth failed with error: %s and stdout of %s\n", stderr.String(), stdout.String())
	}

	// verify that datacloud functions are installed
	//  this will need to be updated when they come out of alpha
	datacloud_cmd := exec.Command("gcloud", "alpha", "dataflow", "-h")
	err = datacloud_cmd.Run()
	if err != nil {
		return fmt.Errorf("gcloud dataflow commands not installed.\n")
	}

	return nil
}
Esempio n. 16
0
func (es *e2eService) startEtcd() (*killCmd, error) {
	dataDir, err := ioutil.TempDir("", "node-e2e")
	if err != nil {
		return nil, err
	}
	es.etcdDataDir = dataDir
	var etcdPath string
	// CoreOS ships a binary named 'etcd' which is really old, so prefer 'etcd2' if it exists
	etcdPath, err = exec.LookPath("etcd2")
	if err != nil {
		etcdPath, err = exec.LookPath("etcd")
	}
	if err != nil {
		glog.Infof("etcd not found in PATH. Defaulting to %s...", defaultEtcdPath)
		_, err = os.Stat(defaultEtcdPath)
		if err != nil {
			return nil, fmt.Errorf("etcd binary not found")
		}
		etcdPath = defaultEtcdPath
	}
	cmd := exec.Command(etcdPath,
		"--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001",
		"--advertise-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001")
	// Execute etcd in the data directory instead of using --data-dir because the flag sometimes requires additional
	// configuration (e.g. --name in version 0.4.9)
	cmd.Dir = es.etcdDataDir
	hcc := newHealthCheckCommand(
		"http://127.0.0.1:4001/v2/keys/", // Trailing slash is required,
		cmd,
		"etcd.log")
	return &killCmd{name: "etcd", cmd: cmd}, es.startServer(hcc)
}
Esempio n. 17
0
func installRubyToolchain() error {
	const toolchain = "sourcegraph.com/sourcegraph/srclib-ruby"

	srclibpathDir := filepath.Join(filepath.SplitList(srclib.Path)[0], toolchain) // toolchain dir under SRCLIBPATH
	if err := os.MkdirAll(filepath.Dir(srclibpathDir), 0700); err != nil {
		return err
	}

	if _, err := exec.LookPath("ruby"); isExecErrNotFound(err) {
		return errors.New("no `ruby` in PATH (do you have Ruby installed properly?)")
	} else if err != nil {
		return err
	}
	if _, err := exec.LookPath("bundle"); isExecErrNotFound(err) {
		return fmt.Errorf("found `ruby` in PATH but did not find `bundle` in PATH; Ruby toolchain requires bundler (run `gem install bundler` to install it)")
	} else if err != nil {
		return err
	}

	log.Println("Downloading Ruby toolchain in", srclibpathDir)
	if err := cloneToolchain(srclibpathDir, toolchain); err != nil {
		return err
	}

	log.Println("Installing deps for Ruby toolchain in", srclibpathDir)
	if err := execCmdInDir(srclibpathDir, "make"); err != nil {
		return fmt.Errorf("%s\n\nTip: If you are using a version of Ruby other than 2.1.2 (the default for srclib), or if you are using your system Ruby, try using a Ruby version manager (such as https://rvm.io) to install a more standard Ruby, and try Ruby 2.1.2.\n\nIf you are still having problems, post an issue at https://github.com/sourcegraph/srclib-ruby/issues with the full log output and information about your OS and Ruby version.\n\n`.", err)
	}

	return nil
}
Esempio n. 18
0
func copyWorld(worlddir, target string) error {
	var cmd string
	var args []string
	var err error

	switch config.HostOS {
	case "linux":
		cmd, err = exec.LookPath("rsync")
		if err == nil {
			args = []string{"-a", worlddir + "/", target}
		} else {
			cmd, err = exec.LookPath("cp")
			if err == nil {
				args = []string{"-r", "-p", "-u", worlddir, target}
			} else {
				return errors.New("Failed to find a suitable copy program (rsync, cp)")
			}
		}

	case "windows":
		cmd, err = exec.LookPath("copy")
		if err != nil {
			return errors.New("Failed to find copy program (copy)")
		}
		//This will do braindead things depending on wether dir exists
		args = []string{"/Y", worlddir, target}
	}

	command := exec.Command(cmd, args...)
	return command.Run()
}
Esempio n. 19
0
// detectVBoxManageCmd detects the VBoxManage cmd's path if needed
func detectVBoxManageCmd() string {
	cmd := "VBoxManage"
	if path, err := exec.LookPath(cmd); err == nil {
		return path
	}

	if runtime.GOOS == "windows" {
		if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" {
			if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
				return path
			}
		}
		if p := os.Getenv("VBOX_MSI_INSTALL_PATH"); p != "" {
			if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
				return path
			}
		}
		// look at HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\VirtualBox\InstallDir
		p := "C:\\Program Files\\Oracle\\VirtualBox"
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	return cmd
}
Esempio n. 20
0
func installTypeScriptToolchain() error {
	const toolchainName = "srclib-typescript"

	srclibpathDir, err := prepareParentDir(toolchainName)
	if err != nil {
		return err
	}

	if _, err := exec.LookPath("node"); isExecErrNotFound(err) {
		return errors.New("no `node` in PATH (do you have Node.js installed properly?)")
	}
	if _, err := exec.LookPath("npm"); isExecErrNotFound(err) {
		return fmt.Errorf("no `npm` in PATH; TypeScript toolchain requires npm")
	}

	if _, err := exec.LookPath("tsc"); isExecErrNotFound(err) {
		return fmt.Errorf("no `tsc` in PATH; TypeScript toolchain requires tsc")
	}

	log.Println("Downloading TypeScript toolchain in", srclibpathDir)
	if err := cloneToolchain(srclibpathDir, toolchainCloneURI(toolchainName)); err != nil {
		return err
	}

	log.Println("Building TypeScript toolchain program")
	if err := execCmdInDir(srclibpathDir, "make"); err != nil {
		return err
	}

	return nil
}
Esempio n. 21
0
// LoadConfig loads TOML config file
func LoadConfig(fn string) error {
	if err := config.Parse(fn); err != nil {
		return err
	}
	if *ConfLoffice != "" {
		if _, err := exec.LookPath(*ConfLoffice); err != nil {
			logger.Warn("msg", "cannot use "+*ConfLoffice+" as loffice!")
			if fn, err := exec.LookPath("soffice"); err == nil {
				logger.Info("msg", "will use "+fn+" instead")
				*ConfLoffice = fn
			}
		}
	}
	if *ConfWorkdir != "" {
		_ = os.Setenv("TMPDIR", *ConfWorkdir)
		Workdir = *ConfWorkdir
	}

	if *ConfPdfseparate != "" {
		bn := filepath.Base(*ConfPdfseparate)
		prefix := (*ConfPdfseparate)[:len(*ConfPdfseparate)-len(bn)]
		for k := range popplerOk {
			if err := exec.Command(prefix+k, "-h").Run(); err == nil {
				popplerOk[k] = prefix + k
			}
		}
	}

	return nil
}
Esempio n. 22
0
// PortForward executes socat in the pod's network namespace and copies
// data between stream (representing the user's local connection on their
// computer) and the specified port in the container.
//
// TODO:
//  - match cgroups of container
//  - should we support nsenter + socat on the host? (current impl)
//  - should we support nsenter + socat in a container, running with elevated privs and --pid=host?
//
// TODO(yifan): Merge with the same function in dockertools.
// TODO(yifan): If the rkt is using lkvm as the stage1 image, then this function will fail.
func (r *runtime) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error {
	glog.V(4).Infof("Rkt port forwarding in container.")

	rktID, err := r.findRktID(pod)
	if err != nil {
		return err
	}

	info, err := r.getPodInfo(rktID)
	if err != nil {
		return err
	}

	_, lookupErr := exec.LookPath("socat")
	if lookupErr != nil {
		return fmt.Errorf("unable to do port forwarding: socat not found.")
	}
	args := []string{"-t", fmt.Sprintf("%d", info.pid), "-n", "socat", "-", fmt.Sprintf("TCP4:localhost:%d", port)}

	_, lookupErr = exec.LookPath("nsenter")
	if lookupErr != nil {
		return fmt.Errorf("unable to do port forwarding: nsenter not found.")
	}
	command := exec.Command("nsenter", args...)
	command.Stdin = stream
	command.Stdout = stream
	return command.Run()
}
Esempio n. 23
0
// GetRstContent calls the Python script rst2html as an external helper
// to convert reStructuredText content to HTML.
func GetRstContent(content []byte) string {
	cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)

	path, err := exec.LookPath("rst2html")
	if err != nil {
		path, err = exec.LookPath("rst2html.py")
		if err != nil {
			jww.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
				"                 Leaving reStructuredText content unrendered.")
			return (string(content))
		}
	}

	cmd := exec.Command(path, "--leave-comments")
	cmd.Stdin = bytes.NewReader(cleanContent)
	var out bytes.Buffer
	cmd.Stdout = &out
	if err := cmd.Run(); err != nil {
		jww.ERROR.Println(err)
	}

	rstLines := strings.Split(out.String(), "\n")
	for i, line := range rstLines {
		if strings.HasPrefix(line, "<body>") {
			rstLines = (rstLines[i+1 : len(rstLines)-3])
		}
	}
	return strings.Join(rstLines, "\n")
}
Esempio n. 24
0
/*
 * Create a new default idmap
 */
func DefaultIdmapSet() (*IdmapSet, error) {
	myname, err := getUsername()
	if err != nil {
		return nil, err
	}

	umin := 1000000
	urange := 100000
	gmin := 1000000
	grange := 100000

	newuidmap, _ := exec.LookPath("newuidmap")
	newgidmap, _ := exec.LookPath("newgidmap")

	if newuidmap != "" && newgidmap != "" && PathExists("/etc/subuid") && PathExists("/etc/subgid") {
		umin, urange, err = getFromMap("/etc/subuid", myname)
		if err != nil {
			return nil, err
		}

		gmin, grange, err = getFromMap("/etc/subgid", myname)
		if err != nil {
			return nil, err
		}
	}

	m := new(IdmapSet)

	e := IdmapEntry{Isuid: true, Nsid: 0, Hostid: umin, Maprange: urange}
	m.Idmap = Extend(m.Idmap, e)
	e = IdmapEntry{Isgid: true, Nsid: 0, Hostid: gmin, Maprange: grange}
	m.Idmap = Extend(m.Idmap, e)

	return m, nil
}
Esempio n. 25
0
func (n *Notifier) SendNotification(title string, subtitle string) {

	if n.commandFlags.Notify {
		onLinux := (runtime.GOOS == "linux")
		onOSX := (runtime.GOOS == "darwin")

		if onOSX {

			_, err := exec.LookPath("terminal-notifier")
			if err == nil {
				args := []string{"-title", title, "-subtitle", subtitle, "-group", "com.onsi.ginkgo"}
				terminal := os.Getenv("TERM_PROGRAM")
				if terminal == "iTerm.app" {
					args = append(args, "-activate", "com.googlecode.iterm2")
				} else if terminal == "Apple_Terminal" {
					args = append(args, "-activate", "com.apple.Terminal")
				}

				exec.Command("terminal-notifier", args...).Run()
			}

		} else if onLinux {

			_, err := exec.LookPath("notify-send")
			if err == nil {
				args := []string{"-a", "ginkgo", title, subtitle}
				exec.Command("notify-send", args...).Run()
			}

		}
	}
}
Esempio n. 26
0
// GetAsciidocContent calls asciidoctor or asciidoc as an external helper
// to convert AsciiDoc content to HTML.
func GetAsciidocContent(content []byte) string {
	cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)

	path, err := exec.LookPath("asciidoctor")
	if err != nil {
		path, err = exec.LookPath("asciidoc")
		if err != nil {
			jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
				"                 Leaving AsciiDoc content unrendered.")
			return (string(content))
		}
	}

	jww.INFO.Println("Rendering with", path, "...")
	cmd := exec.Command(path, "--safe", "-")
	cmd.Stdin = bytes.NewReader(cleanContent)
	var out bytes.Buffer
	cmd.Stdout = &out
	if err := cmd.Run(); err != nil {
		jww.ERROR.Println(err)
	}

	asciidocLines := strings.Split(out.String(), "\n")
	for i, line := range asciidocLines {
		if strings.HasPrefix(line, "<body") {
			asciidocLines = (asciidocLines[i+1 : len(asciidocLines)-3])
		}
	}
	return strings.Join(asciidocLines, "\n")
}
Esempio n. 27
0
func (spec SpecPackage) checkPackage(defaults PlatformDefaults) (err error) {
	var cmd *exec.Cmd

	switch spec.Type {
	case "rpm":
		rpm, err := exec.LookPath("rpm")
		if err != nil {
			return err
		}
		cmd = exec.Command(rpm, "-q", spec.Name)
	case "dpkg":
		dpkg, err := exec.LookPath("dpkg")
		if err != nil {
			return err
		}
		cmd = exec.Command(dpkg, "-L", spec.Name)
	case "pacman":
		// TODO
	case "ebuild":
		// TODO
	case "homebrew":
		cmd = exec.Command("/usr/local/bin/brew", "ls", spec.Name)
	case "gem":
		cmd = exec.Command("/bin/bash", "-ic", "gem contents "+spec.Name)
	default:
		return errors.New("Unknown package manager type " + spec.Type)
	}

	err = cmd.Run()
	if err != nil && !spec.Absent {
		return err
	} else {
		return nil
	}
}
//findPath finds the path to wkhtmltopdf by
//- first looking in the current dir
//- looking in the PATH and PATHEXT environment dirs
//- using the WKHTMLTOPDF_PATH environment dir
//The path is cached, meaning you can not change the location of wkhtmltopdf in
//a running program once it has been found
func (pdfg *PDFGenerator) findPath() error {
	const exe = "wkhtmltopdf"
	if binPath != "" {
		pdfg.binPath = binPath
		return nil
	}
	exeDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		return err
	}
	path, err := exec.LookPath(filepath.Join(exeDir, exe))
	if err == nil && path != "" {
		binPath = path
		pdfg.binPath = path
		return nil
	}
	path, err = exec.LookPath(exe)
	if err == nil && path != "" {
		binPath = path
		pdfg.binPath = path
		return nil
	}
	dir := os.Getenv("WKHTMLTOPDF_PATH")
	if dir == "" {
		return fmt.Errorf("%s not found", exe)
	}
	path, err = exec.LookPath(filepath.Join(dir, exe))
	if err == nil && path != "" {
		binPath = path
		pdfg.binPath = path
		return nil
	}
	return fmt.Errorf("%s not found", exe)
}
Esempio n. 29
0
func (g *GpgCLI) Configure() (err error) {

	g.mutex.Lock()
	defer g.mutex.Unlock()

	prog := G.Env.GetGpg()
	opts := G.Env.GetGpgOptions()

	if len(prog) > 0 {
		err = canExec(prog)
	} else {
		prog, err = exec.LookPath("gpg2")
		if err != nil {
			prog, err = exec.LookPath("gpg")
		}
	}
	if err != nil {
		return err
	}

	g.logUI.Debug("| configured GPG w/ path: %s", prog)

	g.path = prog
	g.options = opts

	return
}
Esempio n. 30
0
func tryContainer(cmd *cobra.Command, args []string) bool {
	if insideContainer() {
		return false
	}
	if !dockerExistsByName("glu") {
		return false
	}
	fmt.Fprintln(os.Stderr, "* Using glu container")
	args = append(strings.Split(cmd.CommandPath(), " "), args...)
	var newCmd []string
	var binary string
	var err error
	if os.Getenv("CIRCLECI") == "true" {
		if binary, err = exec.LookPath("sudo"); err != nil {
			return false
		}
		os.Setenv("GLU_CONTAINER", "true")
		newCmd = []string{"sudo", "-E", "lxc-attach", "-n", dockerID("glu"), "--", "/bin/glu"}
		newCmd = append(newCmd, args[1:]...)
	} else {
		if binary, err = exec.LookPath("docker"); err != nil {
			return false
		}
		newCmd = []string{"docker", "exec", "glu"}
		newCmd = append(newCmd, args...)
	}
	syscall.Exec(binary, newCmd, os.Environ())
	return true
}