Beispiel #1
0
// Clean up if failure to install
func cleanup() {
	unloadPlist(vars.MacSystemPlist)

	if utils.FileExists(vars.AgentOptPath) {
		os.RemoveAll(vars.AgentOptPath)
	}

	if utils.FileExists(vars.MacSystemPlist) {
		os.Remove(vars.MacSystemPlist)
	}
}
Beispiel #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.")
	}
}
Beispiel #3
0
func removeRunningPlist() error {
	if utils.FileExists(vars.MacSystemPlist) {
		err := unloadPlist(vars.MacSystemPlist)
		if err != nil {
			return err
		}
	}

	return nil
}