Ejemplo n.º 1
0
func unloadPlist(path string) error {
	unloadCmd := []string{"/bin/launchctl", "unload", path}
	_, err := utils.RunCmd(unloadCmd)
	if err != nil {
		// Most likely means already unloaded, or does not exist.
		return err
	}

	return nil
}
Ejemplo n.º 2
0
func macInstall() {
	err := removeRunningPlist()
	if err != nil {
		utils.Errors("Failed to remove running plist: " + err.Error())
	}

	if utils.FileExists(vars.AgentOptPath) {
		if err := os.RemoveAll(vars.AgentOptPath); err != nil {
			utils.Errors("Failed to remove " + vars.AgentOptPath + " : " + err.Error())
		}
	}

	// Copy the agent to opt path

	if !utils.FileExists(path.Join(CurrDir, vars.AgentDirName)) {
		utils.Errors("Missing " + vars.AgentDirName + " in " + CurrDir)
	}

	err = utils.CopyDir(path.Join(CurrDir, vars.AgentDirName), vars.AgentOptPath)
	if err != nil {
		cleanup()
		utils.Errors("Failed to copy agent directory to /opt: " + err.Error())
	}

	// Create a symlink inside the bin directory to the compiled python
	err = utils.CreateSymLink(vars.MacCompiledPythonExe, vars.AgentPythonBinExe)
	if err != nil {
		cleanup()
		utils.Errors("Failed to create symlink: " + err.Error())
	}

	// Create the agent config
	if err := createAgentConfig(); err != nil {
		cleanup()
		utils.Errors("Failed to create the agent config: " + err.Error())
	}

	// Copy the agent plist to system path
	err = utils.CopyFile(vars.MacAgentPlist, vars.MacSystemPlist)
	if err != nil {
		cleanup()
		utils.Errors("Failed to copy the plist to the system directory.")
	}

	// Load the plist
	cmd := []string{"launchctl", "load", "-w", vars.MacSystemPlist}
	_, err = utils.RunCmd(cmd)
	if err != nil {
		cleanup()
		utils.Errors("Failed to load system plist.")
	}
}