예제 #1
0
func (c *UninstallCommand) Execute(args []string) error {
	utils.EnsureSudo()
	steps := utils.Steps{
		{
			"Removing launchd agent",
			func() error {
				utils.StopAgent()
				utils.RemoveHost()
				return utils.RemoveAgent()
			},
		},
		{
			"Removing files",
			func() error {
				err := utils.RemoveSudoer()
				if err != nil {
					return err
				}

				return utils.RemoveDir()
			},
		},
	}

	return utils.Spin(steps)
}
예제 #2
0
파일: stop.go 프로젝트: dunkelstern/dlite
func (c *StopCommand) Execute(args []string) error {
	return utils.StopAgent()
}
예제 #3
0
func (c *InstallCommand) Execute(args []string) error {
	utils.EnsureSudo()
	err := utils.CreateDir()
	if err != nil {
		return err
	}

	steps := utils.Steps{
		{
			"Building disk image",
			func() error {
				// clean up but ignore errors since it's possible things weren't installed
				utils.StopAgent()
				utils.RemoveAgent()
				utils.RemoveHost()
				utils.RemoveDir()

				err := utils.CreateDir()
				if err != nil {
					return err
				}

				return utils.CreateDisk(c.SSHKey, c.Disk)
			},
		},
		{
			"Downloading OS",
			func() error {
				if c.Version == "" {
					latest, err := utils.GetLatestOSVersion()
					if err != nil {
						return err
					}
					c.Version = latest
				}
				return utils.DownloadOS(c.Version)
			},
		},
		{
			"Writing configuration",
			func() error {
				uuid := uuid.NewV1().String()
				return utils.SaveConfig(utils.Config{
					Uuid:     uuid,
					CpuCount: c.Cpus,
					Memory:   c.Memory,
					Hostname: c.Hostname,
					DiskSize: c.Disk,
					Share:    c.Share,
				})
			},
		},
		{
			"Creating launchd agent",
			func() error {
				err := utils.AddSudoer()
				if err != nil {
					return err
				}

				return utils.CreateAgent()
			},
		},
	}

	return utils.Spin(steps)
}