Example #1
0
func main() {
	// Terminates here on failure to get all input
	input.GetInput()

	if !*input.NoVerify {
		serverAddress := *input.ServerHostName
		if *input.ServerHostName == "" {
			serverAddress = *input.ServerIpAddress
		}

		err := verify.VerifyLogin(*input.Username, *input.Password, serverAddress)
		if err != nil {
			utils.Errors(err.Error())
		}
	}

	var err error
	CurrDir, err = utils.GetExeDir()
	if err != nil {
		utils.Errors("Failed to get exe directory.")
	}

	if *input.Update == "" {
		macInstall()
	} else {
		macUpdate()
	}
}
Example #2
0
func GetInput() {
	flag.Parse()

	// Using to append all fatal messages.
	fatalMessages := make([]string, 0)

	if os.Getuid() != 0 {
		fatalMessages = append(fatalMessages, "Install script must be run with root privileges.")
	}

	if *UserName == "" {
		fatalMessages = append(fatalMessages, "Please provide a username to -u.")
	}
	if *Password == "" {
		fatalMessages = append(fatalMessages, "Please provide a password to -pw.")
	}

	if *ServerHostName == "" && *ServerIpAddress == "" {
		fatalMessages = append(fatalMessages, "Please provide a server hostname to -s or a server ip address to -i.")
	}

	if len(fatalMessages) > 0 {
		utils.Errors(fatalMessages...)
	}
}
Example #3
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.")
	}
}